GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
url-transfer.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 2006-2025 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
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;
52};
53
55{
56public:
57
58 friend class url_transfer;
59
61
62 base_url_transfer (const std::string& host,
63 const std::string& /* user_arg */,
64 const std::string& /* passwd */,
65 std::ostream& os);
66
67 base_url_transfer (const std::string& url, std::ostream& os);
68
69 OCTAVE_DISABLE_COPY_MOVE (base_url_transfer)
70
71 virtual ~base_url_transfer () = default;
72
73 bool is_valid () const { return m_valid; }
74
75 bool good () const { return m_valid && m_ok; }
76
77 virtual void perform () { }
78
79 virtual std::string lasterror () const { return m_errmsg; }
80
81 virtual std::ostream& set_ostream (std::ostream& /* os */)
82 {
83 return *m_curr_ostream;
84 }
85
86 virtual std::istream& set_istream (std::istream& /* is */)
87 {
88 return *m_curr_istream;
89 }
90
91 virtual void ascii () { }
92
93 virtual void binary () { }
94
95 bool is_ascii () const { return m_ascii_mode; }
96
97 bool is_binary () const { return ! m_ascii_mode; }
98
99 virtual void cwd (const std::string& /* path */) { }
100
101 virtual void del (const std::string& /* file */) { }
102
103 virtual void rmdir (const std::string& /* path */) { }
104
105 virtual void mkdir (const std::string& /* path */) { }
106
107 virtual void rename (const std::string& /* oldname */,
108 const std::string& /* newname */) { }
109
110 virtual void put (const std::string& /* file */,
111 std::istream& /* is */) { }
112
113 virtual void get (const std::string& /* file */,
114 std::ostream& /* os */) { }
115
116 void mget_directory (const std::string& directory,
117 const std::string& target);
118
119 string_vector mput_directory (const std::string& base,
120 const std::string& directory);
121
122 virtual void dir () { }
123
124 virtual string_vector list () { return string_vector (); }
125
126 virtual void get_fileinfo (const std::string& /* filename */,
127 double& /* filesize */,
128 OCTAVE_TIME_T& /* filetime */,
129 bool& /* fileisdir */) { }
130
131 virtual std::string pwd () { return ""; }
132
133 virtual void http_get (const Array<std::string>& /* param */) { }
134
135 virtual void http_post (const Array<std::string>& /* param */) { }
136
137 virtual void http_action (const Array<std::string>& /* param */,
138 const std::string& /* action */) { }
139
140 virtual void cookie_jar (const std::string& /* filename */) { }
141
142 virtual void set_header_fields (const Array<std::string>& /* param */) { }
143
144 virtual void form_data_post (const Array<std::string>& /* param */) { }
145
146 virtual void set_weboptions (const struct weboptions& /* param */) { }
147
148protected:
149
150 // Host for ftp transfers or full URL for http requests.
151 std::string m_host_or_url;
153 bool m_ftp;
155 bool m_ok;
156 std::string m_errmsg;
157 std::istream *m_curr_istream;
158 std::ostream *m_curr_ostream;
159};
160
162{
163public:
164
165 url_transfer ();
166
167 url_transfer (const std::string& host, const std::string& user,
168 const std::string& passwd, std::ostream& os);
169
170 url_transfer (const std::string& url, std::ostream& os);
171
172 url_transfer (const url_transfer&) = default;
173
174 url_transfer& operator = (const url_transfer&) = default;
175
176 ~url_transfer () = default;
177
178 bool is_valid () const { return m_rep->is_valid (); }
179
180 bool good () const { return m_rep->good (); }
181
182 std::string lasterror () const { return m_rep->lasterror (); }
183
184 std::ostream& set_ostream (std::ostream& os)
185 {
186 return m_rep->set_ostream (os);
187 }
188
189 std::istream& set_istream (std::istream& is)
190 {
191 return m_rep->set_istream (is);
192 }
193
194 void ascii () { m_rep->ascii (); }
195
196 void binary () { m_rep->binary (); }
197
198 bool is_ascii () const { return m_rep->is_ascii (); }
199
200 bool is_binary () const { return m_rep->is_binary (); }
201
202 void cwd (const std::string& path) { m_rep->cwd (path); }
203
204 void del (const std::string& file) { m_rep->del (file); }
205
206 void rmdir (const std::string& path) { m_rep->rmdir (path); }
207
208 void mkdir (const std::string& path) { m_rep->mkdir (path); }
209
210 void rename (const std::string& oldname, const std::string& newname)
211 {
212 m_rep->rename (oldname, newname);
213 }
214
215 void put (const std::string& file, std::istream& is)
216 {
217 m_rep->put (file, is);
218 }
219
220 void get (const std::string& file, std::ostream& os)
221 {
222 m_rep->get (file, os);
223 }
224
225 void mget_directory (const std::string& directory,
226 const std::string& target)
227 {
228 m_rep->mget_directory (directory, target);
229 }
230
231 string_vector mput_directory (const std::string& base,
232 const std::string& directory)
233 {
234 return m_rep->mput_directory (base, directory);
235 }
236
237 void dir () { m_rep->dir (); }
238
239 string_vector list () { return m_rep->list (); }
240
241 void get_fileinfo (const std::string& filename, double& filesize,
242 OCTAVE_TIME_T& filetime, bool& fileisdir)
243 {
244 m_rep->get_fileinfo (filename, filesize, filetime, fileisdir);
245 }
246
247 std::string pwd () { return m_rep->pwd (); }
248
249 void http_get (const Array<std::string>& param)
250 {
251 m_rep->http_get (param);
252 }
253
254 void http_post (const Array<std::string>& param)
255 {
256 m_rep->http_post (param);
257 }
258
259 void http_action (const Array<std::string>& param,
260 const std::string& action)
261 {
262 m_rep->http_action (param, action);
263 }
264
265 void cookie_jar (const std::string& filename)
266 {
267 m_rep->cookie_jar (filename);
268 }
269
271 {
272 m_rep->set_header_fields (param);
273 }
274
276 {
277 m_rep->form_data_post (param);
278 }
279
280 void set_weboptions (const struct weboptions& param)
281 {
282 m_rep->set_weboptions (param);
283 }
284
285private:
286
287 std::shared_ptr<base_url_transfer> m_rep;
288};
289
290OCTAVE_END_NAMESPACE(octave)
291
292#endif
N Dimensional Array with copy-on-write semantics.
Definition Array.h:130
virtual std::ostream & set_ostream(std::ostream &)
virtual void http_get(const Array< std::string > &)
virtual void rename(const std::string &, const std::string &)
std::string m_host_or_url
bool good() const
virtual std::istream & set_istream(std::istream &)
virtual void dir()
virtual void form_data_post(const Array< std::string > &)
bool is_binary() const
std::string m_errmsg
virtual void get(const std::string &, std::ostream &)
virtual void ascii()
virtual void set_weboptions(const struct weboptions &)
virtual void binary()
virtual void put(const std::string &, std::istream &)
virtual void perform()
virtual void set_header_fields(const Array< std::string > &)
virtual void cwd(const std::string &)
virtual std::string pwd()
virtual void cookie_jar(const std::string &)
virtual void del(const std::string &)
std::istream * m_curr_istream
virtual string_vector list()
bool is_ascii() const
virtual void http_post(const Array< std::string > &)
virtual void get_fileinfo(const std::string &, double &, OCTAVE_TIME_T &, bool &)
std::ostream * m_curr_ostream
virtual void http_action(const Array< std::string > &, const std::string &)
virtual void rmdir(const std::string &)
virtual void mkdir(const std::string &)
virtual std::string lasterror() const
void put(const std::string &file, std::istream &is)
void get_fileinfo(const std::string &filename, double &filesize, OCTAVE_TIME_T &filetime, bool &fileisdir)
std::ostream & set_ostream(std::ostream &os)
string_vector list()
~url_transfer()=default
void get(const std::string &file, std::ostream &os)
bool is_ascii() const
void http_post(const Array< std::string > &param)
void cwd(const std::string &path)
void set_header_fields(const Array< std::string > &param)
void set_weboptions(const struct weboptions &param)
bool is_valid() const
void http_get(const Array< std::string > &param)
void mkdir(const std::string &path)
string_vector mput_directory(const std::string &base, const std::string &directory)
std::string lasterror() const
std::istream & set_istream(std::istream &is)
void http_action(const Array< std::string > &param, const std::string &action)
void mget_directory(const std::string &directory, const std::string &target)
std::string pwd()
url_transfer(const url_transfer &)=default
void cookie_jar(const std::string &filename)
void rmdir(const std::string &path)
bool is_binary() const
void del(const std::string &file)
void rename(const std::string &oldname, const std::string &newname)
bool good() const
void form_data_post(const Array< std::string > &param)
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
#define OCTAVE_API
Definition main.in.cc:55
std::string UserAgent
std::string ArrayFormat
std::string ContentReader
std::string RequestMethod
Array< std::string > HeaderFields
std::string Password
std::string CertificateFilename
std::string Username