Disk ARchive  2.6.8
Full featured and portable backup and archiving tool
i_entrepot_libcurl.hpp
Go to the documentation of this file.
1 /*********************************************************************/
2 // dar - disk archive - a backup/restoration program
3 // Copyright (C) 2002-2020 Denis Corbin
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 //
19 // to contact the author : http://dar.linux.free.fr/email.html
20 /*********************************************************************/
21 
25 
26 #ifndef I_ENTREPOT_LIBCURL_HPP
27 #define I_ENTREPOT_LIBCURL_HPP
28 
29 #include "../my_config.h"
30 
31 extern "C"
32 {
33 #if LIBCURL_AVAILABLE
34 #if HAVE_CURL_CURL_H
35 #include <curl/curl.h>
36 #endif
37 #endif
38 }
39 
40 #include <string>
41 #include <deque>
42 #include "entrepot_libcurl.hpp"
43 #include "secu_string.hpp"
44 #include "mem_ui.hpp"
46 
47 namespace libdar
48 {
49 
52 
54 
55 #if defined ( LIBCURL_AVAILABLE ) && defined ( LIBTHREADAR_AVAILABLE )
56 
57  class entrepot_libcurl::i_entrepot_libcurl : public entrepot, public mem_ui
58  {
59  public:
60  i_entrepot_libcurl(const std::shared_ptr<user_interaction> & dialog,
61  mycurl_protocol proto,
62  const std::string & login,
63  const secu_string & password,
64  const std::string & host,
65  const std::string & port,
66  bool auth_from_file,
67  const std::string & sftp_pub_keyfile,
68  const std::string & sftp_prv_keyfile,
69  const std::string & sftp_known_hosts,
70  U_I waiting_time
71  );
72  i_entrepot_libcurl(const i_entrepot_libcurl & ref) = default;
73  i_entrepot_libcurl(i_entrepot_libcurl && ref) = default;
74  i_entrepot_libcurl & operator = (const i_entrepot_libcurl & ref) = default;
75  i_entrepot_libcurl & operator = (i_entrepot_libcurl && ref) noexcept = default;
76  ~i_entrepot_libcurl() throw () {};
77 
78 
79  // inherited from class entrepot
80 
83  virtual std::string get_url() const override { return base_URL + get_full_path().display(); };
84  virtual void read_dir_reset() const override;
85  virtual bool read_dir_next(std::string & filename) const override;
86  virtual entrepot *clone() const override { return new (std::nothrow) i_entrepot_libcurl(*this); };
87 
88  protected:
89 
90  // inherited from class entrepot
91 
92  virtual fichier_global *inherited_open(const std::shared_ptr<user_interaction> & dialog,
93  const std::string & filename,
94  gf_mode mode,
95  bool force_permission,
96  U_I permission,
97  bool fail_if_exists,
98  bool erase) const override;
99 
100  virtual void inherited_unlink(const std::string & filename) const override;
101  virtual void read_dir_flush() override;
102 
103  private:
104  mycurl_protocol x_proto;
105  std::string base_URL;
106  mycurl_easyhandle_sharing easyh;
107  std::deque<std::string> current_dir;
108  std::string reading_dir_tmp;
109  U_I wait_delay;
110 
111  void set_libcurl_URL();
112  void set_libcurl_authentication(user_interaction & dialog,
113  const std::string & location,
114  const std::string & login,
115  const secu_string & password,
116  bool auth_from_file,
117  const std::string & sftp_pub_keyfile,
118  const std::string & sftp_prv_keyfile,
119  const std::string & sftp_known_hosts
120  );
121  void detruit();
122 
123  static std::string mycurl_protocol2string(mycurl_protocol proto);
124  static std::string build_url_from(mycurl_protocol proto, const std::string & host, const std::string & port);
125  static size_t get_ftp_listing_callback(void *buffer, size_t size, size_t nmemb, void *userp);
126  static size_t null_callback(void *buffer, size_t size, size_t nmemb, void *userp) { return size*nmemb; };
127  static bool mycurl_is_protocol_available(mycurl_protocol proto);
128 
129  // needed to access the entrepot inherited protected methods
130  friend class entrepot_libcurl;
131  };
132 
133 #endif
134 
136 } // end of namespace
137 
138 #endif
libdar::entrepot_libcurl::get_full_path
virtual path get_full_path() const override
returns the full path of location
libdar::entrepot_libcurl::clone
virtual entrepot * clone() const override
generate a clone of "this"
Definition: entrepot_libcurl.hpp:88
libdar::gf_mode
gf_mode
generic_file openning modes
Definition: gf_mode.hpp:43
libdar::entrepot_libcurl::entrepot_libcurl
entrepot_libcurl(const std::shared_ptr< user_interaction > &dialog, mycurl_protocol proto, const std::string &login, const secu_string &password, const std::string &host, const std::string &port, bool auth_from_file, const std::string &sftp_pub_keyfile, const std::string &sftp_prv_keyfile, const std::string &sftp_known_hosts, U_I waiting_time)
libdar::entrepot::entrepot
entrepot()
constructor
libdar::path::display
std::string display() const
convert back a path to a string
libdar::entrepot_libcurl::get_url
virtual std::string get_url() const override
secu_string.hpp
this file contains the definition of secu_string class, a std::string like class but allocated in sec...
libdar::mycurl_protocol
mycurl_protocol
libcurl protocols supported by libdar
Definition: mycurl_protocol.hpp:48
mycurl_easyhandle_sharing.hpp
used to optimize network session establised by libcurl
entrepot_libcurl.hpp
defines the implementation for remote filesystem entrepot using libcurl
libdar::entrepot_libcurl::read_dir_reset
virtual void read_dir_reset() const override
routines to read existing files in the current directory (see set_location() / set_root() methods)
mem_ui.hpp
class mem_ui definition. This class is to be used as parent class to handle user_interaction object m...
libdar
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:46