# HG changeset patch # User John W. Eaton # Date 1560350621 18000 # Node ID b42350f18afbe88afc813bf7e7b4a7a0b2f1464e # Parent f3450193272d114d90004c895d6d86bc3c3ec95f style fixes for url-transfer classes * url-transfer.cc, url-transfer.h: Use m_ prefix for member variables. diff -r f3450193272d -r b42350f18afb liboctave/util/url-transfer.cc --- a/liboctave/util/url-transfer.cc Wed Jun 12 08:48:15 2019 -0500 +++ b/liboctave/util/url-transfer.cc Wed Jun 12 09:43:41 2019 -0500 @@ -51,23 +51,26 @@ namespace octave { base_url_transfer::base_url_transfer (void) - : host_or_url (), valid (false), ftp (false), - ascii_mode (false), ok (true), errmsg (), - curr_istream (&std::cin), curr_ostream (&std::cout) { } + : m_host_or_url (), m_valid (false), m_ftp (false), + m_ascii_mode (false), m_ok (true), m_errmsg (), + m_curr_istream (&std::cin), m_curr_ostream (&std::cout) + { } base_url_transfer::base_url_transfer (const std::string& host, const std::string& /* user_arg */, const std::string& /* passwd */, std::ostream& os) - : host_or_url (host), valid (false), ftp (true), - ascii_mode (false), ok (true), errmsg (), curr_istream (&std::cin), - curr_ostream (&os) { } + : m_host_or_url (host), m_valid (false), m_ftp (true), + m_ascii_mode (false), m_ok (true), m_errmsg (), + m_curr_istream (&std::cin), m_curr_ostream (&os) + { } base_url_transfer::base_url_transfer (const std::string& url, std::ostream& os) - : host_or_url (url), valid (false), ftp (false), - ascii_mode (false), ok (true), errmsg (), - curr_istream (&std::cin), curr_ostream (&os) { } + : m_host_or_url (url), m_valid (false), m_ftp (false), + m_ascii_mode (false), m_ok (true), m_errmsg (), + m_curr_istream (&std::cin), m_curr_ostream (&os) + { } void base_url_transfer::delete_file (const std::string& file) @@ -89,8 +92,8 @@ if (status < 0) { - ok = false; - errmsg = "__ftp_mget__: can not create directory '" + m_ok = false; + m_errmsg = "__ftp_mget__: can not create directory '" + target + sep + directory + "': " + msg; return; } @@ -125,8 +128,8 @@ if (! ofile.is_open ()) { - ok = false; - errmsg = "__ftp_mget__: unable to open file"; + m_ok = false; + m_errmsg = "__ftp_mget__: unable to open file"; break; } @@ -182,13 +185,15 @@ if (file == "." || file == "..") continue; - std::string realfile = realdir + sys::file_ops::dir_sep_str () + file; + std::string realfile + = realdir + sys::file_ops::dir_sep_str () + file; + sys::file_stat fs (realfile); if (! fs.exists ()) { - ok = false; - errmsg = "__ftp__mput: file '" + realfile + m_ok = false; + m_errmsg = "__ftp__mput: file '" + realfile + "' does not exist"; break; } @@ -210,8 +215,8 @@ if (! ifile.is_open ()) { - ok = false; - errmsg = "__ftp_mput__: unable to open file '" + m_ok = false; + m_errmsg = "__ftp_mput__: unable to open file '" + realfile + "'"; break; } @@ -228,8 +233,8 @@ } else { - ok = false; - errmsg = "__ftp_mput__: can not read the directory '" + m_ok = false; + m_errmsg = "__ftp_mput__: can not read the directory '" + realdir + "'"; } } @@ -270,11 +275,11 @@ #define SETOPT(option, parameter) \ do \ { \ - CURLcode res = curl_easy_setopt (curl, option, parameter); \ + CURLcode res = curl_easy_setopt (m_curl, option, parameter); \ if (res != CURLE_OK) \ { \ - ok = false; \ - errmsg = curl_easy_strerror (res); \ + m_ok = false; \ + m_errmsg = curl_easy_strerror (res); \ return; \ } \ } \ @@ -284,11 +289,11 @@ #define SETOPTR(option, parameter) \ do \ { \ - CURLcode res = curl_easy_setopt (curl, option, parameter); \ + CURLcode res = curl_easy_setopt (m_curl, option, parameter); \ if (res != CURLE_OK) \ { \ - ok = false; \ - errmsg = curl_easy_strerror (res); \ + m_ok = false; \ + m_errmsg = curl_easy_strerror (res); \ return retval; \ } \ } \ @@ -299,46 +304,46 @@ public: curl_transfer (void) - : base_url_transfer (), curl (curl_easy_init ()), errnum (), url (), - userpwd () + : base_url_transfer (), m_curl (curl_easy_init ()), m_errnum (), m_url (), + m_userpwd () { - if (curl) - valid = true; + if (m_curl) + m_valid = true; else - errmsg = "can not create curl object"; + m_errmsg = "can not create curl object"; } curl_transfer (const std::string& host, const std::string& user_arg, const std::string& passwd, std::ostream& os) : base_url_transfer (host, user_arg, passwd, os), - curl (curl_easy_init ()), errnum (), url (), userpwd () + m_curl (curl_easy_init ()), m_errnum (), m_url (), m_userpwd () { - if (curl) - valid = true; + if (m_curl) + m_valid = true; else { - errmsg = "can not create curl object"; + m_errmsg = "can not create curl object"; return; } init (user_arg, passwd, std::cin, os); - url = "ftp://" + host; - SETOPT (CURLOPT_URL, url.c_str ()); + m_url = "ftp://" + host; + SETOPT (CURLOPT_URL, m_url.c_str ()); // Set up the link, with no transfer. perform (); } curl_transfer (const std::string& url_str, std::ostream& os) - : base_url_transfer (url_str, os), curl (curl_easy_init ()), errnum (), - url (), userpwd () + : base_url_transfer (url_str, os), m_curl (curl_easy_init ()), + m_errnum (), m_url (), m_userpwd () { - if (curl) - valid = true; + if (m_curl) + m_valid = true; else { - errmsg = "can not create curl object"; + m_errmsg = "can not create curl object"; return; } @@ -369,20 +374,20 @@ ~curl_transfer (void) { - if (curl) - curl_easy_cleanup (curl); + if (m_curl) + curl_easy_cleanup (m_curl); } void perform (void) { BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; - errnum = curl_easy_perform (curl); + m_errnum = curl_easy_perform (m_curl); - if (errnum != CURLE_OK) + if (m_errnum != CURLE_OK) { - ok = false; - errmsg = curl_easy_strerror (errnum); + m_ok = false; + m_errmsg = curl_easy_strerror (m_errnum); } END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; @@ -390,34 +395,34 @@ std::string lasterror (void) const { - return std::string (curl_easy_strerror (errnum)); + return std::string (curl_easy_strerror (m_errnum)); } std::ostream& set_ostream (std::ostream& os) { - std::ostream& retval = *curr_ostream; - curr_ostream = &os; - SETOPTR (CURLOPT_WRITEDATA, static_cast (curr_ostream)); + std::ostream& retval = *m_curr_ostream; + m_curr_ostream = &os; + SETOPTR (CURLOPT_WRITEDATA, static_cast (m_curr_ostream)); return retval; } std::istream& set_istream (std::istream& is) { - std::istream& retval = *curr_istream; - curr_istream = &is; - SETOPTR (CURLOPT_READDATA, static_cast (curr_istream)); + std::istream& retval = *m_curr_istream; + m_curr_istream = &is; + SETOPTR (CURLOPT_READDATA, static_cast (m_curr_istream)); return retval; } void ascii (void) { - ascii_mode = true; + m_ascii_mode = true; SETOPT (CURLOPT_TRANSFERTEXT, 1); } void binary (void) { - ascii_mode = false; + m_ascii_mode = false; SETOPT (CURLOPT_TRANSFERTEXT, 0); } @@ -463,8 +468,8 @@ void put (const std::string& file, std::istream& is) { - url = "ftp://" + host_or_url + '/' + file; - SETOPT (CURLOPT_URL, url.c_str ()); + m_url = "ftp://" + m_host_or_url + '/' + file; + SETOPT (CURLOPT_URL, m_url.c_str ()); SETOPT (CURLOPT_UPLOAD, 1); SETOPT (CURLOPT_NOBODY, 0); std::istream& old_is = set_istream (is); @@ -476,14 +481,14 @@ set_istream (old_is); SETOPT (CURLOPT_NOBODY, 1); SETOPT (CURLOPT_UPLOAD, 0); - url = "ftp://" + host_or_url; - SETOPT (CURLOPT_URL, url.c_str ()); + m_url = "ftp://" + m_host_or_url; + SETOPT (CURLOPT_URL, m_url.c_str ()); } void get (const std::string& file, std::ostream& os) { - url = "ftp://" + host_or_url + '/' + file; - SETOPT (CURLOPT_URL, url.c_str ()); + m_url = "ftp://" + m_host_or_url + '/' + file; + SETOPT (CURLOPT_URL, m_url.c_str ()); SETOPT (CURLOPT_NOBODY, 0); std::ostream& old_os = set_ostream (os); @@ -493,14 +498,14 @@ set_ostream (old_os); SETOPT (CURLOPT_NOBODY, 1); - url = "ftp://" + host_or_url; - SETOPT (CURLOPT_URL, url.c_str ()); + m_url = "ftp://" + m_host_or_url; + SETOPT (CURLOPT_URL, m_url.c_str ()); } void dir (void) { - url = "ftp://" + host_or_url + '/'; - SETOPT (CURLOPT_URL, url.c_str ()); + m_url = "ftp://" + m_host_or_url + '/'; + SETOPT (CURLOPT_URL, m_url.c_str ()); SETOPT (CURLOPT_NOBODY, 0); perform (); @@ -508,8 +513,8 @@ return; SETOPT (CURLOPT_NOBODY, 1); - url = "ftp://" + host_or_url; - SETOPT (CURLOPT_URL, url.c_str ()); + m_url = "ftp://" + m_host_or_url; + SETOPT (CURLOPT_URL, m_url.c_str ()); } string_vector list (void) @@ -517,9 +522,9 @@ string_vector retval; std::ostringstream buf; - url = "ftp://" + host_or_url + '/'; + m_url = "ftp://" + m_host_or_url + '/'; SETOPTR (CURLOPT_WRITEDATA, static_cast (&buf)); - SETOPTR (CURLOPT_URL, url.c_str ()); + SETOPTR (CURLOPT_URL, m_url.c_str ()); SETOPTR (CURLOPT_DIRLISTONLY, 1); SETOPTR (CURLOPT_NOBODY, 0); @@ -528,10 +533,10 @@ return retval; SETOPTR (CURLOPT_NOBODY, 1); - url = "ftp://" + host_or_url; - SETOPTR (CURLOPT_WRITEDATA, static_cast (curr_ostream)); + m_url = "ftp://" + m_host_or_url; + SETOPTR (CURLOPT_WRITEDATA, static_cast (m_curr_ostream)); SETOPTR (CURLOPT_DIRLISTONLY, 0); - SETOPTR (CURLOPT_URL, url.c_str ()); + SETOPTR (CURLOPT_URL, m_url.c_str ()); // Count number of directory entries std::string str = buf.str (); @@ -565,8 +570,8 @@ { std::string path = pwd (); - url = "ftp://" + host_or_url + '/' + path + '/' + filename; - SETOPT (CURLOPT_URL, url.c_str ()); + m_url = "ftp://" + m_host_or_url + '/' + path + '/' + filename; + SETOPT (CURLOPT_URL, m_url.c_str ()); SETOPT (CURLOPT_FILETIME, 1); SETOPT (CURLOPT_HEADERFUNCTION, throw_away); SETOPT (CURLOPT_WRITEFUNCTION, throw_away); @@ -588,17 +593,17 @@ fileisdir = false; time_t ft; - curl_easy_getinfo (curl, CURLINFO_FILETIME, &ft); + curl_easy_getinfo (m_curl, CURLINFO_FILETIME, &ft); filetime = ft; double fs; - curl_easy_getinfo (curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &fs); + curl_easy_getinfo (m_curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &fs); filesize = fs; SETOPT (CURLOPT_WRITEFUNCTION, write_data); SETOPT (CURLOPT_HEADERFUNCTION, 0); SETOPT (CURLOPT_FILETIME, 0); - url = "ftp://" + host_or_url; - SETOPT (CURLOPT_URL, url.c_str ()); + m_url = "ftp://" + m_host_or_url; + SETOPT (CURLOPT_URL, m_url.c_str ()); // The MDTM command seems to reset the path to the root with the // servers I tested with, so cd again into the correct path. Make @@ -653,7 +658,7 @@ void http_action (const Array& param, const std::string& action) { - url = host_or_url; + m_url = m_host_or_url; std::string query_string; @@ -662,9 +667,9 @@ if (action.empty () || action == "get") { if (! query_string.empty ()) - url += '?' + query_string; + m_url += '?' + query_string; - SETOPT (CURLOPT_URL, url.c_str ()); + SETOPT (CURLOPT_URL, m_url.c_str ()); } else if (action == "post" || action == "put" || action == "delete") { @@ -680,15 +685,15 @@ SETOPT (CURLOPT_CUSTOMREQUEST, "DELETE"); } - SETOPT (CURLOPT_URL, url.c_str ()); + SETOPT (CURLOPT_URL, m_url.c_str ()); } else { - ok = false; - errmsg = "curl_transfer: unknown http action"; + m_ok = false; + m_errmsg = "curl_transfer: unknown http action"; } - if (ok) + if (m_ok) perform (); } @@ -731,7 +736,7 @@ { struct curl_httppost *post = NULL, *last = NULL; - SETOPT (CURLOPT_URL, host_or_url.c_str ()); + SETOPT (CURLOPT_URL, m_host_or_url.c_str ()); unwind_protect frame; @@ -745,8 +750,8 @@ std::string data = param(i+1); if (name == "file") - curl_formadd(&post, &last, CURLFORM_COPYNAME, name.c_str (), - CURLFORM_FILE, data.c_str (), CURLFORM_END); + curl_formadd (&post, &last, CURLFORM_COPYNAME, name.c_str (), + CURLFORM_FILE, data.c_str (), CURLFORM_END); else curl_formadd(&post, &last, CURLFORM_COPYNAME, name.c_str (), CURLFORM_COPYCONTENTS, data.c_str (), CURLFORM_END); @@ -774,10 +779,15 @@ if (! options.Username.empty ()) { if (! options.Password.empty ()) - SETOPT (CURLOPT_USERPWD, (options.Username + ":" + options.Password) - .c_str ()); + { + std::string tmp = options.Username + ":" + options.Password; + SETOPT (CURLOPT_USERPWD, tmp.c_str ()); + } else - SETOPT (CURLOPT_USERPWD, (options.Username + ":").c_str ()); + { + std::string tmp = options.Username + ":"; + SETOPT (CURLOPT_USERPWD, tmp.c_str ()); + } } // Unimplemented. Only for MATLAB complatiblity. @@ -796,10 +806,10 @@ private: // Pointer to cURL object. - CURL *curl; + CURL *m_curl; // cURL error code. - CURLcode errnum; + CURLcode m_errnum; // The cURL library changed the curl_easy_setopt call to make an // internal copy of string parameters in version 7.17.0. Prior @@ -814,8 +824,8 @@ // the handle is released. The curl_handle::curl_handle_rep class // contains the pointer to the CURL handle and so is the best // candidate for storing the strings as well. (bug #36717) - std::string url; - std::string userpwd; + std::string m_url; + std::string m_userpwd; void init (const std::string& user, const std::string& passwd, std::istream& is, std::ostream& os) @@ -824,11 +834,11 @@ SETOPT (CURLOPT_NOBODY, 1); // Set the username and password - userpwd = user; + m_userpwd = user; if (! passwd.empty ()) - userpwd += ':' + passwd; - if (! userpwd.empty ()) - SETOPT (CURLOPT_USERPWD, userpwd.c_str ()); + m_userpwd += ':' + passwd; + if (! m_userpwd.empty ()) + SETOPT (CURLOPT_USERPWD, m_userpwd.c_str ()); // Define our callback to get called when there's data to be written. SETOPT (CURLOPT_WRITEFUNCTION, write_data); @@ -879,9 +889,9 @@ std::string text = param(i+1); // Encode strings. - char *enc_name = curl_easy_escape (curl, name.c_str (), + char *enc_name = curl_easy_escape (m_curl, name.c_str (), name.length ()); - char *enc_text = curl_easy_escape (curl, text.c_str (), + char *enc_text = curl_easy_escape (m_curl, text.c_str (), text.length ()); query << enc_name << '=' << enc_text; @@ -932,16 +942,16 @@ # define REP_CLASS base_url_transfer #endif - url_transfer::url_transfer (void) : rep (new REP_CLASS ()) + url_transfer::url_transfer (void) : m_rep (new REP_CLASS ()) { } url_transfer::url_transfer (const std::string& host, const std::string& user, const std::string& passwd, std::ostream& os) - : rep (new REP_CLASS (host, user, passwd, os)) + : m_rep (new REP_CLASS (host, user, passwd, os)) { } url_transfer::url_transfer (const std::string& url, std::ostream& os) - : rep (new REP_CLASS (url, os)) + : m_rep (new REP_CLASS (url, os)) { } #undef REP_CLASS diff -r f3450193272d -r b42350f18afb liboctave/util/url-transfer.h --- a/liboctave/util/url-transfer.h Wed Jun 12 08:48:15 2019 -0500 +++ b/liboctave/util/url-transfer.h Wed Jun 12 09:43:41 2019 -0500 @@ -88,31 +88,31 @@ virtual ~base_url_transfer (void) = default; - bool is_valid (void) const { return valid; } + bool is_valid (void) const { return m_valid; } - bool good (void) const { return valid && ok; } + bool good (void) const { return m_valid && m_ok; } virtual void perform (void) { } - virtual std::string lasterror (void) const { return errmsg; } + virtual std::string lasterror (void) const { return m_errmsg; } virtual std::ostream& set_ostream (std::ostream& /* os */) { - return *curr_ostream; + return *m_curr_ostream; } virtual std::istream& set_istream (std::istream& /* is */) { - return *curr_istream; + return *m_curr_istream; } virtual void ascii (void) { } virtual void binary (void) { } - bool is_ascii (void) const { return ascii_mode; } + bool is_ascii (void) const { return m_ascii_mode; } - bool is_binary (void) const { return ! ascii_mode; } + bool is_binary (void) const { return ! m_ascii_mode; } virtual void cwd (const std::string& /* path */) { } @@ -162,17 +162,18 @@ virtual void form_data_post (const Array& /* param */) { } virtual void set_weboptions (const struct weboptions& /* param */) { } + protected: // Host for ftp transfers or full URL for http requests. - std::string host_or_url; - bool valid; - bool ftp; - bool ascii_mode; - bool ok; - std::string errmsg; - std::istream *curr_istream; - std::ostream *curr_ostream; + std::string m_host_or_url; + bool m_valid; + bool m_ftp; + bool m_ascii_mode; + bool m_ok; + std::string m_errmsg; + std::istream *m_curr_istream; + std::ostream *m_curr_ostream; }; class @@ -194,109 +195,116 @@ ~url_transfer (void) = default; - bool is_valid (void) const { return rep->is_valid (); } + bool is_valid (void) const { return m_rep->is_valid (); } - bool good (void) const { return rep->good (); } + bool good (void) const { return m_rep->good (); } - std::string lasterror (void) const { return rep->lasterror (); } + std::string lasterror (void) const { return m_rep->lasterror (); } std::ostream& set_ostream (std::ostream& os) { - return rep->set_ostream (os); + return m_rep->set_ostream (os); } std::istream& set_istream (std::istream& is) { - return rep->set_istream (is); + return m_rep->set_istream (is); } - void ascii (void) { rep->ascii (); } + void ascii (void) { m_rep->ascii (); } - void binary (void) { rep->binary (); } + void binary (void) { m_rep->binary (); } - bool is_ascii (void) const { return rep->is_ascii (); } + bool is_ascii (void) const { return m_rep->is_ascii (); } - bool is_binary (void) const { return rep->is_binary (); } + bool is_binary (void) const { return m_rep->is_binary (); } - void cwd (const std::string& path) { rep->cwd (path); } + void cwd (const std::string& path) { m_rep->cwd (path); } - void del (const std::string& file) { rep->del (file); } + void del (const std::string& file) { m_rep->del (file); } - void rmdir (const std::string& path) { rep->rmdir (path); } + void rmdir (const std::string& path) { m_rep->rmdir (path); } - void mkdir (const std::string& path) { rep->mkdir (path); } + void mkdir (const std::string& path) { m_rep->mkdir (path); } void rename (const std::string& oldname, const std::string& newname) { - rep->rename (oldname, newname); + m_rep->rename (oldname, newname); } void put (const std::string& file, std::istream& is) { - rep->put (file, is); + m_rep->put (file, is); } void get (const std::string& file, std::ostream& os) { - rep->get (file, os); + m_rep->get (file, os); } void mget_directory (const std::string& directory, const std::string& target) { - rep->mget_directory (directory, target); + m_rep->mget_directory (directory, target); } string_vector mput_directory (const std::string& base, const std::string& directory) { - return rep->mput_directory (base, directory); + return m_rep->mput_directory (base, directory); } - void dir (void) { rep->dir (); } + void dir (void) { m_rep->dir (); } - string_vector list (void) { return rep->list (); } + string_vector list (void) { return m_rep->list (); } void get_fileinfo (const std::string& filename, double& filesize, time_t& filetime, bool& fileisdir) { - rep->get_fileinfo (filename, filesize, filetime, fileisdir); + m_rep->get_fileinfo (filename, filesize, filetime, fileisdir); } - std::string pwd (void) { return rep->pwd (); } + std::string pwd (void) { return m_rep->pwd (); } - void http_get (const Array& param) { rep->http_get (param); } + void http_get (const Array& param) + { + m_rep->http_get (param); + } - void http_post (const Array& param) { rep->http_post (param); } + void http_post (const Array& param) + { + m_rep->http_post (param); + } void http_action (const Array& param, const std::string& action) { - rep->http_action (param, action); + m_rep->http_action (param, action); } void cookie_jar (const std::string& filename) { - rep->cookie_jar (filename); + m_rep->cookie_jar (filename); } void set_header_fields (const Array& param) { - rep->set_header_fields (param); + m_rep->set_header_fields (param); } void form_data_post (const Array& param) { - rep->form_data_post (param); + m_rep->form_data_post (param); } void set_weboptions (const struct weboptions& param) { - rep->set_weboptions (param); + m_rep->set_weboptions (param); } + private: - std::shared_ptr rep; + std::shared_ptr m_rep; }; }