26 #ifndef MYCURL_EASYHANDLE_NODE_HPP
27 #define MYCURL_EASYHANDLE_NODE_HPP
29 #include "../my_config.h"
35 #include <curl/curl.h>
57 class mycurl_easyhandle_node
61 mycurl_easyhandle_node() { init(); };
64 mycurl_easyhandle_node(
const mycurl_easyhandle_node & ref);
67 mycurl_easyhandle_node(mycurl_easyhandle_node && ref) noexcept;
70 mycurl_easyhandle_node & operator = (
const mycurl_easyhandle_node & ref);
73 mycurl_easyhandle_node & operator = (mycurl_easyhandle_node && ref) noexcept;
76 ~mycurl_easyhandle_node() {
if(handle !=
nullptr) curl_easy_cleanup(handle); };
79 template<
class T>
void setopt(CURLoption opt,
const T & val) { check_for_type(opt, val); wanted.add(opt, val); }
82 void setopt_list(
const mycurl_param_list & listing) { (void) wanted.update_with(listing); };
85 void setopt_default(CURLoption opt);
88 void setopt_all_default();
91 void apply(
const std::shared_ptr<user_interaction> & dialog,
93 const bool & end_anyway =
false);
97 template<
class T>
void getinfo(CURLINFO info, T* val)
99 CURLcode err = curl_easy_getinfo(handle, info, val);
101 throw Erange(
"mycurl_easyhandle_node::getinfo",
102 tools_printf(gettext(
"Error met while fetching info %d: %s"),
104 curl_easy_strerror(err)));
107 static void init_defaults();
108 static void release_defaults() { defaults.clear(); };
128 mycurl_param_list current;
129 mycurl_param_list wanted;
132 template<
class T>
void set_to_default(CURLoption opt)
136 if(current.get_val(opt, ptr))
138 if(defaults.get_val(opt, ptr))
139 wanted.add(opt, *ptr);
158 static constexpr
const opt_asso association[] =
160 { CURLOPT_APPEND, type_long },
161 { CURLOPT_DIRLISTONLY, type_long },
162 { CURLOPT_NETRC, type_long },
163 { CURLOPT_NOBODY, type_long },
164 { CURLOPT_SSH_KNOWNHOSTS, type_string },
165 { CURLOPT_SSH_PUBLIC_KEYFILE, type_string },
166 { CURLOPT_SSH_PRIVATE_KEYFILE, type_string },
167 { CURLOPT_SSH_AUTH_TYPES, type_long },
168 { CURLOPT_QUOTE, type_mycurl_slist },
169 { CURLOPT_RANGE, type_string },
170 { CURLOPT_READDATA, type_pointer },
171 { CURLOPT_READFUNCTION, type_pointer },
172 { CURLOPT_RESUME_FROM_LARGE, type_curl_off_t },
173 { CURLOPT_UPLOAD, type_long },
174 { CURLOPT_URL, type_string },
175 { CURLOPT_USERNAME, type_string },
176 { CURLOPT_USERPWD, type_secu_string },
177 { CURLOPT_VERBOSE, type_long },
178 { CURLOPT_WRITEDATA, type_pointer },
179 { CURLOPT_WRITEFUNCTION, type_pointer },
181 { CURLOPT_APPEND, eolist }
184 static opttype get_opt_type(CURLoption opt);
186 static bool defaults_initialized;
187 static mycurl_param_list defaults;
189 template <
class T>
void check_for_type(CURLoption opt,
const T & val)
191 switch(get_opt_type(opt))
194 if(
typeid(val) !=
typeid(std::string))
197 case type_secu_string:
198 if(
typeid(val) !=
typeid(secu_string))
202 if(
typeid(val) !=
typeid(
void *))
206 if(
typeid(val) !=
typeid(
long))
209 case type_mycurl_slist:
210 if(
typeid(val) !=
typeid(mycurl_slist))
213 case type_curl_off_t:
214 if(
typeid(val) !=
typeid(curl_off_t))
std::string tools_printf(const char *format,...)
make printf-like formating to a std::string
wrapper for element a CURL* object can receive as parameter in order to be put in etherogeneous list
wrapper of the curl_slist struct to allow usual copy/move on C++ object
libdar namespace encapsulate all libdar symbols
defines the interaction interface between libdar and users.