WebDAV Client
client.hpp
1 /*#***************************************************************************
2 # __ __ _____ _____
3 # Project | | | | | \ / ___|
4 # | |__| | | |\ \ / /
5 # | | | | ) ) ( (
6 # | /\ | | |/ / \ \___
7 # \_/ \_/ |_____/ \_____|
8 #
9 # Copyright (C) 2016, The WDC Project, <designerror@yandex.ru>, et al.
10 #
11 # This software is licensed as described in the file LICENSE, which
12 # you should have received as part of this distribution.
13 #
14 # You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 # copies of the Software, and permit persons to whom the Software is
16 # furnished to do so, under the terms of the LICENSE file.
17 #
18 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 # KIND, either express or implied.
20 #
21 ############################################################################*/
22 
23 #ifndef WEBDAV_CLIENT_H
24 #define WEBDAV_CLIENT_H
25 #pragma once
26 
27 #include <functional>
28 #include <iostream>
29 #include <map>
30 #include <string>
31 #include <vector>
32 
33 namespace WebDAV
34 {
35  using progress_t = std::function<int(void *context,
36  size_t dltotal,
37  size_t dlnow,
38  size_t ultotal,
39  size_t ulnow)> ;
40 
41  using callback_t = std::function<void(bool)> ;
42 
43  using strings_t = std::vector<std::string>;
44  using dict_t = std::map<std::string, std::string>;
45 
52  class Client
53  {
54  public:
55 
68  static auto Init(const dict_t& options) noexcept -> Client *;
69 
71  static void Cleanup() noexcept;
72 
78  auto free_size() const noexcept -> unsigned long long;
79 
85  auto check(const std::string& remote_resource = "/") const noexcept -> bool;
86 
92  auto info(const std::string& remote_resource) const noexcept -> dict_t;
93 
99  auto clean(const std::string& remote_resource) const noexcept -> bool;
100 
105  auto is_directory(const std::string& remote_resource) const noexcept -> bool;
106 
112  auto list(const std::string& remote_directory = "") const noexcept -> strings_t;
113 
120  auto create_directory(
121  const std::string& remote_directory,
122  bool recursive = false
123  ) const noexcept -> bool;
124 
131  auto move(
132  const std::string& remote_source_resource,
133  const std::string& remote_destination_resource
134  ) const noexcept -> bool;
135 
142  auto copy(
143  const std::string& remote_source_resource,
144  const std::string& remote_destination_resource
145  ) const noexcept -> bool;
146 
154  auto download(
155  const std::string& remote_file,
156  const std::string& local_file,
157  progress_t progress = nullptr
158  ) const noexcept -> bool;
159 
168  auto download_to(
169  const std::string& remote_file,
170  char * & buffer_ptr,
171  unsigned long long & buffer_size,
172  progress_t progress = nullptr
173  ) const noexcept -> bool;
174 
182  auto download_to(
183  const std::string& remote_file,
184  std::ostream& stream,
185  progress_t progress = nullptr
186  ) const noexcept -> bool;
187 
196  auto async_download(
197  const std::string& remote_file,
198  const std::string& local_file,
199  callback_t callback = nullptr,
200  progress_t progress = nullptr
201  ) const noexcept -> void;
202 
210  auto upload(
211  const std::string& remote_file,
212  const std::string& local_file,
213  progress_t progress = nullptr
214  ) const noexcept -> bool;
215 
224  auto upload_from(
225  const std::string& remote_file,
226  char * buffer_ptr,
227  unsigned long long buffer_size,
228  progress_t progress = nullptr
229  ) const noexcept -> bool;
230 
238  auto upload_from(
239  const std::string& remote_file,
240  std::istream& stream,
241  progress_t progress = nullptr
242  ) const noexcept -> bool;
243 
252  auto async_upload(
253  const std::string& remote_file,
254  const std::string& local_file,
255  callback_t callback = nullptr,
256  progress_t progress = nullptr
257  ) const noexcept -> void;
258 
259 
260  virtual ~Client() {};
261 
262  protected:
263 
264  enum { buffer_size = 1000 * 1000 };
265 
266  Client() {}
267  };
268 }
269 
270 #endif
auto list(const std::string &remote_directory="") const noexcept -> strings_t
auto create_directory(const std::string &remote_directory, bool recursive=false) const noexcept -> bool
auto async_download(const std::string &remote_file, const std::string &local_file, callback_t callback=nullptr, progress_t progress=nullptr) const noexcept -> void
auto upload(const std::string &remote_file, const std::string &local_file, progress_t progress=nullptr) const noexcept -> bool
static void Cleanup() noexcept
This function releases resources acquired by curl_global_init.
auto check(const std::string &remote_resource="/") const noexcept -> bool
auto is_directory(const std::string &remote_resource) const noexcept -> bool
auto download(const std::string &remote_file, const std::string &local_file, progress_t progress=nullptr) const noexcept -> bool
auto free_size() const noexcept -> unsigned long long
Definition: client.hpp:33
auto download_to(const std::string &remote_file, char *&buffer_ptr, unsigned long long &buffer_size, progress_t progress=nullptr) const noexcept -> bool
WebDAV Client.
Definition: client.hpp:52
auto info(const std::string &remote_resource) const noexcept -> dict_t
auto clean(const std::string &remote_resource) const noexcept -> bool
auto async_upload(const std::string &remote_file, const std::string &local_file, callback_t callback=nullptr, progress_t progress=nullptr) const noexcept -> void
auto upload_from(const std::string &remote_file, char *buffer_ptr, unsigned long long buffer_size, progress_t progress=nullptr) const noexcept -> bool
auto move(const std::string &remote_source_resource, const std::string &remote_destination_resource) const noexcept -> bool
auto copy(const std::string &remote_source_resource, const std::string &remote_destination_resource) const noexcept -> bool
static auto Init(const dict_t &options) noexcept -> Client *