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

0001 /*
0002     SPDX-FileCopyrightText: 2015-2017 Krzysztof Nowicki <krissn@op.pl>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <QHash>
0010 #include <QString>
0011 #include <QUrl>
0012 
0013 #include "ewsjob.h"
0014 #include "ewsserverversion.h"
0015 #include "ewstypes.h"
0016 
0017 namespace KIO
0018 {
0019 class Job;
0020 }
0021 
0022 class EwsPoxAutodiscoverRequest : public EwsJob
0023 {
0024     Q_OBJECT
0025 public:
0026     enum Action {
0027         RedirectUrl = 0,
0028         RedirectAddr,
0029         Settings,
0030     };
0031 
0032     enum ProtocolType {
0033         ExchangeProto,
0034         ExchangeProxyProto,
0035         ExchangeWebProto,
0036         UnknownProto,
0037     };
0038 
0039     class Protocol
0040     {
0041     public:
0042         Protocol()
0043             : mType(UnknownProto)
0044         {
0045         }
0046 
0047         bool isValid() const
0048         {
0049             return mType != UnknownProto;
0050         }
0051 
0052         ProtocolType type() const
0053         {
0054             return mType;
0055         }
0056 
0057         const QString &ewsUrl() const
0058         {
0059             return mEwsUrl;
0060         }
0061 
0062         const QString &oabUrl() const
0063         {
0064             return mOabUrl;
0065         }
0066 
0067     private:
0068         ProtocolType mType;
0069         QString mEwsUrl;
0070         QString mOabUrl;
0071         friend class EwsPoxAutodiscoverRequest;
0072     };
0073 
0074     EwsPoxAutodiscoverRequest(const QUrl &url, const QString &email, const QString &userAgent, bool useNTLMv2, QObject *parent);
0075     ~EwsPoxAutodiscoverRequest() override;
0076 
0077     const EwsServerVersion &serverVersion() const
0078     {
0079         return mServerVersion;
0080     }
0081 
0082     void dump() const;
0083 
0084     void start() override;
0085 
0086     Action action() const
0087     {
0088         return mAction;
0089     }
0090 
0091     const Protocol protocol(ProtocolType type) const
0092     {
0093         return mProtocols.value(type);
0094     }
0095 
0096     const QString &redirectAddr() const
0097     {
0098         return mRedirectAddr;
0099     }
0100 
0101     const QString &redirectUrl() const
0102     {
0103         return mRedirectUrl;
0104     }
0105 
0106     const QUrl &lastHttpUrl() const
0107     {
0108         return mLastUrl;
0109     }
0110 
0111 protected:
0112     void doSend();
0113     void prepare(const QString &body);
0114     bool readResponse(QXmlStreamReader &reader);
0115 
0116 protected Q_SLOTS:
0117     void requestResult(KJob *job);
0118     void requestData(KIO::Job *job, const QByteArray &data);
0119     void requestRedirect(KIO::Job *job, const QUrl &url);
0120 
0121 private:
0122     bool readAccount(QXmlStreamReader &reader);
0123     bool readProtocol(QXmlStreamReader &reader);
0124 
0125     QString mResponseData;
0126     QString mBody;
0127     QUrl mUrl;
0128     QString mEmail;
0129     QString mUserAgent;
0130     bool mUseNTLMv2;
0131     EwsServerVersion mServerVersion;
0132     Action mAction;
0133     QString mRedirectUrl;
0134     QString mRedirectAddr;
0135     QHash<ProtocolType, Protocol> mProtocols;
0136     QUrl mLastUrl;
0137 };