File indexing completed on 2024-11-17 04:44:00
0001 /**************************************************************************** 0002 ** QWebDAV Library (qwebdavlib) - LGPL v2.1 0003 ** 0004 ** HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV) 0005 ** from June 2007 0006 ** http://tools.ietf.org/html/rfc4918 0007 ** 0008 ** Web Distributed Authoring and Versioning (WebDAV) SEARCH 0009 ** from November 2008 0010 ** http://tools.ietf.org/html/rfc5323 0011 ** 0012 ** Missing: 0013 ** - LOCK support 0014 ** - process WebDAV SEARCH responses 0015 ** 0016 ** Copyright (C) 2012 Martin Haller <martin.haller@rebnil.com> 0017 ** for QWebDAV library (qwebdavlib) version 1.0 0018 ** https://github.com/mhaller/qwebdavlib 0019 ** 0020 ** Copyright (C) 2012 Timo Zimmermann <meedav@timozimmermann.de> 0021 ** for portions from QWebdav plugin for MeeDav (LGPL v2.1) 0022 ** http://projects.developer.nokia.com/meedav/ 0023 ** 0024 ** Copyright (C) 2009-2010 Corentin Chary <corentin.chary@gmail.com> 0025 ** for portions from QWebdav - WebDAV lib for Qt4 (LGPL v2.1) 0026 ** http://xf.iksaif.net/dev/qwebdav.html 0027 ** 0028 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 0029 ** for naturalCompare() (LGPL v2.1) 0030 ** http://qt.gitorious.org/qt/qt/blobs/4.7/src/gui/dialogs/qfilesystemmodel.cpp 0031 ** 0032 ** This library is free software; you can redistribute it and/or 0033 ** modify it under the terms of the GNU Library General Public 0034 ** License as published by the Free Software Foundation; either 0035 ** version 2 of the License, or (at your option) any later version. 0036 ** 0037 ** This library is distributed in the hope that it will be useful, 0038 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 0039 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0040 ** Library General Public License for more details. 0041 ** 0042 ** You should have received a copy of the GNU Library General Public License 0043 ** along with this library; see the file COPYING.LIB. If not, write to 0044 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0045 ** Boston, MA 02110-1301, USA. 0046 ** 0047 ** http://www.gnu.org/licenses/lgpl-2.1-standalone.html 0048 ** 0049 ****************************************************************************/ 0050 0051 #ifndef QWEBDAV_H 0052 #define QWEBDAV_H 0053 0054 #include <QtCore> 0055 #include <QtNetwork> 0056 0057 #include "qwebdavshared_export.h" 0058 0059 /** 0060 * @brief Main class used to handle the webdav protocol 0061 */ 0062 class QWEBDAVSHARED_EXPORT QWebdav : public QNetworkAccessManager 0063 { 0064 Q_OBJECT 0065 0066 public: 0067 enum QWebdavConnectionType {HTTP = 1, HTTPS}; 0068 0069 QWebdav(QObject* parent = nullptr); 0070 ~QWebdav(); 0071 0072 typedef QMap<QString, QMap < QString, QVariant > > PropValues; 0073 typedef QMap<QString, QStringList > PropNames; 0074 0075 0076 QString hostname() const; 0077 int port() const; 0078 QString rootPath() const; 0079 QString username() const; 0080 QString password() const; 0081 QWebdavConnectionType connectionType() const; 0082 bool isSSL() const; 0083 0084 void setConnectionSettings( const QWebdavConnectionType connectionType, 0085 const QString &hostname, 0086 const QString &rootPath = "/", 0087 const QString &username = "", 0088 const QString &password = "", 0089 int port = 0, 0090 bool ignoreSslErrors = true); 0091 0092 QNetworkReply* list(const QString& path, int depth = 1); 0093 0094 QNetworkReply* search(const QString& path, const QString& query); 0095 0096 QNetworkReply* get(const QString& path, const QMap<QByteArray, QByteArray> &headers); 0097 0098 QNetworkReply* put(const QString& path, const QByteArray& data, const QMap<QByteArray, QByteArray> &headers); 0099 0100 QNetworkReply* mkdir(const QString& dir ); 0101 // The extended MKCOL used in CardDAV 0102 QNetworkReply* mkdir(const QString& dir, const QByteArray& query); 0103 QNetworkReply* mkcalendar(const QString& dir, const QByteArray& query); 0104 QNetworkReply* copy(const QString& pathFrom, const QString& pathTo, bool overwrite = false); 0105 QNetworkReply* move(const QString& pathFrom, const QString& pathTo, bool overwrite = false); 0106 QNetworkReply* remove(const QString& path ); 0107 0108 QNetworkReply* propfind(const QString& path, const QByteArray& query, int depth = 0); 0109 QNetworkReply* propfind(const QString& path, const QWebdav::PropNames& props, int depth = 0); 0110 0111 QNetworkReply* report(const QString& path, const QByteArray& query, int depth = 0); 0112 0113 QNetworkReply* proppatch(const QString& path, const QWebdav::PropValues& props); 0114 QNetworkReply* proppatch(const QString& path, const QByteArray& query); 0115 0116 protected Q_SLOTS: 0117 void provideAuthenication(QNetworkReply* reply, QAuthenticator* authenticator); 0118 void sslErrors(QNetworkReply *reply,const QList<QSslError> &errors); 0119 0120 protected: 0121 QNetworkReply* createDAVRequest(const QString& method, QNetworkRequest& req, const QByteArray& outgoingData = {}); 0122 0123 //! creates the absolute path from m_rootPath and relPath 0124 QString absolutePath(const QString &relPath); 0125 0126 private: 0127 QString m_rootPath; 0128 QString m_username; 0129 QString m_password; 0130 QUrl m_baseUrl; 0131 0132 QWebdavConnectionType m_currentConnectionType; 0133 0134 QNetworkReply *m_authenticator_lastReply; 0135 0136 bool m_ignoreSslErrors; 0137 }; 0138 0139 #endif // QWEBDAV_H