Skip to content

Commit

Permalink
Report error Virus Detected.
Browse files Browse the repository at this point in the history
Signed-off-by: alex-z <[email protected]>
  • Loading branch information
allexzander committed Nov 30, 2023
1 parent 308ccec commit 58d6cda
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/libsync/owncloudpropagator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,12 @@ void PropagateItemJob::reportClientStatuses()
propagator()->account()->reportClientStatus(ClientStatusReporting::Status::DownloadError_ConflictInvalidCharacters);
} else if (_item->_httpErrorCode != 0 && _item->_httpErrorCode != 200 && _item->_httpErrorCode != 201 && _item->_httpErrorCode != 204) {
if (_item->_direction == SyncFileItem::Up) {
propagator()->account()->reportClientStatus(ClientStatusReporting::Status::UploadError_ServerError);
if (_item->_httpErrorCode == 503 && !_item->_errorException.isEmpty()

Check warning on line 361 in src/libsync/owncloudpropagator.cpp

View workflow job for this annotation

GitHub Actions / build

/src/libsync/owncloudpropagator.cpp:361:13 [bugprone-branch-clone]

if with identical then and else branches
&& _item->_errorException.contains(QStringLiteral("UnsupportedMediaType")) && _item->_errorString.contains(QStringLiteral("virus"), Qt::CaseInsensitive)) {
propagator()->account()->reportClientStatus(ClientStatusReporting::Status::UploadError_Virus_Detected);
} else {
propagator()->account()->reportClientStatus(ClientStatusReporting::Status::UploadError_ServerError);
}
} else {
propagator()->account()->reportClientStatus(ClientStatusReporting::Status::DownloadError_ServerError);
}
Expand Down
25 changes: 25 additions & 0 deletions src/libsync/owncloudpropagator_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ inline bool fileIsStillChanging(const OCC::SyncFileItem &item)

namespace OCC {


inline QByteArray getEtagFromReply(QNetworkReply *reply)
{
QByteArray ocEtag = parseEtag(reply->rawHeader("OC-ETag"));
Expand All @@ -62,6 +63,30 @@ inline QByteArray getEtagFromReply(QNetworkReply *reply)
return ret;
}

inline QByteArray getExceptionFromReply(QNetworkReply *reply)
{
Q_ASSERT(reply);
if (!reply) {
qCDebug(lcPropagator) << "Could not parse null reply";
return {};
}

if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() != 503) {
return {};
}

const auto replyBody = reply->readAll();
reply->reset();

auto exceptionStartIndex = replyBody.indexOf(QByteArrayLiteral("<s:exception>"));
if (exceptionStartIndex != -1) {
exceptionStartIndex += QByteArrayLiteral("<s:exception>").size();
const auto exceptionEndIndex = replyBody.indexOf('<', exceptionStartIndex);
return replyBody.mid(exceptionStartIndex, exceptionEndIndex - exceptionStartIndex);
}
return {};
}

/**
* Given an error from the network, map to a SyncFileItem::Status error
*/
Expand Down
1 change: 1 addition & 0 deletions src/libsync/propagateupload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ bool PollJob::finished()
_item->_requestId = requestId();
_item->_status = classifyError(err, _item->_httpErrorCode);
_item->_errorString = errorString();
_item->_errorException = getExceptionFromReply(reply());

if (_item->_status == SyncFileItem::FatalError || _item->_httpErrorCode >= 400) {
if (_item->_status != SyncFileItem::FatalError
Expand Down
1 change: 1 addition & 0 deletions src/libsync/syncfileitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ class OWNCLOUDSYNC_EXPORT SyncFileItem
quint16 _httpErrorCode = 0;
RemotePermissions _remotePerm;
QString _errorString; // Contains a string only in case of error
QString _errorException; // Contains a server exception string only in case of error
QByteArray _responseTimeStamp;
QByteArray _requestId; // X-Request-Id of the failed request
quint32 _affectedItems = 1; // the number of affected items by the operation on this item.
Expand Down

0 comments on commit 58d6cda

Please sign in to comment.