| Disk ARchive 2.8.1 Full featured and portable backup and archiving tool

Loading...
Searching...
No Matches
i_entrepot_libcurl.hpp
Go to the documentation of this file.
1/*********************************************************************/
2// dar - disk archive - a backup/restoration program
3// Copyright (C) 2002-2025 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, see the AUTHOR file
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 <map>
43#include "entrepot_libcurl.hpp"
44#include "secu_string.hpp"
45#include "mem_ui.hpp"
46#include "mycurl_easyhandle_sharing.hpp"
47
48 namespace libdar
49{
50
53
55
56#if defined ( LIBCURL_AVAILABLE ) && defined ( LIBTHREADAR_AVAILABLE )
57
58 class entrepot_libcurl::i_entrepot_libcurl : public entrepot, public mem_ui
59 {
60 public:
61 i_entrepot_libcurl(const std::shared_ptr<user_interaction> & dialog,
62 remote_entrepot_type proto,
63 const std::string & login,
64 const secu_string & password,
65 const std::string & host,
66 const std::string & port,
67 bool auth_from_file,
68 const std::string & sftp_pub_keyfile,
69 const std::string & sftp_prv_keyfile,
70 const std::string & sftp_known_hosts,
71 U_I waiting_time,
72 bool verbose
73 );
74 i_entrepot_libcurl(const i_entrepot_libcurl & ref) = default;
75 i_entrepot_libcurl(i_entrepot_libcurl && ref) = default;
76 i_entrepot_libcurl & operator = (const i_entrepot_libcurl & ref) = delete;
77 i_entrepot_libcurl & operator = (i_entrepot_libcurl && ref) noexcept = delete;
78 ~i_entrepot_libcurl() throw () {};
79
80
81 // inherited from class entrepot
82
85 virtual std::string get_url() const override { return base_URL + get_full_path().display_without_root(); };
86 virtual void change_user_interaction(const std::shared_ptr<user_interaction> & new_dialog) override { change_ui(new_dialog); };
87 virtual std::shared_ptr<user_interaction> get_current_user_interaction() const override { return get_pointer(); };
88 virtual void read_dir_reset() const override { set_current_dir(false); };
89 virtual bool read_dir_next(std::string & filename) const override;
90 virtual void read_dir_reset_dirinfo() const override { set_current_dir(true); };
91 virtual bool read_dir_next_dirinfo(std::string & filename, inode_type &tp) const override;
92
93 virtual void create_dir(const std::string & dirname, U_I permission) override;
94
95 virtual entrepot *clone() const override { return new (std::nothrow) i_entrepot_libcurl(*this); };
96
97 protected:
98
99 // inherited from class entrepot
100
101 virtual fichier_global *inherited_open(const std::shared_ptr<user_interaction> & dialog,
102 const std::string & filename,
103 gf_mode mode,
104 bool force_permission,
105 U_I permission,
106 bool fail_if_exists,
107 bool erase) const override;
108
109 virtual void inherited_unlink(const std::string & filename) const override;
110 virtual void read_dir_flush() const override;
111
112 private:
113 remote_entrepot_type x_proto;
114 std::string base_URL;
115 mutable mycurl_easyhandle_sharing easyh;
116 mutable std::map<std::string, inode_type> current_dir;
117 mutable std::string reading_dir_tmp;
118 mutable std::deque<std::string> temporary_list;
119 mutable std::map<std::string, inode_type>::const_iterator cur_dir_cursor;
120 U_I wait_delay;
121 bool verbosity;
122 mutable bool withdirinfo;
123
124 std::string get_libcurl_URL() const;
125 void set_libcurl_authentication(user_interaction & dialog,
126 const std::string & location,
127 const std::string & login,
128 const secu_string & password,
129 bool auth_from_file,
130 const std::string & sftp_pub_keyfile,
131 const std::string & sftp_prv_keyfile,
132 const std::string & sftp_known_hosts
133 );
134
135 void fill_temporary_list() const;
136 void update_current_dir_with_line(const std::string & line) const;
137 void set_current_dir(bool details) const;
138
139
140 static std::string mycurl_protocol2string(remote_entrepot_type proto);
141 static std::string build_url_from(remote_entrepot_type proto, const std::string & host, const std::string & port);
142 static size_t get_ftp_listing_callback(void *buffer, size_t size, size_t nmemb, void *userp);
143 static size_t null_callback(void *buffer, size_t size, size_t nmemb, void *userp) { return size*nmemb; };
144 static bool mycurl_is_protocol_available(remote_entrepot_type proto);
145
146 // needed to access the entrepot inherited protected methods
147 friend class entrepot_libcurl;
148 };
149
150#endif
152
153} // end of namespace
154
155#endif
libdar::entrepot
the Entrepot interface
Definition entrepot.hpp:57
libdar::mem_ui
class mem_ui to keep a copy of a user_interaction object
Definition mem_ui.hpp:55
entrepot_libcurl.hpp
defines the implementation for remote filesystem entrepot using libcurl
libdar::remote_entrepot_type
remote_entrepot_type
type of entrepot to create
Definition remote_entrepot_api.hpp:44
mem_ui.hpp
class mem_ui definition. This class is to be used as parent class to handle user_interaction object m...
my_config.h
include macro defined by the configure script and some specific additional ones
mycurl_easyhandle_sharing.hpp
used to optimize network session establised by libcurl
libdar
libdar namespace encapsulate all libdar symbols
Definition archive.hpp:47
secu_string.hpp
this file contains the definition of secu_string class, a std::string like class but allocated in sec...