GNU Octave  8.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
url-transfer.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2006-2023 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if ! defined (octave_url_transfer_h)
27 #define octave_url_transfer_h 1
28 
29 #include "octave-config.h"
30 
31 #include <istream>
32 #include <memory>
33 #include <ostream>
34 #include <string>
35 
36 #include "Array-fwd.h"
37 #include "str-vec.h"
38 
40 
41 struct weboptions
42 {
43  std::string UserAgent;
44  long Timeout;
45  std::string Username;
46  std::string Password;
48  std::string ContentReader;
49  std::string RequestMethod;
50  std::string ArrayFormat;
51  std::string CertificateFilename;
52 };
53 
54 class
57 {
58 public:
59 
60  friend class url_transfer;
61 
62  base_url_transfer (void);
63 
64  base_url_transfer (const std::string& host,
65  const std::string& /* user_arg */,
66  const std::string& /* passwd */,
67  std::ostream& os);
68 
69  base_url_transfer (const std::string& url, std::ostream& os);
70 
71  // No copying!
72 
74 
76 
77  virtual ~base_url_transfer (void) = default;
78 
79  bool is_valid (void) const { return m_valid; }
80 
81  bool good (void) const { return m_valid && m_ok; }
82 
83  virtual void perform (void) { }
84 
85  virtual std::string lasterror (void) const { return m_errmsg; }
86 
87  virtual std::ostream& set_ostream (std::ostream& /* os */)
88  {
89  return *m_curr_ostream;
90  }
91 
92  virtual std::istream& set_istream (std::istream& /* is */)
93  {
94  return *m_curr_istream;
95  }
96 
97  virtual void ascii (void) { }
98 
99  virtual void binary (void) { }
100 
101  bool is_ascii (void) const { return m_ascii_mode; }
102 
103  bool is_binary (void) const { return ! m_ascii_mode; }
104 
105  virtual void cwd (const std::string& /* path */) { }
106 
107  virtual void del (const std::string& /* file */) { }
108 
109  virtual void rmdir (const std::string& /* path */) { }
110 
111  virtual void mkdir (const std::string& /* path */) { }
112 
113  virtual void rename (const std::string& /* oldname */,
114  const std::string& /* newname */) { }
115 
116  virtual void put (const std::string& /* file */,
117  std::istream& /* is */) { }
118 
119  virtual void get (const std::string& /* file */,
120  std::ostream& /* os */) { }
121 
122  void mget_directory (const std::string& directory,
123  const std::string& target);
124 
125  string_vector mput_directory (const std::string& base,
126  const std::string& directory);
127 
128  virtual void dir (void) { }
129 
130  virtual string_vector list (void) { return string_vector (); }
131 
132  virtual void get_fileinfo (const std::string& /* filename */,
133  double& /* filesize */,
134  OCTAVE_TIME_T& /* filetime */,
135  bool& /* fileisdir */) { }
136 
137  virtual std::string pwd (void) { return ""; }
138 
139  virtual void http_get (const Array<std::string>& /* param */) { }
140 
141  virtual void http_post (const Array<std::string>& /* param */) { }
142 
143  virtual void http_action (const Array<std::string>& /* param */,
144  const std::string& /* action */) { }
145 
146  virtual void cookie_jar (const std::string& /* filename */) { }
147 
148  virtual void set_header_fields (const Array<std::string>& /* param */) { }
149 
150  virtual void form_data_post (const Array<std::string>& /* param */) { }
151 
152  virtual void set_weboptions (const struct weboptions& /* param */) { }
153 
154 protected:
155 
156  // Host for ftp transfers or full URL for http requests.
157  std::string m_host_or_url;
158  bool m_valid;
159  bool m_ftp;
161  bool m_ok;
162  std::string m_errmsg;
163  std::istream *m_curr_istream;
164  std::ostream *m_curr_ostream;
165 };
166 
167 class
170 {
171 public:
172 
173  url_transfer (void);
174 
175  url_transfer (const std::string& host, const std::string& user,
176  const std::string& passwd, std::ostream& os);
177 
178  url_transfer (const std::string& url, std::ostream& os);
179 
180  url_transfer (const url_transfer&) = default;
181 
183 
184  ~url_transfer (void) = default;
185 
186  bool is_valid (void) const { return m_rep->is_valid (); }
187 
188  bool good (void) const { return m_rep->good (); }
189 
190  std::string lasterror (void) const { return m_rep->lasterror (); }
191 
192  std::ostream& set_ostream (std::ostream& os)
193  {
194  return m_rep->set_ostream (os);
195  }
196 
197  std::istream& set_istream (std::istream& is)
198  {
199  return m_rep->set_istream (is);
200  }
201 
202  void ascii (void) { m_rep->ascii (); }
203 
204  void binary (void) { m_rep->binary (); }
205 
206  bool is_ascii (void) const { return m_rep->is_ascii (); }
207 
208  bool is_binary (void) const { return m_rep->is_binary (); }
209 
210  void cwd (const std::string& path) { m_rep->cwd (path); }
211 
212  void del (const std::string& file) { m_rep->del (file); }
213 
214  void rmdir (const std::string& path) { m_rep->rmdir (path); }
215 
216  void mkdir (const std::string& path) { m_rep->mkdir (path); }
217 
218  void rename (const std::string& oldname, const std::string& newname)
219  {
220  m_rep->rename (oldname, newname);
221  }
222 
223  void put (const std::string& file, std::istream& is)
224  {
225  m_rep->put (file, is);
226  }
227 
228  void get (const std::string& file, std::ostream& os)
229  {
230  m_rep->get (file, os);
231  }
232 
233  void mget_directory (const std::string& directory,
234  const std::string& target)
235  {
236  m_rep->mget_directory (directory, target);
237  }
238 
239  string_vector mput_directory (const std::string& base,
240  const std::string& directory)
241  {
242  return m_rep->mput_directory (base, directory);
243  }
244 
245  void dir (void) { m_rep->dir (); }
246 
247  string_vector list (void) { return m_rep->list (); }
248 
249  void get_fileinfo (const std::string& filename, double& filesize,
250  OCTAVE_TIME_T& filetime, bool& fileisdir)
251  {
252  m_rep->get_fileinfo (filename, filesize, filetime, fileisdir);
253  }
254 
255  std::string pwd (void) { return m_rep->pwd (); }
256 
257  void http_get (const Array<std::string>& param)
258  {
259  m_rep->http_get (param);
260  }
261 
262  void http_post (const Array<std::string>& param)
263  {
264  m_rep->http_post (param);
265  }
266 
267  void http_action (const Array<std::string>& param,
268  const std::string& action)
269  {
270  m_rep->http_action (param, action);
271  }
272 
273  void cookie_jar (const std::string& filename)
274  {
275  m_rep->cookie_jar (filename);
276  }
277 
279  {
280  m_rep->set_header_fields (param);
281  }
282 
283  void form_data_post (const Array<std::string>& param)
284  {
285  m_rep->form_data_post (param);
286  }
287 
288  void set_weboptions (const struct weboptions& param)
289  {
290  m_rep->set_weboptions (param);
291  }
292 
293 private:
294 
295  std::shared_ptr<base_url_transfer> m_rep;
296 };
297 
299 
300 #endif
OCTAVE_END_NAMESPACE(octave)
virtual void http_get(const Array< std::string > &)
Definition: url-transfer.h:139
virtual void ascii(void)
Definition: url-transfer.h:97
virtual void rename(const std::string &, const std::string &)
Definition: url-transfer.h:113
std::string m_host_or_url
Definition: url-transfer.h:157
bool good(void) const
Definition: url-transfer.h:81
virtual void form_data_post(const Array< std::string > &)
Definition: url-transfer.h:150
std::string m_errmsg
Definition: url-transfer.h:162
virtual void get(const std::string &, std::ostream &)
Definition: url-transfer.h:119
virtual void binary(void)
Definition: url-transfer.h:99
virtual ~base_url_transfer(void)=default
virtual void set_weboptions(const struct weboptions &)
Definition: url-transfer.h:152
virtual void put(const std::string &, std::istream &)
Definition: url-transfer.h:116
virtual void set_header_fields(const Array< std::string > &)
Definition: url-transfer.h:148
bool is_valid(void) const
Definition: url-transfer.h:79
virtual void cwd(const std::string &)
Definition: url-transfer.h:105
virtual void cookie_jar(const std::string &)
Definition: url-transfer.h:146
virtual void perform(void)
Definition: url-transfer.h:83
virtual void del(const std::string &)
Definition: url-transfer.h:107
std::istream * m_curr_istream
Definition: url-transfer.h:163
virtual void dir(void)
Definition: url-transfer.h:128
virtual std::string pwd(void)
Definition: url-transfer.h:137
virtual std::istream & set_istream(std::istream &)
Definition: url-transfer.h:92
virtual void http_post(const Array< std::string > &)
Definition: url-transfer.h:141
virtual void get_fileinfo(const std::string &, double &, OCTAVE_TIME_T &, bool &)
Definition: url-transfer.h:132
virtual std::string lasterror(void) const
Definition: url-transfer.h:85
virtual string_vector list(void)
Definition: url-transfer.h:130
virtual std::ostream & set_ostream(std::ostream &)
Definition: url-transfer.h:87
bool is_binary(void) const
Definition: url-transfer.h:103
bool is_ascii(void) const
Definition: url-transfer.h:101
std::ostream * m_curr_ostream
Definition: url-transfer.h:164
virtual void http_action(const Array< std::string > &, const std::string &)
Definition: url-transfer.h:143
virtual void rmdir(const std::string &)
Definition: url-transfer.h:109
base_url_transfer(const base_url_transfer &)=delete
virtual void mkdir(const std::string &)
Definition: url-transfer.h:111
void put(const std::string &file, std::istream &is)
Definition: url-transfer.h:223
void get_fileinfo(const std::string &filename, double &filesize, OCTAVE_TIME_T &filetime, bool &fileisdir)
Definition: url-transfer.h:249
std::ostream & set_ostream(std::ostream &os)
Definition: url-transfer.h:192
void ascii(void)
Definition: url-transfer.h:202
void get(const std::string &file, std::ostream &os)
Definition: url-transfer.h:228
void http_post(const Array< std::string > &param)
Definition: url-transfer.h:262
void binary(void)
Definition: url-transfer.h:204
void cwd(const std::string &path)
Definition: url-transfer.h:210
void set_header_fields(const Array< std::string > &param)
Definition: url-transfer.h:278
void set_weboptions(const struct weboptions &param)
Definition: url-transfer.h:288
bool is_valid(void) const
Definition: url-transfer.h:186
bool is_ascii(void) const
Definition: url-transfer.h:206
std::istream & set_istream(std::istream &is)
Definition: url-transfer.h:197
void http_get(const Array< std::string > &param)
Definition: url-transfer.h:257
void mkdir(const std::string &path)
Definition: url-transfer.h:216
string_vector mput_directory(const std::string &base, const std::string &directory)
Definition: url-transfer.h:239
bool good(void) const
Definition: url-transfer.h:188
string_vector list(void)
Definition: url-transfer.h:247
void http_action(const Array< std::string > &param, const std::string &action)
Definition: url-transfer.h:267
url_transfer(void)
std::string lasterror(void) const
Definition: url-transfer.h:190
url_transfer & operator=(const url_transfer &)=default
void mget_directory(const std::string &directory, const std::string &target)
Definition: url-transfer.h:233
void dir(void)
Definition: url-transfer.h:245
url_transfer(const url_transfer &)=default
~url_transfer(void)=default
std::string pwd(void)
Definition: url-transfer.h:255
void cookie_jar(const std::string &filename)
Definition: url-transfer.h:273
bool is_binary(void) const
Definition: url-transfer.h:208
void rmdir(const std::string &path)
Definition: url-transfer.h:214
std::shared_ptr< base_url_transfer > m_rep
Definition: url-transfer.h:295
void del(const std::string &file)
Definition: url-transfer.h:212
void rename(const std::string &oldname, const std::string &newname)
Definition: url-transfer.h:218
void form_data_post(const Array< std::string > &param)
Definition: url-transfer.h:283
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
#define OCTAVE_API
Definition: main.in.cc:55
std::string UserAgent
Definition: url-transfer.h:43
std::string ArrayFormat
Definition: url-transfer.h:50
std::string ContentReader
Definition: url-transfer.h:48
std::string RequestMethod
Definition: url-transfer.h:49
Array< std::string > HeaderFields
Definition: url-transfer.h:47
std::string Password
Definition: url-transfer.h:46
long Timeout
Definition: url-transfer.h:44
std::string CertificateFilename
Definition: url-transfer.h:51
std::string Username
Definition: url-transfer.h:45