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