File indexing completed on 2024-12-22 04:57:04

0001 /*
0002     SPDX-FileCopyrightText: 2015-2017 Krzysztof Nowicki <krissn@op.pl>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "ewsunsubscriberequest.h"
0008 
0009 #include <QXmlStreamWriter>
0010 
0011 #include "ewsclient_debug.h"
0012 
0013 EwsUnsubscribeRequest::EwsUnsubscribeRequest(EwsClient &client, QObject *parent)
0014     : EwsRequest(client, parent)
0015 {
0016 }
0017 
0018 EwsUnsubscribeRequest::~EwsUnsubscribeRequest() = default;
0019 
0020 void EwsUnsubscribeRequest::start()
0021 {
0022     QString reqString;
0023     QXmlStreamWriter writer(&reqString);
0024 
0025     startSoapDocument(writer);
0026 
0027     writer.writeStartElement(ewsMsgNsUri, QStringLiteral("Unsubscribe"));
0028 
0029     writer.writeTextElement(ewsMsgNsUri, QStringLiteral("SubscriptionId"), mSubscriptionId);
0030 
0031     writer.writeEndElement(); // Unsubscribe
0032 
0033     endSoapDocument(writer);
0034 
0035     qCDebug(EWSCLI_PROTO_LOG) << reqString;
0036 
0037     prepare(reqString);
0038 
0039     doSend();
0040 }
0041 
0042 bool EwsUnsubscribeRequest::parseResult(QXmlStreamReader &reader)
0043 {
0044     return parseResponseMessage(reader, QStringLiteral("Unsubscribe"), [this](QXmlStreamReader &reader) {
0045         return parseUnsubscribeResponse(reader);
0046     });
0047 }
0048 
0049 bool EwsUnsubscribeRequest::parseUnsubscribeResponse(QXmlStreamReader &reader)
0050 {
0051     QSharedPointer<Response> resp(new Response(reader));
0052     if (resp->responseClass() == EwsResponseUnknown) {
0053         return false;
0054     }
0055 
0056     mResponse = resp;
0057     return true;
0058 }
0059 
0060 EwsUnsubscribeRequest::Response::Response(QXmlStreamReader &reader)
0061     : EwsRequest::Response(reader)
0062 {
0063     if (mClass == EwsResponseParseError) {
0064         return;
0065     }
0066 
0067     while (reader.readNextStartElement()) {
0068         if (reader.namespaceUri() != ewsMsgNsUri && reader.namespaceUri() != ewsTypeNsUri) {
0069             setErrorMsg(QStringLiteral("Unexpected namespace in %1 element: %2").arg(QStringLiteral("ResponseMessage"), reader.namespaceUri().toString()));
0070             return;
0071         }
0072 
0073         if (!readResponseElement(reader)) {
0074             setErrorMsg(QStringLiteral("Failed to read EWS request - invalid response element."));
0075             return;
0076         }
0077     }
0078 }
0079 
0080 #include "moc_ewsunsubscriberequest.cpp"