Skip to content

Commit

Permalink
Accept valid lsColJob reply XML content types
Browse files Browse the repository at this point in the history
Signed-off-by: Claudio Cambra <claudio.cambra@gmail.com>
  • Loading branch information
claucambra committed Sep 9, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 1f4d340 commit 7da962e
Showing 2 changed files with 18 additions and 7 deletions.
14 changes: 10 additions & 4 deletions src/libsync/discoveryphase.cpp
Original file line number Diff line number Diff line change
@@ -583,14 +583,20 @@ void DiscoverySingleDirectoryJob::lsJobFinishedWithoutErrorSlot()

void DiscoverySingleDirectoryJob::lsJobFinishedWithErrorSlot(QNetworkReply *r)
{
QString contentType = r->header(QNetworkRequest::ContentTypeHeader).toString();
int httpCode = r->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
const QString contentType = r->header(QNetworkRequest::ContentTypeHeader).toString();
const bool invalidContentType = !contentType.contains("application/xml; charset=utf-8") &&
!contentType.contains("application/xml; charset=\"utf-8\"") &&
!contentType.contains("text/xml; charset=utf-8") &&
!contentType.contains("text/xml; charset=\"utf-8\"");
const int httpCode = r->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
QString msg = r->errorString();

qCWarning(lcDiscovery) << "LSCOL job error" << r->errorString() << httpCode << r->error();
if (r->error() == QNetworkReply::NoError
&& !contentType.contains("application/xml; charset=utf-8")) {

if (r->error() == QNetworkReply::NoError && invalidContentType) {
msg = tr("Server error: PROPFIND reply is not XML formatted!");
}

emit finished(HttpError{ httpCode, msg });
deleteLater();
}
11 changes: 8 additions & 3 deletions src/libsync/networkjobs.cpp
Original file line number Diff line number Diff line change
@@ -395,9 +395,14 @@ bool LsColJob::finished()
qCInfo(lcLsColJob) << "LSCOL of" << reply()->request().url() << "FINISHED WITH STATUS"
<< replyStatusString();

QString contentType = reply()->header(QNetworkRequest::ContentTypeHeader).toString();
int httpCode = reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
if (httpCode == 207 && contentType.contains("application/xml; charset=utf-8")) {
const QString contentType = reply()->header(QNetworkRequest::ContentTypeHeader).toString();
const int httpCode = reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
const bool validContentType = contentType.contains("application/xml; charset=utf-8") ||
contentType.contains("application/xml; charset=\"utf-8\"") ||
contentType.contains("text/xml; charset=utf-8") ||
contentType.contains("text/xml; charset=\"utf-8\"");

if (httpCode == 207 && validContentType) {
LsColXMLParser parser;
connect(&parser, &LsColXMLParser::directoryListingSubfolders,
this, &LsColJob::directoryListingSubfolders);

0 comments on commit 7da962e

Please sign in to comment.