Mercurial > octave-nkf
annotate src/DLD-FUNCTIONS/urlwrite.cc @ 13985:43cc49c7abd1
Use thread-safe atomic reference counting (GCC and MSVC).
* configure.ac: New --enable-atomic-refcount argument.
(octave_allocator): Fix USE_OCTAVE_ALLOCATOR variable assignment.
(OCTAVE_CONFIG_INCLUDED): New macro in config.h.
* oct-refcount.h (OCTREFCOUNT_ATOMIC_INCREMENT,
OCTREFCOUNT_ATOMIC_INCREMENT_POST, OCTREFCOUNT_ATOMIC_DECREMENT,
OCTREFCOUNT_ATOMIC_DECREMENT_POST): New macro, defined for MSVC and GCC
when USE_ATOMIC_REFCOUNT is defined.
(octave_refcount:operator++, octave_refcount::operator--): Use them.
(octave_refcount::operator count_type): Cast returned value to volatile.
(octave_refcount::direct): Remove unsafe member.
* Array.h (Array::make_unique): Delete rep if refcount reaches 0.
* Sparse.h (Sparse::make_unique): Delete rep if refcount reaches 0.
* Array.h (Array:~Array, Array::operator=): Delete rep only when refcount is
excatly 0.
* Array.cc (Array::clear): Likewise.
* Sparse.cc (Sparse::~Sparse, Sparse::operator=): Likewise.
* SparseCmplxQR.h (SparseCmplxQR::~SparseCmplxQR, SparseCmplxQR::operator=):
Likewise.
* SparseQR.h (SparseQR::~SparseQR, SparseQR::operator=): Likewise.
* sparse-base-chol.h (sparse_base_chol::~sparse_base_chol,
sparse_base_chol::operator): Likewise.
* dim-vector.h (oct-refcount.h): New included header.
(dim_vector::make_unique, dim_vector::resize): Use OCTREFCOUNT_ATOMIC_DECREMENT
macro and delete rep when refcount reaches 0.
(dim_vector::dim_vector): Use OCTREFCOUNT_ATOMIC_INCREMENT.
(dim_vector::operator=): Use OCTREFCOUNT_ATOMIC_INCREMENT and
OCTREFCOUNT_ATOMIC_DECREMENT.
(dim_vector::~dim_vector): Use OCTREFCOUNT_ATOMIC_DECREMENT.
* oct-mutex.h (oct-refcount.h): New included header.
(octave_base_mutex::count): Use octave_refcount class.
* gl-render.cc (oct-refcount.h): New included header.
* graphics.h.in (oct-refcount.h): Likewise.
(base_property::count, base_graphics_toolkit::count,
base_graphics_object::count, base_graphics_event::count): Use octave_refcount.
(property::~property, property::operator=): Delete rep only when refcountn is
excatly 0.
* oct-map.h (octave_fields::make_unique): Delete rep when refcount reaches 0.
* oct-stream.h (oct-refcount.h): New included header.
(octave_base_stream::count): Use octave_refcount class.
* ov.h (octave_value::make_unique): Delete rep when refcount reaches 0.
* symtab.h (oct-refcount.h): New included header.
(symbol_record_rep::count, fcn_info_rep::count): Use octave_refcount class.
* DLD-FUNCTIONS/urlwrite.cc (oct-refcount.h): New included header.
(curl_handle_rep::count): Use octave_refcount class.
author | Michael Goffioul <michael.goffioul@gmail.com> |
---|---|
date | Sat, 03 Dec 2011 15:19:42 +0000 |
parents | a33ec41d0340 |
children | de90542b7afc |
rev | line source |
---|---|
6043 | 1 // urlwrite and urlread, a curl front-end for octave |
2 /* | |
3 | |
11523 | 4 Copyright (C) 2006-2011 Alexander Barth |
9880 | 5 Copyright (C) 2009 David Bateman |
6043 | 6 |
7 This file is part of Octave. | |
8 | |
9 Octave is free software; you can redistribute it and/or modify it | |
10 under the terms of the GNU General Public License as published by the | |
7016 | 11 Free Software Foundation; either version 3 of the License, or (at your |
12 option) any later version. | |
6043 | 13 |
14 Octave is distributed in the hope that it will be useful, but WITHOUT | |
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
17 for more details. | |
18 | |
19 You should have received a copy of the GNU General Public License | |
7016 | 20 along with Octave; see the file COPYING. If not, see |
21 <http://www.gnu.org/licenses/>. | |
6043 | 22 |
23 */ | |
24 | |
25 // Author: Alexander Barth <abarth@marine.usf.edu> | |
26 // Adapted-By: jwe | |
27 | |
28 #ifdef HAVE_CONFIG_H | |
29 #include <config.h> | |
30 #endif | |
31 | |
32 #include <string> | |
33 #include <fstream> | |
34 #include <iomanip> | |
9880 | 35 #include <iostream> |
6043 | 36 |
9880 | 37 #include "dir-ops.h" |
8151
3725f819b5b3
urlwrite.cc (Furlwrite): delete files we create if download fails
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
38 #include "file-ops.h" |
3725f819b5b3
urlwrite.cc (Furlwrite): delete files we create if download fails
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
39 #include "file-stat.h" |
6043 | 40 #include "oct-env.h" |
9880 | 41 #include "glob-match.h" |
6043 | 42 |
43 #include "defun-dld.h" | |
44 #include "error.h" | |
45 #include "oct-obj.h" | |
46 #include "ov-cell.h" | |
47 #include "pager.h" | |
9880 | 48 #include "oct-map.h" |
13985
43cc49c7abd1
Use thread-safe atomic reference counting (GCC and MSVC).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13978
diff
changeset
|
49 #include "oct-refcount.h" |
8151
3725f819b5b3
urlwrite.cc (Furlwrite): delete files we create if download fails
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
50 #include "unwind-prot.h" |
6043 | 51 |
9905
84a7c11ff928
Correctly compile even when libcurl is not present according to configure
Rik <rdrider0-list@yahoo.com>
parents:
9885
diff
changeset
|
52 #ifdef HAVE_CURL |
6043 | 53 |
54 #include <curl/curl.h> | |
9885 | 55 #include <curl/curlver.h> |
6043 | 56 #include <curl/easy.h> |
57 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
58 static int |
6043 | 59 write_data (void *buffer, size_t size, size_t nmemb, void *streamp) |
60 { | |
61 std::ostream& stream = *(static_cast<std::ostream*> (streamp)); | |
62 stream.write (static_cast<const char*> (buffer), size*nmemb); | |
63 return (stream.fail () ? 0 : size * nmemb); | |
64 } | |
65 | |
9880 | 66 static int |
67 read_data (void *buffer, size_t size, size_t nmemb, void *streamp) | |
6043 | 68 { |
9880 | 69 std::istream& stream = *(static_cast<std::istream*> (streamp)); |
70 stream.read (static_cast<char*> (buffer), size*nmemb); | |
71 if (stream.eof ()) | |
72 return stream.gcount (); | |
73 else | |
74 return (stream.fail () ? 0 : size * nmemb); | |
6043 | 75 } |
76 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
77 static size_t |
9880 | 78 throw_away (void *, size_t size, size_t nmemb, void *) |
6992 | 79 { |
9880 | 80 return static_cast<size_t>(size * nmemb); |
6992 | 81 } |
82 | |
9880 | 83 class |
84 curl_handle | |
6043 | 85 { |
9880 | 86 private: |
87 class | |
88 curl_handle_rep | |
89 { | |
90 public: | |
91 curl_handle_rep (void) : count (1), valid (true), ascii (false) | |
92 { | |
93 curl = curl_easy_init (); | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
94 if (!curl) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
95 error ("can not create curl handle"); |
9880 | 96 } |
97 | |
98 ~curl_handle_rep (void) | |
99 { | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
100 if (curl) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
101 curl_easy_cleanup (curl); |
9880 | 102 } |
103 | |
104 bool is_valid (void) const | |
105 { | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
106 return valid; |
9880 | 107 } |
108 | |
109 bool perform (bool curlerror) const | |
110 { | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
111 bool retval = false; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
112 if (!error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
113 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
114 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
6043 | 115 |
12963
27e5f0e79f19
Return better error codes from curl, even if connection is successful
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12782
diff
changeset
|
116 errnum = curl_easy_perform (curl); |
27e5f0e79f19
Return better error codes from curl, even if connection is successful
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12782
diff
changeset
|
117 if (errnum != CURLE_OK) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
118 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
119 if (curlerror) |
12963
27e5f0e79f19
Return better error codes from curl, even if connection is successful
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12782
diff
changeset
|
120 error ("%s", curl_easy_strerror (errnum)); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
121 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
122 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
123 retval = true; |
9880 | 124 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
125 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
126 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
127 return retval; |
9880 | 128 } |
6043 | 129 |
9880 | 130 CURL* handle (void) const |
131 { | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
132 return curl; |
9880 | 133 } |
134 | |
135 bool is_ascii (void) const | |
136 { | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
137 return ascii; |
9880 | 138 } |
139 | |
140 bool is_binary (void) const | |
141 { | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
142 return !ascii; |
9880 | 143 } |
144 | |
13985
43cc49c7abd1
Use thread-safe atomic reference counting (GCC and MSVC).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13978
diff
changeset
|
145 octave_refcount<size_t> count; |
9880 | 146 std::string host; |
147 bool valid; | |
148 bool ascii; | |
12963
27e5f0e79f19
Return better error codes from curl, even if connection is successful
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12782
diff
changeset
|
149 mutable CURLcode errnum; |
9880 | 150 |
151 private: | |
152 CURL *curl; | |
6043 | 153 |
9880 | 154 // No copying! |
155 | |
156 curl_handle_rep (const curl_handle_rep& ov); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
157 |
9880 | 158 curl_handle_rep& operator = (const curl_handle_rep&); |
159 }; | |
160 | |
161 public: | |
6043 | 162 |
9880 | 163 // I'd love to rewrite this as a private method of the curl_handle |
164 // class, but you can't pass the va_list from the wrapper setopt to | |
165 // the curl_easy_setopt function. | |
166 #define setopt(option, parameter) \ | |
167 { \ | |
168 CURLcode res = curl_easy_setopt (rep->handle (), option, parameter); \ | |
169 if (res != CURLE_OK) \ | |
170 error ("%s", curl_easy_strerror (res)); \ | |
171 } | |
172 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
173 curl_handle (void) : rep (new curl_handle_rep ()) |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
174 { |
9880 | 175 rep->valid = false; |
176 } | |
177 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
178 curl_handle (const std::string& _host, const std::string& user, |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
179 const std::string& passwd) : |
9880 | 180 rep (new curl_handle_rep ()) |
181 { | |
182 rep->host = _host; | |
183 init (user, passwd, std::cin, octave_stdout); | |
184 | |
185 std::string url = "ftp://" + _host; | |
186 setopt (CURLOPT_URL, url.c_str()); | |
6043 | 187 |
9880 | 188 // Setup the link, with no transfer |
189 if (!error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
190 perform (); |
9880 | 191 } |
192 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
193 curl_handle (const std::string& url, const std::string& method, |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
194 const Cell& param, std::ostream& os, bool& retval) : |
9880 | 195 rep (new curl_handle_rep ()) |
196 { | |
197 retval = false; | |
198 | |
199 init ("", "", std::cin, os); | |
200 | |
201 setopt (CURLOPT_NOBODY, 0); | |
202 | |
203 // Don't need to store the parameters here as we can't change | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
204 // the URL after the handle is created |
9880 | 205 std::string query_string = form_query_string (param); |
6043 | 206 |
9880 | 207 if (method == "get") |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
208 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
209 query_string = url + "?" + query_string; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
210 setopt (CURLOPT_URL, query_string.c_str ()); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
211 } |
9880 | 212 else if (method == "post") |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
213 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
214 setopt (CURLOPT_URL, url.c_str ()); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
215 setopt (CURLOPT_POSTFIELDS, query_string.c_str ()); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
216 } |
9880 | 217 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
218 setopt (CURLOPT_URL, url.c_str()); |
9880 | 219 |
220 if (!error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
221 retval = perform (false); |
9880 | 222 } |
223 | |
224 curl_handle (const curl_handle& h) : rep (h.rep) | |
6043 | 225 { |
9880 | 226 rep->count++; |
227 } | |
228 | |
229 ~curl_handle (void) | |
230 { | |
231 if (--rep->count == 0) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
232 delete rep; |
9880 | 233 } |
234 | |
235 curl_handle& operator = (const curl_handle& h) | |
236 { | |
237 if (this != &h) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
238 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
239 if (--rep->count == 0) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
240 delete rep; |
9880 | 241 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
242 rep = h.rep; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
243 rep->count++; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
244 } |
9880 | 245 return *this; |
246 } | |
247 | |
248 bool is_valid (void) const | |
249 { | |
250 return rep->is_valid (); | |
6043 | 251 } |
9880 | 252 |
253 std::string lasterror (void) const | |
254 { | |
12963
27e5f0e79f19
Return better error codes from curl, even if connection is successful
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12782
diff
changeset
|
255 return std::string (curl_easy_strerror (rep->errnum)); |
9880 | 256 } |
257 | |
258 void set_ostream (std::ostream& os) const | |
259 { | |
260 setopt (CURLOPT_WRITEDATA, static_cast<void*> (&os)); | |
261 } | |
262 | |
263 void set_istream (std::istream& is) const | |
6043 | 264 { |
9880 | 265 setopt (CURLOPT_READDATA, static_cast<void*> (&is)); |
266 } | |
267 | |
268 void ascii (void) const | |
269 { | |
270 setopt (CURLOPT_TRANSFERTEXT, 1); | |
271 rep->ascii = true; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
272 } |
9880 | 273 |
274 void binary (void) const | |
275 { | |
276 setopt (CURLOPT_TRANSFERTEXT, 0); | |
277 rep->ascii = false; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
278 } |
9880 | 279 |
280 bool is_ascii (void) const | |
281 { | |
282 return rep->is_ascii (); | |
283 } | |
284 | |
285 bool is_binary (void) const | |
286 { | |
287 return rep->is_binary (); | |
6043 | 288 } |
9880 | 289 |
290 void cwd (const std::string& path) const | |
291 { | |
292 struct curl_slist *slist = 0; | |
293 std::string cmd = "cwd " + path; | |
294 slist = curl_slist_append (slist, cmd.c_str()); | |
295 setopt (CURLOPT_POSTQUOTE, slist); | |
296 if (! error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
297 perform (); |
9880 | 298 setopt (CURLOPT_POSTQUOTE, 0); |
299 curl_slist_free_all (slist); | |
300 } | |
6043 | 301 |
9880 | 302 void del (const std::string& file) const |
303 { | |
304 struct curl_slist *slist = 0; | |
305 std::string cmd = "dele " + file; | |
306 slist = curl_slist_append (slist, cmd.c_str()); | |
307 setopt (CURLOPT_POSTQUOTE, slist); | |
308 if (! error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
309 perform (); |
9880 | 310 setopt (CURLOPT_POSTQUOTE, 0); |
311 curl_slist_free_all (slist); | |
312 } | |
313 | |
314 void rmdir (const std::string& path) const | |
315 { | |
316 struct curl_slist *slist = 0; | |
317 std::string cmd = "rmd " + path; | |
318 slist = curl_slist_append (slist, cmd.c_str()); | |
319 setopt (CURLOPT_POSTQUOTE, slist); | |
320 if (! error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
321 perform (); |
9880 | 322 setopt (CURLOPT_POSTQUOTE, 0); |
323 curl_slist_free_all (slist); | |
324 } | |
6043 | 325 |
9880 | 326 bool mkdir (const std::string& path, bool curlerror = true) const |
327 { | |
328 bool retval = false; | |
329 struct curl_slist *slist = 0; | |
330 std::string cmd = "mkd " + path; | |
331 slist = curl_slist_append (slist, cmd.c_str()); | |
332 setopt (CURLOPT_POSTQUOTE, slist); | |
333 if (! error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
334 retval = perform (curlerror); |
9880 | 335 setopt (CURLOPT_POSTQUOTE, 0); |
336 curl_slist_free_all (slist); | |
337 return retval; | |
338 } | |
6043 | 339 |
9880 | 340 void rename (const std::string& oldname, const std::string& newname) const |
341 { | |
342 struct curl_slist *slist = 0; | |
343 std::string cmd = "rnfr " + oldname; | |
344 slist = curl_slist_append (slist, cmd.c_str()); | |
345 cmd = "rnto " + newname; | |
346 slist = curl_slist_append (slist, cmd.c_str()); | |
347 setopt (CURLOPT_POSTQUOTE, slist); | |
348 if (! error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
349 perform (); |
9880 | 350 setopt (CURLOPT_POSTQUOTE, 0); |
351 curl_slist_free_all (slist); | |
352 } | |
353 | |
354 void put (const std::string& file, std::istream& is) const | |
355 { | |
356 std::string url = "ftp://" + rep->host + "/" + file; | |
357 setopt (CURLOPT_URL, url.c_str()); | |
358 setopt (CURLOPT_UPLOAD, 1); | |
359 setopt (CURLOPT_NOBODY, 0); | |
360 set_istream (is); | |
361 if (! error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
362 perform (); |
9880 | 363 set_istream (std::cin); |
364 setopt (CURLOPT_NOBODY, 1); | |
365 setopt (CURLOPT_UPLOAD, 0); | |
366 url = "ftp://" + rep->host; | |
367 setopt (CURLOPT_URL, url.c_str()); | |
368 } | |
7013 | 369 |
9880 | 370 void get (const std::string& file, std::ostream& os) const |
371 { | |
372 std::string url = "ftp://" + rep->host + "/" + file; | |
373 setopt (CURLOPT_URL, url.c_str()); | |
374 setopt (CURLOPT_NOBODY, 0); | |
375 set_ostream (os); | |
376 if (! error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
377 perform (); |
9880 | 378 set_ostream (octave_stdout); |
379 setopt (CURLOPT_NOBODY, 1); | |
380 url = "ftp://" + rep->host; | |
381 setopt (CURLOPT_URL, url.c_str()); | |
382 } | |
383 | |
384 void dir (void) const | |
385 { | |
386 std::string url = "ftp://" + rep->host + "/"; | |
387 setopt (CURLOPT_URL, url.c_str()); | |
388 setopt (CURLOPT_NOBODY, 0); | |
389 if (! error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
390 perform (); |
9880 | 391 setopt (CURLOPT_NOBODY, 1); |
392 url = "ftp://" + rep->host; | |
393 setopt (CURLOPT_URL, url.c_str()); | |
394 } | |
6390 | 395 |
9880 | 396 string_vector list (void) const |
397 { | |
398 std::ostringstream buf; | |
399 std::string url = "ftp://" + rep->host + "/"; | |
400 setopt (CURLOPT_WRITEDATA, static_cast<void*> (&buf)); | |
401 setopt (CURLOPT_URL, url.c_str()); | |
402 setopt (CURLOPT_DIRLISTONLY, 1); | |
403 setopt (CURLOPT_NOBODY, 0); | |
404 if (! error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
405 perform (); |
9880 | 406 setopt (CURLOPT_NOBODY, 1); |
407 url = "ftp://" + rep->host; | |
408 setopt (CURLOPT_WRITEDATA, static_cast<void*> (&octave_stdout)); | |
409 setopt (CURLOPT_DIRLISTONLY, 0); | |
410 setopt (CURLOPT_URL, url.c_str()); | |
411 | |
412 // Count number of directory entries | |
413 std::string str = buf.str (); | |
414 octave_idx_type n = 0; | |
415 size_t pos = 0; | |
416 while (true) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
417 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
418 pos = str.find_first_of('\n', pos); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
419 if (pos == std::string::npos) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
420 break; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
421 pos++; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
422 n++; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
423 } |
9880 | 424 string_vector retval (n); |
425 pos = 0; | |
426 for (octave_idx_type i = 0; i < n; i++) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
427 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
428 size_t newpos = str.find_first_of('\n', pos); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
429 if (newpos == std::string::npos) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
430 break; |
9880 | 431 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
432 retval(i) = str.substr(pos, newpos - pos); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
433 pos = newpos + 1; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
434 } |
9880 | 435 return retval; |
436 } | |
437 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
438 void get_fileinfo (const std::string& filename, double& filesize, |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
439 time_t& filetime, bool& fileisdir) const |
9880 | 440 { |
441 std::string path = pwd(); | |
6043 | 442 |
9880 | 443 std::string url = "ftp://" + rep->host + "/" + path + "/" + filename; |
444 setopt (CURLOPT_URL, url.c_str()); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
445 setopt (CURLOPT_FILETIME, 1); |
9880 | 446 setopt (CURLOPT_HEADERFUNCTION, throw_away); |
447 setopt (CURLOPT_WRITEFUNCTION, throw_away); | |
6043 | 448 |
9880 | 449 // FIXME |
450 // The MDTM command fails for a directory on the servers I tested | |
451 // so this is a means of testing for directories. It also means | |
452 // I can't get the date of directories! | |
453 if (! error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
454 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
455 if (! perform (false)) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
456 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
457 fileisdir = true; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
458 filetime = -1; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
459 filesize = 0; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
460 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
461 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
462 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
463 fileisdir = false; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
464 time_t ft; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
465 curl_easy_getinfo(rep->handle (), CURLINFO_FILETIME, &ft); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
466 filetime = ft; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
467 double fs; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
468 curl_easy_getinfo(rep->handle (), |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
469 CURLINFO_CONTENT_LENGTH_DOWNLOAD, &fs); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
470 filesize = fs; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
471 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
472 } |
6992 | 473 |
9880 | 474 setopt (CURLOPT_WRITEFUNCTION, write_data); |
475 setopt (CURLOPT_HEADERFUNCTION, 0); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
476 setopt (CURLOPT_FILETIME, 0); |
9880 | 477 url = "ftp://" + rep->host; |
478 setopt (CURLOPT_URL, url.c_str()); | |
479 | |
480 // The MDTM command seems to reset the path to the root with the | |
481 // servers I tested with, so cd again into the correct path. Make | |
482 // the path absolute so that this will work even with servers that | |
483 // don't end up in the root after an MDTM command. | |
484 cwd ("/" + path); | |
485 } | |
486 | |
487 std::string pwd (void) const | |
488 { | |
489 struct curl_slist *slist = 0; | |
490 std::string retval; | |
491 std::ostringstream buf; | |
6992 | 492 |
9880 | 493 slist = curl_slist_append (slist, "pwd"); |
494 setopt (CURLOPT_POSTQUOTE, slist); | |
495 setopt (CURLOPT_HEADERFUNCTION, write_data); | |
496 setopt (CURLOPT_WRITEHEADER, static_cast<void *>(&buf)); | |
497 | |
498 if (! error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
499 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
500 perform (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
501 retval = buf.str(); |
9880 | 502 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
503 // Can I assume that the path is alway in "" on the last line |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
504 size_t pos2 = retval.rfind ('"'); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
505 size_t pos1 = retval.rfind ('"', pos2 - 1); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
506 retval = retval.substr(pos1 + 1, pos2 - pos1 - 1); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
507 } |
9880 | 508 setopt (CURLOPT_HEADERFUNCTION, 0); |
509 setopt (CURLOPT_WRITEHEADER, 0); | |
510 setopt (CURLOPT_POSTQUOTE, 0); | |
511 curl_slist_free_all (slist); | |
512 | |
513 return retval; | |
514 } | |
6992 | 515 |
9880 | 516 bool perform (bool curlerror = true) const |
517 { | |
518 return rep->perform (curlerror); | |
519 } | |
520 | |
521 private: | |
522 curl_handle_rep *rep; | |
523 | |
524 std::string form_query_string (const Cell& param) | |
525 { | |
526 std::ostringstream query; | |
527 | |
528 for (int i = 0; i < param.numel (); i += 2) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
529 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
530 std::string name = param(i).string_value (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
531 std::string text = param(i+1).string_value (); |
9880 | 532 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
533 // Encode strings. |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
534 char *enc_name = curl_easy_escape (rep->handle(), name.c_str (), |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
535 name.length ()); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
536 char *enc_text = curl_easy_escape (rep->handle(), text.c_str (), |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
537 text.length ()); |
9880 | 538 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
539 query << enc_name << "=" << enc_text; |
9880 | 540 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
541 curl_free (enc_name); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
542 curl_free (enc_text); |
9880 | 543 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
544 if (i < param.numel()-1) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
545 query << "&"; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
546 } |
9880 | 547 |
548 query.flush (); | |
6043 | 549 |
9880 | 550 return query.str (); |
551 } | |
552 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
553 void init (const std::string& user, const std::string& passwd, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
554 std::istream& is, std::ostream& os) |
9880 | 555 { |
556 // No data transfer by default | |
557 setopt (CURLOPT_NOBODY, 1); | |
558 | |
559 // Set the username and password | |
9918
57b41617c9fd
avoid LIBCURL version check
John W. Eaton <jwe@octave.org>
parents:
9905
diff
changeset
|
560 std::string userpwd = user; |
57b41617c9fd
avoid LIBCURL version check
John W. Eaton <jwe@octave.org>
parents:
9905
diff
changeset
|
561 if (! passwd.empty ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
562 userpwd += ":" + passwd; |
10377
fb62fbbe28c0
urlwrite: don't set CURLOPT_USERPWD if userpwd is empty
David Bateman <dbateman@free.fr>
parents:
10250
diff
changeset
|
563 if (! userpwd.empty ()) |
fb62fbbe28c0
urlwrite: don't set CURLOPT_USERPWD if userpwd is empty
David Bateman <dbateman@free.fr>
parents:
10250
diff
changeset
|
564 setopt (CURLOPT_USERPWD, userpwd.c_str ()); |
9880 | 565 |
566 // Define our callback to get called when there's data to be written. | |
567 setopt (CURLOPT_WRITEFUNCTION, write_data); | |
6992 | 568 |
9880 | 569 // Set a pointer to our struct to pass to the callback. |
570 setopt (CURLOPT_WRITEDATA, static_cast<void*> (&os)); | |
571 | |
572 // Define our callback to get called when there's data to be read | |
573 setopt (CURLOPT_READFUNCTION, read_data); | |
574 | |
575 // Set a pointer to our struct to pass to the callback. | |
576 setopt (CURLOPT_READDATA, static_cast<void*> (&is)); | |
577 | |
578 // Follow redirects. | |
579 setopt (CURLOPT_FOLLOWLOCATION, true); | |
580 | |
581 // Don't use EPSV since connecting to sites that don't support it | |
582 // will hang for some time (3 minutes?) before moving on to try PASV | |
583 // instead. | |
584 setopt (CURLOPT_FTP_USE_EPSV, false); | |
585 | |
586 setopt (CURLOPT_NOPROGRESS, true); | |
587 setopt (CURLOPT_FAILONERROR, true); | |
6992 | 588 |
9880 | 589 setopt (CURLOPT_POSTQUOTE, 0); |
590 setopt (CURLOPT_QUOTE, 0); | |
591 } | |
592 | |
593 #undef setopt | |
594 }; | |
595 | |
596 class | |
597 curl_handles | |
598 { | |
599 public: | |
600 | |
601 typedef std::map<std::string, curl_handle>::iterator iterator; | |
602 typedef std::map<std::string, curl_handle>::const_iterator const_iterator; | |
6043 | 603 |
9880 | 604 curl_handles (void) : map () |
605 { | |
606 curl_global_init(CURL_GLOBAL_DEFAULT); | |
607 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
608 |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
609 ~curl_handles (void) |
9880 | 610 { |
611 // Remove the elements of the map explicitly as they should | |
612 // be deleted before the call to curl_global_cleanup | |
11548
50a7935f2512
Don't invalidate iterators when calling std::map::erase, found by cppcheck
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11523
diff
changeset
|
613 map.erase (begin(), end()); |
6992 | 614 |
9880 | 615 curl_global_cleanup (); |
616 } | |
617 | |
618 iterator begin (void) { return iterator (map.begin ()); } | |
619 const_iterator begin (void) const { return const_iterator (map.begin ()); } | |
620 | |
621 iterator end (void) { return iterator (map.end ()); } | |
622 const_iterator end (void) const { return const_iterator (map.end ()); } | |
6992 | 623 |
9880 | 624 iterator seek (const std::string& k) { return map.find (k); } |
625 const_iterator seek (const std::string& k) const { return map.find (k); } | |
626 | |
627 std::string key (const_iterator p) const { return p->first; } | |
628 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
629 curl_handle& contents (const std::string& k) |
9880 | 630 { |
631 return map[k]; | |
632 } | |
633 | |
634 curl_handle contents (const std::string& k) const | |
635 { | |
636 const_iterator p = seek (k); | |
637 return p != end () ? p->second : curl_handle (); | |
638 } | |
639 | |
640 curl_handle& contents (iterator p) | |
641 { return p->second; } | |
6992 | 642 |
9880 | 643 curl_handle contents (const_iterator p) const |
644 { return p->second; } | |
645 | |
646 void del (const std::string& k) | |
647 { | |
648 iterator p = map.find (k); | |
649 | |
650 if (p != map.end ()) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
651 map.erase (p); |
9880 | 652 } |
6043 | 653 |
9880 | 654 private: |
655 std::map<std::string, curl_handle> map; | |
656 }; | |
657 | |
658 static curl_handles handles; | |
659 | |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10154
diff
changeset
|
660 static void |
9880 | 661 cleanup_urlwrite (std::string filename) |
662 { | |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10154
diff
changeset
|
663 octave_unlink (filename); |
6043 | 664 } |
665 | |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10154
diff
changeset
|
666 static void |
9880 | 667 reset_path (const curl_handle curl) |
668 { | |
669 curl.cwd (".."); | |
670 } | |
8151
3725f819b5b3
urlwrite.cc (Furlwrite): delete files we create if download fails
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
671 |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10154
diff
changeset
|
672 static void |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10154
diff
changeset
|
673 delete_file (std::string file) |
8151
3725f819b5b3
urlwrite.cc (Furlwrite): delete files we create if download fails
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
674 { |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10154
diff
changeset
|
675 octave_unlink (file); |
8151
3725f819b5b3
urlwrite.cc (Furlwrite): delete files we create if download fails
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
676 } |
9880 | 677 #endif |
8151
3725f819b5b3
urlwrite.cc (Furlwrite): delete files we create if download fails
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
678 |
6043 | 679 DEFUN_DLD (urlwrite, args, nargout, |
680 "-*- texinfo -*-\n\ | |
10840 | 681 @deftypefn {Loadable Function} {} urlwrite (@var{url}, @var{localfile})\n\ |
6043 | 682 @deftypefnx {Loadable Function} {@var{f} =} urlwrite (@var{url}, @var{localfile})\n\ |
683 @deftypefnx {Loadable Function} {[@var{f}, @var{success}] =} urlwrite (@var{url}, @var{localfile})\n\ | |
684 @deftypefnx {Loadable Function} {[@var{f}, @var{success}, @var{message}] =} urlwrite (@var{url}, @var{localfile})\n\ | |
9880 | 685 Download a remote file specified by its @var{url} and save it as\n\ |
10840 | 686 @var{localfile}. For example:\n\ |
6043 | 687 \n\ |
688 @example\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
689 @group\n\ |
12642
f96b9b9f141b
doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
690 urlwrite (\"ftp://ftp.octave.org/pub/octave/README\",\n\ |
7031 | 691 \"README.txt\");\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
692 @end group\n\ |
6043 | 693 @end example\n\ |
694 \n\ | |
695 The full path of the downloaded file is returned in @var{f}. The\n\ | |
696 variable @var{success} is 1 if the download was successful,\n\ | |
697 otherwise it is 0 in which case @var{message} contains an error\n\ | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
698 message. If no output argument is specified and an error occurs,\n\ |
6588 | 699 then the error is signaled through Octave's error handling mechanism.\n\ |
6043 | 700 \n\ |
701 This function uses libcurl. Curl supports, among others, the HTTP,\n\ | |
702 FTP and FILE protocols. Username and password may be specified in\n\ | |
703 the URL, for example:\n\ | |
704 \n\ | |
705 @example\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
706 @group\n\ |
6588 | 707 urlwrite (\"http://username:password@@example.com/file.txt\",\n\ |
708 \"file.txt\");\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
709 @end group\n\ |
6043 | 710 @end example\n\ |
711 \n\ | |
712 GET and POST requests can be specified by @var{method} and @var{param}.\n\ | |
6589 | 713 The parameter @var{method} is either @samp{get} or @samp{post}\n\ |
6588 | 714 and @var{param} is a cell array of parameter and value pairs.\n\ |
715 For example:\n\ | |
6043 | 716 \n\ |
717 @example\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
718 @group\n\ |
6588 | 719 urlwrite (\"http://www.google.com/search\", \"search.html\",\n\ |
720 \"get\", @{\"query\", \"octave\"@});\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
721 @end group\n\ |
6043 | 722 @end example\n\ |
723 @seealso{urlread}\n\ | |
724 @end deftypefn") | |
725 { | |
726 octave_value_list retval; | |
727 | |
9905
84a7c11ff928
Correctly compile even when libcurl is not present according to configure
Rik <rdrider0-list@yahoo.com>
parents:
9885
diff
changeset
|
728 #ifdef HAVE_CURL |
6043 | 729 |
730 int nargin = args.length (); | |
731 | |
732 // verify arguments | |
733 if (nargin != 2 && nargin != 4) | |
734 { | |
735 print_usage (); | |
736 return retval; | |
737 } | |
738 | |
739 std::string url = args(0).string_value(); | |
740 | |
741 if (error_state) | |
742 { | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
743 error ("urlwrite: URL must be a character string"); |
6043 | 744 return retval; |
745 } | |
746 | |
747 // name to store the file if download is succesful | |
748 std::string filename = args(1).string_value(); | |
749 | |
750 if (error_state) | |
751 { | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
752 error ("urlwrite: LOCALFILE must be a character string"); |
6043 | 753 return retval; |
754 } | |
755 | |
756 std::string method; | |
757 Cell param; // empty cell array | |
758 | |
759 if (nargin == 4) | |
760 { | |
761 method = args(2).string_value(); | |
762 | |
763 if (error_state) | |
764 { | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
765 error ("urlwrite: METHOD must be \"get\" or \"post\""); |
6043 | 766 return retval; |
767 } | |
768 | |
769 if (method != "get" && method != "post") | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
770 { |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
771 error ("urlwrite: METHOD must be \"get\" or \"post\""); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
772 return retval; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
773 } |
6043 | 774 |
775 param = args(3).cell_value(); | |
776 | |
777 if (error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
778 { |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
779 error ("urlwrite: parameters (PARAM) for get and post requests must be given as a cell"); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
780 return retval; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
781 } |
6043 | 782 |
783 | |
784 if (param.numel () % 2 == 1 ) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
785 { |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
786 error ("urlwrite: number of elements in PARAM must be even"); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
787 return retval; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
788 } |
6043 | 789 } |
790 | |
8151
3725f819b5b3
urlwrite.cc (Furlwrite): delete files we create if download fails
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
791 // The file should only be deleted if it doesn't initially exist, we |
3725f819b5b3
urlwrite.cc (Furlwrite): delete files we create if download fails
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
792 // create it, and the download fails. We use unwind_protect to do |
3725f819b5b3
urlwrite.cc (Furlwrite): delete files we create if download fails
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
793 // it so that the deletion happens no matter how we exit the function. |
3725f819b5b3
urlwrite.cc (Furlwrite): delete files we create if download fails
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
794 |
3725f819b5b3
urlwrite.cc (Furlwrite): delete files we create if download fails
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
795 file_stat fs (filename); |
3725f819b5b3
urlwrite.cc (Furlwrite): delete files we create if download fails
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
796 |
6986 | 797 std::ofstream ofile (filename.c_str(), std::ios::out | std::ios::binary); |
6043 | 798 |
6986 | 799 if (! ofile.is_open ()) |
6043 | 800 { |
801 error ("urlwrite: unable to open file"); | |
802 return retval; | |
803 } | |
804 | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9918
diff
changeset
|
805 unwind_protect_safe frame; |
8151
3725f819b5b3
urlwrite.cc (Furlwrite): delete files we create if download fails
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
806 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9918
diff
changeset
|
807 frame.add_fcn (cleanup_urlwrite, filename); |
9880 | 808 |
13978
a33ec41d0340
Fix error reporting in urlwrite (bug #34971)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12963
diff
changeset
|
809 bool ok; |
a33ec41d0340
Fix error reporting in urlwrite (bug #34971)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12963
diff
changeset
|
810 curl_handle curl = curl_handle (url, method, param, ofile, ok); |
6043 | 811 |
6986 | 812 ofile.close (); |
6043 | 813 |
9880 | 814 if (!error_state) |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9918
diff
changeset
|
815 frame.discard (); |
9880 | 816 else |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9918
diff
changeset
|
817 frame.run (); |
8151
3725f819b5b3
urlwrite.cc (Furlwrite): delete files we create if download fails
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
818 |
6043 | 819 if (nargout > 0) |
820 { | |
13978
a33ec41d0340
Fix error reporting in urlwrite (bug #34971)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12963
diff
changeset
|
821 if (ok) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
822 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
823 retval(2) = std::string (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
824 retval(1) = true; |
10250 | 825 retval(0) = octave_env::make_absolute (filename); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
826 } |
8151
3725f819b5b3
urlwrite.cc (Furlwrite): delete files we create if download fails
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
827 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
828 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
829 retval(2) = curl.lasterror (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
830 retval(1) = false; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
831 retval(0) = std::string (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
832 } |
6043 | 833 } |
834 | |
13978
a33ec41d0340
Fix error reporting in urlwrite (bug #34971)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12963
diff
changeset
|
835 if (nargout < 2 && ! ok) |
9880 | 836 error ("urlwrite: curl: %s", curl.lasterror ().c_str ()); |
6043 | 837 |
838 #else | |
6981 | 839 error ("urlwrite: not available in this version of Octave"); |
6043 | 840 #endif |
841 | |
842 return retval; | |
843 } | |
844 | |
845 DEFUN_DLD (urlread, args, nargout, | |
846 "-*- texinfo -*-\n\ | |
10840 | 847 @deftypefn {Loadable Function} {@var{s} =} urlread (@var{url})\n\ |
6043 | 848 @deftypefnx {Loadable Function} {[@var{s}, @var{success}] =} urlread (@var{url})\n\ |
6549 | 849 @deftypefnx {Loadable Function} {[@var{s}, @var{success}, @var{message}] =} urlread (@var{url})\n\ |
6547 | 850 @deftypefnx {Loadable Function} {[@dots{}] =} urlread (@var{url}, @var{method}, @var{param})\n\ |
9880 | 851 Download a remote file specified by its @var{url} and return its content\n\ |
10840 | 852 in string @var{s}. For example:\n\ |
6043 | 853 \n\ |
854 @example\n\ | |
6588 | 855 s = urlread (\"ftp://ftp.octave.org/pub/octave/README\");\n\ |
6043 | 856 @end example\n\ |
857 \n\ | |
858 The variable @var{success} is 1 if the download was successful,\n\ | |
859 otherwise it is 0 in which case @var{message} contains an error\n\ | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
860 message. If no output argument is specified and an error occurs,\n\ |
6588 | 861 then the error is signaled through Octave's error handling mechanism.\n\ |
6043 | 862 \n\ |
863 This function uses libcurl. Curl supports, among others, the HTTP,\n\ | |
864 FTP and FILE protocols. Username and password may be specified in the\n\ | |
10840 | 865 URL@. For example:\n\ |
6043 | 866 \n\ |
867 @example\n\ | |
7031 | 868 s = urlread (\"http://user:password@@example.com/file.txt\");\n\ |
6043 | 869 @end example\n\ |
870 \n\ | |
871 GET and POST requests can be specified by @var{method} and @var{param}.\n\ | |
6588 | 872 The parameter @var{method} is either @samp{get} or @samp{post}\n\ |
873 and @var{param} is a cell array of parameter and value pairs.\n\ | |
10840 | 874 For example:\n\ |
6043 | 875 \n\ |
876 @example\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
877 @group\n\ |
6588 | 878 s = urlread (\"http://www.google.com/search\", \"get\",\n\ |
879 @{\"query\", \"octave\"@});\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
880 @end group\n\ |
6043 | 881 @end example\n\ |
882 @seealso{urlwrite}\n\ | |
883 @end deftypefn") | |
884 { | |
6588 | 885 // Octave's return value |
6043 | 886 octave_value_list retval; |
887 | |
9905
84a7c11ff928
Correctly compile even when libcurl is not present according to configure
Rik <rdrider0-list@yahoo.com>
parents:
9885
diff
changeset
|
888 #ifdef HAVE_CURL |
6043 | 889 |
890 int nargin = args.length (); | |
891 | |
892 // verify arguments | |
893 if (nargin != 1 && nargin != 3) | |
894 { | |
895 print_usage (); | |
896 return retval; | |
897 } | |
898 | |
899 std::string url = args(0).string_value(); | |
900 | |
901 if (error_state) | |
902 { | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
903 error ("urlread: URL must be a character string"); |
6043 | 904 return retval; |
905 } | |
906 | |
907 std::string method; | |
908 Cell param; // empty cell array | |
909 | |
910 if (nargin == 3) | |
911 { | |
912 method = args(1).string_value(); | |
913 | |
914 if (error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
915 { |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
916 error ("urlread: METHOD must be \"get\" or \"post\""); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
917 return retval; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
918 } |
6043 | 919 |
920 if (method != "get" && method != "post") | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
921 { |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
922 error ("urlread: METHOD must be \"get\" or \"post\""); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
923 return retval; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
924 } |
6043 | 925 |
926 param = args(2).cell_value(); | |
927 | |
928 if (error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
929 { |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
930 error ("urlread: parameters (PARAM) for get and post requests must be given as a cell"); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
931 return retval; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
932 } |
6043 | 933 |
934 if (param.numel () % 2 == 1 ) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
935 { |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
936 error ("urlread: number of elements in PARAM must be even"); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
937 return retval; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
938 } |
6043 | 939 } |
940 | |
6986 | 941 std::ostringstream buf; |
6043 | 942 |
13978
a33ec41d0340
Fix error reporting in urlwrite (bug #34971)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12963
diff
changeset
|
943 bool ok; |
a33ec41d0340
Fix error reporting in urlwrite (bug #34971)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12963
diff
changeset
|
944 curl_handle curl = curl_handle (url, method, param, buf, ok); |
6043 | 945 |
946 if (nargout > 0) | |
947 { | |
6986 | 948 retval(0) = buf.str (); |
13978
a33ec41d0340
Fix error reporting in urlwrite (bug #34971)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12963
diff
changeset
|
949 retval(1) = ok; |
6986 | 950 // Return empty string if no error occured. |
13978
a33ec41d0340
Fix error reporting in urlwrite (bug #34971)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12963
diff
changeset
|
951 retval(2) = ok ? "" : curl.lasterror (); |
6043 | 952 } |
953 | |
13978
a33ec41d0340
Fix error reporting in urlwrite (bug #34971)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12963
diff
changeset
|
954 if (nargout < 2 && ! ok) |
9880 | 955 error ("urlread: curl: %s", curl.lasterror().c_str()); |
6043 | 956 |
957 #else | |
6981 | 958 error ("urlread: not available in this version of Octave"); |
6043 | 959 #endif |
960 | |
961 return retval; | |
962 } | |
9880 | 963 |
964 DEFUN_DLD (__ftp__, args, , | |
965 "-*- texinfo -*-\n\ | |
10840 | 966 @deftypefn {Loadable Function} {} __ftp__ (@var{handle}, @var{host})\n\ |
9880 | 967 @deftypefnx {Loadable Function} {} __ftp__ (@var{handle}, @var{host}, @var{username}, @var{password})\n\ |
968 Undocumented internal function\n\ | |
969 @end deftypefn") | |
970 { | |
971 #ifdef HAVE_CURL | |
972 int nargin = args.length (); | |
973 std::string handle; | |
974 std::string host; | |
975 std::string user = "anonymous"; | |
976 std::string passwd = ""; | |
977 | |
978 if (nargin < 2 || nargin > 4) | |
979 error ("incorrect number of arguments"); | |
980 else | |
981 { | |
982 handle = args(0).string_value (); | |
983 host = args(1).string_value (); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
984 |
9880 | 985 if (nargin > 1) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
986 user = args(2).string_value (); |
9880 | 987 |
988 if (nargin > 2) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
989 passwd = args(3).string_value (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
990 |
9880 | 991 if (!error_state) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
992 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
993 handles.contents (handle) = curl_handle (host, user, passwd); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
994 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
995 if (error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
996 handles.del (handle); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
997 } |
9880 | 998 } |
999 #else | |
1000 error ("__ftp__: not available in this version of Octave"); | |
1001 #endif | |
1002 | |
1003 return octave_value (); | |
1004 } | |
1005 | |
1006 DEFUN_DLD (__ftp_pwd__, args, , | |
1007 "-*- texinfo -*-\n\ | |
1008 @deftypefn {Loadable Function} {} __ftp_pwd__ (@var{handle})\n\ | |
1009 Undocumented internal function\n\ | |
1010 @end deftypefn") | |
1011 { | |
1012 octave_value retval; | |
1013 #ifdef HAVE_CURL | |
1014 int nargin = args.length (); | |
1015 | |
1016 if (nargin != 1) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
1017 error ("__ftp_pwd__: incorrect number of arguments"); |
9880 | 1018 else |
1019 { | |
1020 std::string handle = args(0).string_value (); | |
1021 | |
1022 if (!error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1023 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1024 const curl_handle curl = handles.contents (handle); |
9880 | 1025 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1026 if (curl.is_valid ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1027 retval = curl.pwd (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1028 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1029 error ("__ftp_pwd__: invalid ftp handle"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1030 } |
9880 | 1031 } |
1032 #else | |
1033 error ("__ftp_pwd__: not available in this version of Octave"); | |
1034 #endif | |
1035 | |
1036 return retval; | |
1037 } | |
1038 | |
1039 DEFUN_DLD (__ftp_cwd__, args, , | |
1040 "-*- texinfo -*-\n\ | |
1041 @deftypefn {Loadable Function} {} __ftp_cwd__ (@var{handle}, @var{path})\n\ | |
1042 Undocumented internal function\n\ | |
1043 @end deftypefn") | |
1044 { | |
1045 #ifdef HAVE_CURL | |
1046 int nargin = args.length (); | |
1047 | |
1048 if (nargin != 1 && nargin != 2) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
1049 error ("__ftp_cwd__: incorrect number of arguments"); |
9880 | 1050 else |
1051 { | |
1052 std::string handle = args(0).string_value (); | |
1053 std::string path = ""; | |
1054 | |
1055 if (nargin > 1) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1056 path = args(1).string_value (); |
9880 | 1057 |
1058 if (!error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1059 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1060 const curl_handle curl = handles.contents (handle); |
9880 | 1061 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1062 if (curl.is_valid ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1063 curl.cwd (path); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1064 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1065 error ("__ftp_cwd__: invalid ftp handle"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1066 } |
9880 | 1067 } |
1068 #else | |
1069 error ("__ftp_cwd__: not available in this version of Octave"); | |
1070 #endif | |
1071 | |
1072 return octave_value (); | |
1073 } | |
1074 | |
1075 DEFUN_DLD (__ftp_dir__, args, nargout, | |
1076 "-*- texinfo -*-\n\ | |
1077 @deftypefn {Loadable Function} {} __ftp_dir__ (@var{handle})\n\ | |
1078 Undocumented internal function\n\ | |
1079 @end deftypefn") | |
1080 { | |
1081 octave_value retval; | |
1082 #ifdef HAVE_CURL | |
1083 int nargin = args.length (); | |
1084 | |
1085 if (nargin != 1) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
1086 error ("__ftp_dir__: incorrect number of arguments"); |
9880 | 1087 else |
1088 { | |
1089 std::string handle = args(0).string_value (); | |
1090 | |
1091 if (!error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1092 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1093 const curl_handle curl = handles.contents (handle); |
9880 | 1094 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1095 if (curl.is_valid ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1096 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1097 if (nargout == 0) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1098 curl.dir (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1099 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1100 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1101 string_vector sv = curl.list (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1102 octave_idx_type n = sv.length (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1103 if (n == 0) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1104 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1105 string_vector flds (5); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1106 flds(0) = "name"; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1107 flds(1) = "date"; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1108 flds(2) = "bytes"; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1109 flds(3) = "isdir"; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1110 flds(4) = "datenum"; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1111 retval = octave_map (flds); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1112 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1113 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1114 { |
11050
b1ee705aef45
urlwrite.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
1115 octave_map st; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1116 Cell filectime (dim_vector (n, 1)); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1117 Cell filesize (dim_vector (n, 1)); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1118 Cell fileisdir (dim_vector (n, 1)); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1119 Cell filedatenum (dim_vector (n, 1)); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1120 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1121 st.assign ("name", Cell (sv)); |
9880 | 1122 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1123 for (octave_idx_type i = 0; i < n; i++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1124 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1125 time_t ftime; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1126 bool fisdir; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1127 double fsize; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1128 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1129 curl.get_fileinfo (sv(i), fsize, ftime, fisdir); |
9880 | 1130 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1131 fileisdir (i) = fisdir; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1132 filectime (i) = ctime (&ftime); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1133 filesize (i) = fsize; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1134 filedatenum (i) = double (ftime); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1135 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1136 st.assign ("date", filectime); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1137 st.assign ("bytes", filesize); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1138 st.assign ("isdir", fileisdir); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1139 st.assign ("datenum", filedatenum); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1140 retval = st; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1141 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1142 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1143 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1144 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1145 error ("__ftp_dir__: invalid ftp handle"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1146 } |
9880 | 1147 } |
1148 #else | |
1149 error ("__ftp_dir__: not available in this version of Octave"); | |
1150 #endif | |
1151 | |
1152 return retval; | |
1153 } | |
1154 | |
1155 DEFUN_DLD (__ftp_ascii__, args, , | |
1156 "-*- texinfo -*-\n\ | |
1157 @deftypefn {Loadable Function} {} __ftp_ascii__ (@var{handle})\n\ | |
1158 Undocumented internal function\n\ | |
1159 @end deftypefn") | |
1160 { | |
1161 #ifdef HAVE_CURL | |
1162 int nargin = args.length (); | |
1163 | |
1164 if (nargin != 1) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
1165 error ("__ftp_ascii__: incorrect number of arguments"); |
9880 | 1166 else |
1167 { | |
1168 std::string handle = args(0).string_value (); | |
1169 | |
1170 if (!error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1171 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1172 const curl_handle curl = handles.contents (handle); |
9880 | 1173 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1174 if (curl.is_valid ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1175 curl.ascii (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1176 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1177 error ("__ftp_ascii__: invalid ftp handle"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1178 } |
9880 | 1179 } |
1180 #else | |
1181 error ("__ftp_ascii__: not available in this version of Octave"); | |
1182 #endif | |
1183 | |
1184 return octave_value (); | |
1185 } | |
1186 | |
1187 DEFUN_DLD (__ftp_binary__, args, , | |
1188 "-*- texinfo -*-\n\ | |
1189 @deftypefn {Loadable Function} {} __ftp_binary__ (@var{handle})\n\ | |
1190 Undocumented internal function\n\ | |
1191 @end deftypefn") | |
1192 { | |
1193 #ifdef HAVE_CURL | |
1194 int nargin = args.length (); | |
1195 | |
1196 if (nargin != 1) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
1197 error ("__ftp_binary__: incorrect number of arguments"); |
9880 | 1198 else |
1199 { | |
1200 std::string handle = args(0).string_value (); | |
1201 | |
1202 if (!error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1203 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1204 const curl_handle curl = handles.contents (handle); |
9880 | 1205 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1206 if (curl.is_valid ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1207 curl.binary (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1208 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1209 error ("__ftp_binary__: invalid ftp handle"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1210 } |
9880 | 1211 } |
1212 #else | |
1213 error ("__ftp_binary__: not available in this version of Octave"); | |
1214 #endif | |
1215 | |
1216 return octave_value (); | |
1217 } | |
1218 | |
1219 DEFUN_DLD (__ftp_close__, args, , | |
1220 "-*- texinfo -*-\n\ | |
1221 @deftypefn {Loadable Function} {} __ftp_close__ (@var{handle})\n\ | |
1222 Undocumented internal function\n\ | |
1223 @end deftypefn") | |
1224 { | |
1225 #ifdef HAVE_CURL | |
1226 int nargin = args.length (); | |
1227 | |
1228 if (nargin != 1) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
1229 error ("__ftp_close__: incorrect number of arguments"); |
9880 | 1230 else |
1231 { | |
1232 std::string handle = args(0).string_value (); | |
1233 | |
1234 if (!error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1235 handles.del (handle); |
9880 | 1236 } |
1237 #else | |
1238 error ("__ftp_close__: not available in this version of Octave"); | |
1239 #endif | |
1240 | |
1241 return octave_value (); | |
1242 } | |
1243 | |
1244 DEFUN_DLD (__ftp_mode__, args, , | |
1245 "-*- texinfo -*-\n\ | |
1246 @deftypefn {Loadable Function} {} __ftp_mode__ (@var{handle})\n\ | |
1247 Undocumented internal function\n\ | |
1248 @end deftypefn") | |
1249 { | |
1250 octave_value retval; | |
1251 #ifdef HAVE_CURL | |
1252 int nargin = args.length (); | |
1253 | |
1254 if (nargin != 1) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
1255 error ("__ftp_mode__: incorrect number of arguments"); |
9880 | 1256 else |
1257 { | |
1258 std::string handle = args(0).string_value (); | |
1259 | |
1260 | |
1261 if (!error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1262 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1263 const curl_handle curl = handles.contents (handle); |
9880 | 1264 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1265 if (curl.is_valid ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1266 retval = (curl.is_ascii() ? "ascii" : "binary"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1267 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1268 error ("__ftp_binary__: invalid ftp handle"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1269 } |
9880 | 1270 } |
1271 #else | |
1272 error ("__ftp_mode__: not available in this version of Octave"); | |
1273 #endif | |
1274 | |
1275 return retval; | |
1276 } | |
1277 | |
1278 DEFUN_DLD (__ftp_delete__, args, , | |
1279 "-*- texinfo -*-\n\ | |
1280 @deftypefn {Loadable Function} {} __ftp_delete__ (@var{handle}, @var{path})\n\ | |
1281 Undocumented internal function\n\ | |
1282 @end deftypefn") | |
1283 { | |
1284 #ifdef HAVE_CURL | |
1285 int nargin = args.length (); | |
1286 | |
1287 if (nargin != 2) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
1288 error ("__ftp_delete__: incorrect number of arguments"); |
9880 | 1289 else |
1290 { | |
1291 std::string handle = args(0).string_value (); | |
1292 std::string file = args(1).string_value (); | |
1293 | |
1294 if (!error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1295 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1296 const curl_handle curl = handles.contents (handle); |
9880 | 1297 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1298 if (curl.is_valid ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1299 curl.del (file); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1300 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1301 error ("__ftp_delete__: invalid ftp handle"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1302 } |
9880 | 1303 } |
1304 #else | |
1305 error ("__ftp_delete__: not available in this version of Octave"); | |
1306 #endif | |
1307 | |
1308 return octave_value (); | |
1309 } | |
1310 | |
1311 DEFUN_DLD (__ftp_rmdir__, args, , | |
1312 "-*- texinfo -*-\n\ | |
1313 @deftypefn {Loadable Function} {} __ftp_rmdir__ (@var{handle}, @var{path})\n\ | |
1314 Undocumented internal function\n\ | |
1315 @end deftypefn") | |
1316 { | |
1317 #ifdef HAVE_CURL | |
1318 int nargin = args.length (); | |
1319 | |
1320 if (nargin != 2) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
1321 error ("__ftp_rmdir__: incorrect number of arguments"); |
9880 | 1322 else |
1323 { | |
1324 std::string handle = args(0).string_value (); | |
1325 std::string dir = args(1).string_value (); | |
1326 | |
1327 if (!error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1328 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1329 const curl_handle curl = handles.contents (handle); |
9880 | 1330 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1331 if (curl.is_valid ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1332 curl.rmdir (dir); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1333 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1334 error ("__ftp_rmdir__: invalid ftp handle"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1335 } |
9880 | 1336 } |
1337 #else | |
1338 error ("__ftp_rmdir__: not available in this version of Octave"); | |
1339 #endif | |
1340 | |
1341 return octave_value (); | |
1342 } | |
1343 | |
1344 DEFUN_DLD (__ftp_mkdir__, args, , | |
1345 "-*- texinfo -*-\n\ | |
1346 @deftypefn {Loadable Function} {} __ftp_mkdir__ (@var{handle}, @var{path})\n\ | |
1347 Undocumented internal function\n\ | |
1348 @end deftypefn") | |
1349 { | |
1350 #ifdef HAVE_CURL | |
1351 int nargin = args.length (); | |
1352 | |
1353 if (nargin != 2) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
1354 error ("__ftp_mkdir__: incorrect number of arguments"); |
9880 | 1355 else |
1356 { | |
1357 std::string handle = args(0).string_value (); | |
1358 std::string dir = args(1).string_value (); | |
1359 | |
1360 if (!error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1361 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1362 const curl_handle curl = handles.contents (handle); |
9880 | 1363 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1364 if (curl.is_valid ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1365 curl.mkdir (dir); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1366 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1367 error ("__ftp_mkdir__: invalid ftp handle"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1368 } |
9880 | 1369 } |
1370 #else | |
1371 error ("__ftp_mkdir__: not available in this version of Octave"); | |
1372 #endif | |
1373 | |
1374 return octave_value (); | |
1375 } | |
1376 | |
1377 DEFUN_DLD (__ftp_rename__, args, , | |
1378 "-*- texinfo -*-\n\ | |
1379 @deftypefn {Loadable Function} {} __ftp_rename__ (@var{handle}, @var{path})\n\ | |
1380 Undocumented internal function\n\ | |
1381 @end deftypefn") | |
1382 { | |
1383 #ifdef HAVE_CURL | |
1384 int nargin = args.length (); | |
1385 | |
1386 if (nargin != 3) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
1387 error ("__ftp_rename__: incorrect number of arguments"); |
9880 | 1388 else |
1389 { | |
1390 std::string handle = args(0).string_value (); | |
1391 std::string oldname = args(1).string_value (); | |
1392 std::string newname = args(2).string_value (); | |
1393 | |
1394 if (!error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1395 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1396 const curl_handle curl = handles.contents (handle); |
9880 | 1397 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1398 if (curl.is_valid ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1399 curl.rename (oldname, newname); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1400 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1401 error ("__ftp_rename__: invalid ftp handle"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1402 } |
9880 | 1403 } |
1404 #else | |
1405 error ("__ftp_rename__: not available in this version of Octave"); | |
1406 #endif | |
1407 | |
1408 return octave_value (); | |
1409 } | |
1410 | |
9905
84a7c11ff928
Correctly compile even when libcurl is not present according to configure
Rik <rdrider0-list@yahoo.com>
parents:
9885
diff
changeset
|
1411 #ifdef HAVE_CURL |
9880 | 1412 static string_vector |
1413 mput_directory (const curl_handle& curl, const std::string& base, | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1414 const std::string& dir) |
9880 | 1415 { |
1416 string_vector retval; | |
1417 | |
1418 if (! curl.mkdir (dir, false)) | |
1419 warning ("__ftp_mput__: can not create the remote directory ""%s""", | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1420 (base.length() == 0 ? dir : base + |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1421 file_ops::dir_sep_str () + dir).c_str ()); |
9880 | 1422 |
1423 curl.cwd (dir); | |
1424 | |
1425 if (! error_state) | |
1426 { | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9918
diff
changeset
|
1427 unwind_protect_safe frame; |
9880 | 1428 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9918
diff
changeset
|
1429 frame.add_fcn (reset_path, curl); |
9880 | 1430 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1431 std::string realdir = base.length() == 0 ? dir : base + |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1432 file_ops::dir_sep_str () + dir; |
9880 | 1433 |
1434 dir_entry dirlist (realdir); | |
1435 | |
1436 if (dirlist) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1437 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1438 string_vector files = dirlist.read (); |
9880 | 1439 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1440 for (octave_idx_type i = 0; i < files.length (); i++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1441 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1442 std::string file = files (i); |
9880 | 1443 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1444 if (file == "." || file == "..") |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1445 continue; |
9880 | 1446 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1447 std::string realfile = realdir + file_ops::dir_sep_str () + file; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1448 file_stat fs (realfile); |
9880 | 1449 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1450 if (! fs.exists ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1451 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1452 error ("__ftp__mput: file ""%s"" does not exist", |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1453 realfile.c_str ()); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1454 break; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1455 } |
9880 | 1456 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1457 if (fs.is_dir ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1458 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1459 retval.append (mput_directory (curl, realdir, file)); |
9880 | 1460 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1461 if (error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1462 break; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1463 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1464 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1465 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1466 // FIXME Does ascii mode need to be flagged here? |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1467 std::ifstream ifile (realfile.c_str(), std::ios::in | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1468 std::ios::binary); |
9880 | 1469 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1470 if (! ifile.is_open ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1471 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1472 error ("__ftp_mput__: unable to open file ""%s""", |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1473 realfile.c_str ()); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1474 break; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1475 } |
9880 | 1476 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1477 curl.put (file, ifile); |
9880 | 1478 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1479 ifile.close (); |
9880 | 1480 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1481 if (error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1482 break; |
9880 | 1483 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1484 retval.append (realfile); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1485 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1486 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1487 } |
9880 | 1488 else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1489 error ("__ftp_mput__: can not read the directory ""%s""", |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1490 realdir.c_str()); |
9880 | 1491 } |
1492 | |
1493 return retval; | |
1494 } | |
9905
84a7c11ff928
Correctly compile even when libcurl is not present according to configure
Rik <rdrider0-list@yahoo.com>
parents:
9885
diff
changeset
|
1495 #endif |
9880 | 1496 |
1497 DEFUN_DLD (__ftp_mput__, args, nargout, | |
1498 "-*- texinfo -*-\n\ | |
1499 @deftypefn {Loadable Function} {} __ftp_mput__ (@var{handle}, @var{files})\n\ | |
1500 Undocumented internal function\n\ | |
1501 @end deftypefn") | |
1502 { | |
1503 string_vector retval; | |
1504 | |
1505 #ifdef HAVE_CURL | |
1506 int nargin = args.length (); | |
1507 | |
1508 if (nargin != 2) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
1509 error ("__ftp_mput__: incorrect number of arguments"); |
9880 | 1510 else |
1511 { | |
1512 std::string handle = args(0).string_value (); | |
1513 std::string pat = args(1).string_value (); | |
1514 | |
1515 if (!error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1516 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1517 const curl_handle curl = handles.contents (handle); |
9880 | 1518 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1519 if (curl.is_valid ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1520 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1521 glob_match pattern (file_ops::tilde_expand (pat)); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1522 string_vector files = pattern.glob (); |
9880 | 1523 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1524 for (octave_idx_type i = 0; i < files.length (); i++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1525 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1526 std::string file = files (i); |
9880 | 1527 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1528 file_stat fs (file); |
9880 | 1529 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1530 if (! fs.exists ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1531 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1532 error ("__ftp__mput: file does not exist"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1533 break; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1534 } |
9880 | 1535 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1536 if (fs.is_dir ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1537 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1538 retval.append (mput_directory (curl, "", file)); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1539 if (error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1540 break; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1541 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1542 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1543 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1544 // FIXME Does ascii mode need to be flagged here? |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1545 std::ifstream ifile (file.c_str(), std::ios::in | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1546 std::ios::binary); |
9880 | 1547 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1548 if (! ifile.is_open ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1549 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1550 error ("__ftp_mput__: unable to open file"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1551 break; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1552 } |
9880 | 1553 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1554 curl.put (file, ifile); |
9880 | 1555 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1556 ifile.close (); |
9880 | 1557 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1558 if (error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1559 break; |
9880 | 1560 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1561 retval.append (file); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1562 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1563 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1564 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1565 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1566 error ("__ftp_mput__: invalid ftp handle"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1567 } |
9880 | 1568 } |
1569 #else | |
1570 error ("__ftp_mput__: not available in this version of Octave"); | |
1571 #endif | |
1572 | |
1573 return (nargout > 0 ? octave_value (retval) : octave_value ()); | |
1574 } | |
1575 | |
1576 #ifdef HAVE_CURL | |
1577 static void | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1578 getallfiles (const curl_handle& curl, const std::string& dir, |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1579 const std::string& target) |
9880 | 1580 { |
1581 std::string sep = file_ops::dir_sep_str (); | |
1582 file_stat fs (dir); | |
1583 | |
1584 if (!fs || !fs.is_dir ()) | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1585 { |
9880 | 1586 std::string msg; |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10154
diff
changeset
|
1587 int status = octave_mkdir (dir, 0777, msg); |
9880 | 1588 |
1589 if (status < 0) | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1590 error ("__ftp_mget__: can't create directory %s%s%s. %s", |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1591 target.c_str(), sep.c_str(), dir.c_str(), msg.c_str()); |
9880 | 1592 } |
1593 | |
1594 if (! error_state) | |
1595 { | |
1596 curl.cwd (dir); | |
1597 | |
1598 if (! error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1599 { |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9918
diff
changeset
|
1600 unwind_protect_safe frame; |
9880 | 1601 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1602 frame.add_fcn (reset_path, curl); |
9880 | 1603 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9918
diff
changeset
|
1604 string_vector sv = curl.list (); |
9880 | 1605 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1606 for (octave_idx_type i = 0; i < sv.length (); i++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1607 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1608 time_t ftime; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1609 bool fisdir; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1610 double fsize; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1611 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1612 curl.get_fileinfo (sv(i), fsize, ftime, fisdir); |
9880 | 1613 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1614 if (fisdir) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1615 getallfiles (curl, sv(i), target + dir + sep); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1616 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1617 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1618 std::string realfile = target + dir + sep + sv(i); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1619 std::ofstream ofile (realfile.c_str(), |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1620 std::ios::out | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1621 std::ios::binary); |
9880 | 1622 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1623 if (! ofile.is_open ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1624 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1625 error ("__ftp_mget__: unable to open file"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1626 break; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1627 } |
9880 | 1628 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9918
diff
changeset
|
1629 unwind_protect_safe frame2; |
9880 | 1630 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1631 frame2.add_fcn (delete_file, realfile); |
9880 | 1632 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1633 curl.get (sv(i), ofile); |
9880 | 1634 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1635 ofile.close (); |
9880 | 1636 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1637 if (!error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1638 frame2.discard (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1639 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1640 frame2.run (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1641 } |
9880 | 1642 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1643 if (error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1644 break; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1645 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1646 } |
9880 | 1647 } |
1648 } | |
1649 #endif | |
1650 | |
1651 DEFUN_DLD (__ftp_mget__, args, , | |
1652 "-*- texinfo -*-\n\ | |
1653 @deftypefn {Loadable Function} {} __ftp_mget__ (@var{handle}, @var{files})\n\ | |
1654 Undocumented internal function\n\ | |
1655 @end deftypefn") | |
1656 { | |
1657 #ifdef HAVE_CURL | |
1658 int nargin = args.length (); | |
1659 | |
1660 if (nargin != 2 && nargin != 3) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
1661 error ("__ftp_mget__: incorrect number of arguments"); |
9880 | 1662 else |
1663 { | |
1664 std::string handle = args(0).string_value (); | |
1665 std::string file = args(1).string_value (); | |
1666 std::string target; | |
1667 | |
1668 if (nargin == 3) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1669 target = args(2).string_value () + file_ops::dir_sep_str (); |
9880 | 1670 |
1671 if (! error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1672 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1673 const curl_handle curl = handles.contents (handle); |
9880 | 1674 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1675 if (curl.is_valid ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1676 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1677 string_vector sv = curl.list (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1678 octave_idx_type n = 0; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1679 glob_match pattern (file); |
9880 | 1680 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1681 for (octave_idx_type i = 0; i < sv.length (); i++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1682 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1683 if (pattern.match (sv(i))) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1684 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1685 n++; |
9880 | 1686 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1687 time_t ftime; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1688 bool fisdir; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1689 double fsize; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1690 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1691 curl.get_fileinfo (sv(i), fsize, ftime, fisdir); |
9880 | 1692 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1693 if (fisdir) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1694 getallfiles (curl, sv(i), target); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1695 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1696 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1697 std::ofstream ofile ((target + sv(i)).c_str(), |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1698 std::ios::out | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1699 std::ios::binary); |
9880 | 1700 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1701 if (! ofile.is_open ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1702 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1703 error ("__ftp_mget__: unable to open file"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1704 break; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1705 } |
9880 | 1706 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9918
diff
changeset
|
1707 unwind_protect_safe frame; |
9880 | 1708 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1709 frame.add_fcn (delete_file, target + sv(i)); |
9880 | 1710 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1711 curl.get (sv(i), ofile); |
9880 | 1712 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1713 ofile.close (); |
9880 | 1714 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1715 if (!error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1716 frame.discard (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1717 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1718 frame.run (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1719 } |
9880 | 1720 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1721 if (error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1722 break; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1723 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1724 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1725 if (n == 0) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1726 error ("__ftp_mget__: file not found"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1727 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1728 } |
9880 | 1729 } |
1730 #else | |
1731 error ("__ftp_mget__: not available in this version of Octave"); | |
1732 #endif | |
1733 | |
1734 return octave_value (); | |
1735 } |