File: WebDavManager.h

package info (click to toggle)
tulip 5.4.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 208,716 kB
  • sloc: cpp: 613,411; makefile: 22,047; ansic: 11,295; python: 4,606; sh: 709; yacc: 522; pascal: 157; php: 66; xml: 56; lex: 55
file content (107 lines) | stat: -rw-r--r-- 3,226 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/**
 *
 * This file is part of Tulip (http://tulip.labri.fr)
 *
 * Authors: David Auber and the Tulip development Team
 * from LaBRI, University of Bordeaux
 *
 * Tulip is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation, either version 3
 * of the License, or (at your option) any later version.
 *
 * Tulip is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 */

#ifndef WEBDAVMANAGER_H
#define WEBDAVMANAGER_H

#include <iostream>

#include <QObject>
#include <QCoreApplication>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>

class QDomDocument;
/**
 * @brief This class uploads files to a server using the WEBDAV protocol.
 * It is tailored for a very specific use and only supports authentified (https) mode.
 **/
class WebDavManager : public QObject {
  Q_OBJECT
public:
  /**
   * @brief Creates a new manager to create folders and upload files on a remote webdav server.
   * All operations take the url as base for where the operations take place, e.g. calling
   *mkdir("foo") will create
   * https://[host]/[url]/foo
   *
   * An easy way to encode your credentials in base64 is to fire up a python interpreter and type:
   * import base64
   * base64.b64encode("username:password")
   *
   * @param host The host of the webdav server (e.g. webdav.labri.fr)
   * @param url The base URL where to upload the files (e.g. perso/huet)
   * @param base64credentials The base64-encoded credentials : base64(username:password)
   **/
  WebDavManager(const QString &host, const QString &url, const QString &base64credentials);

  /**
   * @brief Checks whether a folder already exists.
   *
   * @param folder The folder to check for presence on the remote server.
   * @return bool Whether the folder exists.
   **/
  bool folderExists(const QString &folder);

  /**
   * @brief Creates a folder on the remote server.
   *
   * @param folder The name of the folder to create.
   * @return bool Whether the operation was sucessfull.
   **/
  bool mkdir(const QString &folder);

  /**
   * @brief Uploads a file to the server.
   *
   * @param filename The full name of the file to create.
   * @param data The contents of the file to upload.
   * @return bool Whether the operation was successfull.
   **/
  bool putFile(const QString &filename, QIODevice *data);

  QDomDocument *getRemoteDescription();

  /**
   * @brief Ensure that all operations are finished.
   *
   * @return void
   **/
  void finish();

public slots:
  void requestFinished(QNetworkReply *reply);

private:
  QUrl initUrl(const QString &dest);

  QNetworkRequest initRequest(const QString &destination, QIODevice *data = nullptr,
                              QVariant mimetype = QVariant("binary/octet-stream"));

  QString _host;
  QString _url;
  QString _credentials;
  QNetworkAccessManager _manager;
  uint _ongoingRequests;
  bool _requestSucessFull;
  bool _displayErrors;
};

#endif // WEBDAVMANAGER_H