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