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