Commit 0bd348a8 authored by chriadam's avatar chriadam

[buteo-sync-plugin-carddav] Ignore addressbook-home-set response to...

[buteo-sync-plugin-carddav] Ignore addressbook-home-set response to addressbook information request. Contributes to MER#1304

This commit ensures that we ignore any addressbook-home-set element
in the response to the addressbook information request, as some
implementations will return both addressbook-home-set and addressbook
collection information in response to the addressbook information
request.

Contributes to MER#1304
parent 1ee72608
......@@ -466,7 +466,7 @@ void CardDav::userInformationResponse()
} else if (responseType == ReplyParser::AddressbookInformationResponse) {
// the server responded with addressbook information instead
// of user principal information. Skip the next discovery step.
QList<ReplyParser::AddressBookInformation> infos = m_parser->parseAddressbookInformation(data);
QList<ReplyParser::AddressBookInformation> infos = m_parser->parseAddressbookInformation(data, QString());
if (infos.isEmpty()) {
LOG_WARNING(Q_FUNC_INFO << "unable to parse addressbook info from user principal response");
emit error();
......@@ -519,6 +519,7 @@ void CardDav::fetchAddressbooksInformation(const QString &addressbooksHomePath)
{
LOG_DEBUG(Q_FUNC_INFO << "requesting addressbook sync information");
QNetworkReply *reply = m_request->addressbooksInformation(m_serverUrl, addressbooksHomePath);
reply->setProperty("addressbooksHomePath", addressbooksHomePath);
if (!reply) {
emit error();
return;
......@@ -531,6 +532,7 @@ void CardDav::fetchAddressbooksInformation(const QString &addressbooksHomePath)
void CardDav::addressbooksInformationResponse()
{
QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
QString addressbooksHomePath = reply->property("addressbooksHomePath").toString();
QByteArray data = reply->readAll();
if (reply->error() != QNetworkReply::NoError) {
int httpError = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
......@@ -541,7 +543,7 @@ void CardDav::addressbooksInformationResponse()
return;
}
QList<ReplyParser::AddressBookInformation> infos = m_parser->parseAddressbookInformation(data);
QList<ReplyParser::AddressBookInformation> infos = m_parser->parseAddressbookInformation(data, addressbooksHomePath);
if (infos.isEmpty()) {
LOG_WARNING(Q_FUNC_INFO << "unable to parse addressbook info from response");
emit error();
......
......@@ -222,7 +222,7 @@ QString ReplyParser::parseAddressbookHome(const QByteArray &addressbookUrlsRespo
return addressbookHome;
}
QList<ReplyParser::AddressBookInformation> ReplyParser::parseAddressbookInformation(const QByteArray &addressbookInformationResponse) const
QList<ReplyParser::AddressBookInformation> ReplyParser::parseAddressbookInformation(const QByteArray &addressbookInformationResponse, const QString &addressbooksHomePath) const
{
/* We expect a response of the form:
<d:multistatus xmlns:d="DAV:" xmlns:cs="http://calendarserver.org/ns/">
......@@ -260,6 +260,15 @@ QList<ReplyParser::AddressBookInformation> ReplyParser::parseAddressbookInformat
QVariantMap rmap = rv.toMap();
ReplyParser::AddressBookInformation currInfo;
currInfo.url = QUrl::fromPercentEncoding(rmap.value("href").toMap().value("@text").toString().toUtf8());
if (!addressbooksHomePath.isEmpty() &&
(currInfo.url == addressbooksHomePath ||
currInfo.url == QStringLiteral("%1/").arg(addressbooksHomePath) ||
(!currInfo.url.endsWith('/') &&
addressbooksHomePath.endsWith('/') &&
currInfo.url == addressbooksHomePath.mid(0, addressbooksHomePath.size()-1)))) {
LOG_DEBUG("ignoring addressbook-home-set response returned for addressbook information request:" << currInfo.url);
continue;
}
// some services (e.g. Cozy) return multiple propstat elements in each response
QVariantList propstats;
......
......@@ -79,7 +79,7 @@ public:
QString parseUserPrincipal(const QByteArray &userInformationResponse, ResponseType *responseType) const;
QString parseAddressbookHome(const QByteArray &addressbookUrlsResponse) const;
QList<AddressBookInformation> parseAddressbookInformation(const QByteArray &addressbookInformationResponse) const;
QList<AddressBookInformation> parseAddressbookInformation(const QByteArray &addressbookInformationResponse, const QString &addressbooksHomePath) const;
QList<ContactInformation> parseSyncTokenDelta(const QByteArray &syncTokenDeltaResponse, QString *newSyncToken) const;
QList<ContactInformation> parseContactMetadata(const QByteArray &contactMetadataResponse, const QString &addresbookUrl) const;
QMap<QString, FullContactInformation> parseContactData(const QByteArray &contactData) const;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment