Mercurial > octave
annotate libinterp/corefcn/urlwrite.cc @ 20799:c349d4c91ce2
eliminate return statements after calls to print_usage
* symtab.cc, sysdep.cc, toplev.cc, tsearch.cc, urlwrite.cc,
variables.cc: Eliminate return statements after calls to print_usage.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 03 Dec 2015 16:40:05 -0500 |
parents | 25d676f9619c |
children | f428cbe7576f |
rev | line source |
---|---|
6043 | 1 // urlwrite and urlread, a curl front-end for octave |
2 /* | |
3 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19597
diff
changeset
|
4 Copyright (C) 2006-2015 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" |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
44 #include "url-transfer.h" |
6043 | 45 |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
46 #include "defun.h" |
6043 | 47 #include "error.h" |
48 #include "oct-obj.h" | |
49 #include "ov-cell.h" | |
50 #include "pager.h" | |
9880 | 51 #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
|
52 #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
|
53 #include "unwind-prot.h" |
17550
77127a3badaa
move curl_object actions to rep class
John W. Eaton <jwe@octave.org>
parents:
17549
diff
changeset
|
54 |
77127a3badaa
move curl_object actions to rep class
John W. Eaton <jwe@octave.org>
parents:
17549
diff
changeset
|
55 static void |
77127a3badaa
move curl_object actions to rep class
John W. Eaton <jwe@octave.org>
parents:
17549
diff
changeset
|
56 delete_file (const std::string& file) |
77127a3badaa
move curl_object actions to rep class
John W. Eaton <jwe@octave.org>
parents:
17549
diff
changeset
|
57 { |
77127a3badaa
move curl_object actions to rep class
John W. Eaton <jwe@octave.org>
parents:
17549
diff
changeset
|
58 octave_unlink (file); |
77127a3badaa
move curl_object actions to rep class
John W. Eaton <jwe@octave.org>
parents:
17549
diff
changeset
|
59 } |
6043 | 60 |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
61 typedef octave_handle curl_handle; |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
62 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
63 class OCTINTERP_API ch_manager |
9880 | 64 { |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
65 protected: |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
66 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
67 ch_manager (void) |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
68 : handle_map (), handle_free_list (), |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
69 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
|
70 |
9880 | 71 public: |
72 | |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
73 static void create_instance (void); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
74 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
75 static bool instance_ok (void) |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
76 { |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
77 bool retval = true; |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
78 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
79 if (! instance) |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
80 create_instance (); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
81 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
82 if (! instance) |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
83 { |
20428
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
84 error ("unable to create ch_manager!"); |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
85 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
86 retval = false; |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
87 } |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
88 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
89 return retval; |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
90 } |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
91 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
92 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
|
93 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
94 static curl_handle get_handle (void) |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
95 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
96 return instance_ok () ? instance->do_get_handle () : curl_handle (); |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
97 } |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
98 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
99 static void free (const curl_handle& h) |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
100 { |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
101 if (instance_ok ()) |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
102 instance->do_free (h); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
103 } |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
104 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
105 static curl_handle lookup (double val) |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
106 { |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
107 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
|
108 } |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
109 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
110 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
|
111 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
112 return val.is_real_scalar () ? lookup (val.double_value ()) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
113 : curl_handle (); |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
114 } |
6043 | 115 |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
116 static url_transfer get_object (double val) |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
117 { |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
118 return get_object (lookup (val)); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
119 } |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
120 |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
121 static url_transfer get_object (const octave_value& val) |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
122 { |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
123 return get_object (lookup (val)); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
124 } |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
125 |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
126 static url_transfer get_object (const curl_handle& h) |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
127 { |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
128 return instance_ok () ? instance->do_get_object (h) : url_transfer (); |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
129 } |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
130 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
131 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
|
132 const std::string& user, |
17556
9e8a9f043944
fix error in previous commit
John W. Eaton <jwe@octave.org>
parents:
17555
diff
changeset
|
133 const std::string& passwd, |
9e8a9f043944
fix error in previous commit
John W. Eaton <jwe@octave.org>
parents:
17555
diff
changeset
|
134 std::ostream& os) |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
135 { |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
136 return instance_ok () |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
137 ? instance->do_make_curl_handle (host, user, passwd, os) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
138 : curl_handle (); |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
139 } |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
140 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
141 static Matrix handle_list (void) |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
142 { |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
143 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
|
144 } |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
145 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
146 private: |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
147 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
148 static ch_manager *instance; |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
149 |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
150 typedef std::map<curl_handle, url_transfer>::iterator iterator; |
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
151 typedef std::map<curl_handle, url_transfer>::const_iterator const_iterator; |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
152 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
153 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
|
154 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
|
155 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
156 // A map of handles to curl objects. |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
157 std::map<curl_handle, url_transfer> handle_map; |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
158 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
159 // The available curl handles. |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
160 std::set<curl_handle> handle_free_list; |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
161 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
162 // 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
|
163 double next_handle; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
164 |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
165 curl_handle do_get_handle (void); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
166 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
167 void do_free (const curl_handle& h); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
168 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
169 curl_handle do_lookup (double val) |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
170 { |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
171 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
|
172 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
173 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
|
174 } |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
175 |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
176 url_transfer do_get_object (const curl_handle& h) |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
177 { |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
178 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
|
179 |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
180 return (p != handle_map.end ()) ? p->second : url_transfer (); |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
181 } |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
182 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
183 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
|
184 const std::string& user, |
17556
9e8a9f043944
fix error in previous commit
John W. Eaton <jwe@octave.org>
parents:
17555
diff
changeset
|
185 const std::string& passwd, |
9e8a9f043944
fix error in previous commit
John W. Eaton <jwe@octave.org>
parents:
17555
diff
changeset
|
186 std::ostream& os) |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
187 { |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
188 curl_handle h = get_handle (); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
189 |
17556
9e8a9f043944
fix error in previous commit
John W. Eaton <jwe@octave.org>
parents:
17555
diff
changeset
|
190 url_transfer obj (host, user, passwd, os); |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
191 |
18287
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
192 if (obj.is_valid ()) |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
193 handle_map[h] = obj; |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
194 else |
20726
25d676f9619c
Preface error() messages with name of function when possible.
Rik <rik@octave.org>
parents:
20716
diff
changeset
|
195 error ("support for URL transfers was disabled when Octave was built"); |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
196 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
197 return h; |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
198 } |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
199 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
200 Matrix do_handle_list (void) |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
201 { |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
202 Matrix retval (1, handle_map.size ()); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
203 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
204 octave_idx_type i = 0; |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
205 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
|
206 { |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
207 curl_handle h = p->first; |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
208 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
209 retval(i++) = h.value (); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
210 } |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
211 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
212 return retval; |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
213 } |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
214 }; |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
215 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
216 void |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
217 ch_manager::create_instance (void) |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
218 { |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
219 instance = new ch_manager (); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
220 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
221 if (instance) |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
222 singleton_cleanup_list::add (cleanup_instance); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
223 } |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
224 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
225 static double |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
226 make_handle_fraction (void) |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
227 { |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
228 static double maxrand = RAND_MAX + 2.0; |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
229 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
230 return (rand () + 1.0) / maxrand; |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
231 } |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
232 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
233 curl_handle |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
234 ch_manager::do_get_handle (void) |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
235 { |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
236 curl_handle retval; |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
237 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
238 // 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
|
239 // 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
|
240 // 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
|
241 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
242 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
|
243 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
244 if (p != handle_free_list.end ()) |
9880 | 245 { |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
246 retval = *p; |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
247 handle_free_list.erase (p); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
248 } |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
249 else |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
250 { |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
251 retval = curl_handle (next_handle); |
6992 | 252 |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
253 next_handle = std::ceil (next_handle) - 1.0 - make_handle_fraction (); |
9880 | 254 } |
255 | |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
256 return retval; |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
257 } |
9880 | 258 |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
259 void |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
260 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
|
261 { |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
262 if (h.ok ()) |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
263 { |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
264 iterator p = handle_map.find (h); |
9880 | 265 |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
266 if (p != handle_map.end ()) |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
267 { |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
268 // 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
|
269 // 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
|
270 // 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
|
271 // each time. |
9880 | 272 |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
273 handle_map.erase (p); |
9880 | 274 |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
275 if (h.value () < 0) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
276 handle_free_list.insert |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
277 (std::ceil (h.value ()) - make_handle_fraction ()); |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
278 } |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
279 else |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
280 error ("ch_manager::free: invalid object %g", h.value ()); |
9880 | 281 } |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
282 } |
9880 | 283 |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
284 ch_manager *ch_manager::instance = 0; |
9880 | 285 |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
286 DEFUN (urlwrite, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
287 "-*- texinfo -*-\n\ |
10840 | 288 @deftypefn {Loadable Function} {} urlwrite (@var{url}, @var{localfile})\n\ |
6043 | 289 @deftypefnx {Loadable Function} {@var{f} =} urlwrite (@var{url}, @var{localfile})\n\ |
290 @deftypefnx {Loadable Function} {[@var{f}, @var{success}] =} urlwrite (@var{url}, @var{localfile})\n\ | |
291 @deftypefnx {Loadable Function} {[@var{f}, @var{success}, @var{message}] =} urlwrite (@var{url}, @var{localfile})\n\ | |
9880 | 292 Download a remote file specified by its @var{url} and save it as\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
293 @var{localfile}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
294 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
295 For example:\n\ |
6043 | 296 \n\ |
297 @example\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
298 @group\n\ |
19160
432ffa35de13
doc: Fix dead link in urlwrite/urlread docstring (bug #43082).
Nir Krakauer < nkrakauer@ccny.cuny.edu>
parents:
18391
diff
changeset
|
299 urlwrite (\"ftp://ftp.octave.org/pub/README\",\n\ |
7031 | 300 \"README.txt\");\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
301 @end group\n\ |
6043 | 302 @end example\n\ |
303 \n\ | |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
304 The full path of the downloaded file is returned in @var{f}.\n\ |
6043 | 305 \n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
306 The variable @var{success} is 1 if the download was successful,\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
307 otherwise it is 0 in which case @var{message} contains an error message.\n\ |
20181
aa36fb998a4d
maint: Remove unnecessary whitespace at end of lines.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
308 \n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
309 If no output argument is specified and an error occurs, then the error is\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
310 signaled through Octave's error handling mechanism.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
311 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
312 This function uses libcurl. Curl supports, among others, the HTTP, FTP and\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
313 FILE protocols. Username and password may be specified in the URL, for\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
314 example:\n\ |
6043 | 315 \n\ |
316 @example\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
317 @group\n\ |
6588 | 318 urlwrite (\"http://username:password@@example.com/file.txt\",\n\ |
319 \"file.txt\");\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
320 @end group\n\ |
6043 | 321 @end example\n\ |
322 \n\ | |
323 GET and POST requests can be specified by @var{method} and @var{param}.\n\ | |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
324 The parameter @var{method} is either @samp{get} or @samp{post} and\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
325 @var{param} is a cell array of parameter and value pairs.\n\ |
6588 | 326 For example:\n\ |
6043 | 327 \n\ |
328 @example\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
329 @group\n\ |
6588 | 330 urlwrite (\"http://www.google.com/search\", \"search.html\",\n\ |
331 \"get\", @{\"query\", \"octave\"@});\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
332 @end group\n\ |
6043 | 333 @end example\n\ |
334 @seealso{urlread}\n\ | |
335 @end deftypefn") | |
336 { | |
337 octave_value_list retval; | |
338 | |
339 int nargin = args.length (); | |
340 | |
341 // verify arguments | |
342 if (nargin != 2 && nargin != 4) | |
20799
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20726
diff
changeset
|
343 print_usage (); |
6043 | 344 |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
345 std::string url = args(0).xstring_value ("urlwrite: URL must be a string"); |
6043 | 346 |
19404
c2f4f6eb5907
A few more instances of stricter input validation for strings (bug #42651).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
347 // name to store the file if download is succesful |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
348 std::string filename = args(1).xstring_value ("urlwrite: LOCALFILE must be a string"); |
19404
c2f4f6eb5907
A few more instances of stricter input validation for strings (bug #42651).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
349 |
6043 | 350 std::string method; |
17554
f0d21e7d4653
avoid Cell arrays in usr_transfer classes
John W. Eaton <jwe@octave.org>
parents:
17553
diff
changeset
|
351 Array<std::string> param; |
6043 | 352 |
353 if (nargin == 4) | |
354 { | |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
355 method = args(2).xstring_value ("urlwrite: METHOD must be a string"); |
6043 | 356 |
19404
c2f4f6eb5907
A few more instances of stricter input validation for strings (bug #42651).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
357 if (method != "get" && method != "post") |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
358 { |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
359 error ("urlwrite: METHOD must be \"get\" or \"post\""); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
360 return retval; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
361 } |
6043 | 362 |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
363 param = args(3).xcellstr_value ("urlwrite: parameters (PARAM) for get and post requests must be given as a cell array of strings"); |
6043 | 364 |
18678
6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents:
18391
diff
changeset
|
365 if (param.numel () % 2 == 1) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
366 { |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
367 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
|
368 return retval; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
369 } |
6043 | 370 } |
371 | |
8151
3725f819b5b3
urlwrite.cc (Furlwrite): delete files we create if download fails
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
372 // 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
|
373 // 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
|
374 // 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
|
375 |
3725f819b5b3
urlwrite.cc (Furlwrite): delete files we create if download fails
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
376 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
|
377 |
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
|
378 std::ofstream ofile (filename.c_str (), std::ios::out | std::ios::binary); |
6043 | 379 |
6986 | 380 if (! ofile.is_open ()) |
6043 | 381 { |
382 error ("urlwrite: unable to open file"); | |
383 return retval; | |
384 } | |
385 | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9918
diff
changeset
|
386 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
|
387 |
17549
a646665cd574
eliminate unecessary static function in urlwrite.cc
John W. Eaton <jwe@octave.org>
parents:
17548
diff
changeset
|
388 frame.add_fcn (delete_file, filename); |
9880 | 389 |
17596
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17556
diff
changeset
|
390 url_transfer curl = url_transfer (url, ofile); |
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17556
diff
changeset
|
391 |
18391
af04b9d9f7ed
allow urlwrite to work again
John W. Eaton <jwe@octave.org>
parents:
18329
diff
changeset
|
392 if (curl.is_valid ()) |
18287
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
393 { |
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
394 curl.http_action (param, method); |
6043 | 395 |
18287
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
396 ofile.close (); |
17553
2d01e20abd85
rework error handling for url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17551
diff
changeset
|
397 |
2d01e20abd85
rework error handling for url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17551
diff
changeset
|
398 if (curl.good ()) |
18287
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
399 frame.discard (); |
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
400 |
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
401 if (nargout > 0) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
402 { |
18287
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
403 if (curl.good ()) |
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
404 { |
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
405 retval(2) = std::string (); |
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
406 retval(1) = true; |
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
407 retval(0) = octave_env::make_absolute (filename); |
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
408 } |
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
409 else |
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
410 { |
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
411 retval(2) = curl.lasterror (); |
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
412 retval(1) = false; |
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
413 retval(0) = std::string (); |
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
414 } |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
415 } |
18287
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
416 |
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
417 if (nargout < 2 && ! curl.good ()) |
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
418 error ("urlwrite: %s", curl.lasterror ().c_str ()); |
17553
2d01e20abd85
rework error handling for url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17551
diff
changeset
|
419 } |
18287
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
420 else |
20726
25d676f9619c
Preface error() messages with name of function when possible.
Rik <rik@octave.org>
parents:
20716
diff
changeset
|
421 error ("support for URL transfers was disabled when Octave was built"); |
6043 | 422 |
423 return retval; | |
424 } | |
425 | |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
426 DEFUN (urlread, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
427 "-*- texinfo -*-\n\ |
10840 | 428 @deftypefn {Loadable Function} {@var{s} =} urlread (@var{url})\n\ |
6043 | 429 @deftypefnx {Loadable Function} {[@var{s}, @var{success}] =} urlread (@var{url})\n\ |
6549 | 430 @deftypefnx {Loadable Function} {[@var{s}, @var{success}, @var{message}] =} urlread (@var{url})\n\ |
6547 | 431 @deftypefnx {Loadable Function} {[@dots{}] =} urlread (@var{url}, @var{method}, @var{param})\n\ |
9880 | 432 Download a remote file specified by its @var{url} and return its content\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
433 in string @var{s}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
434 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
435 For example:\n\ |
6043 | 436 \n\ |
437 @example\n\ | |
19160
432ffa35de13
doc: Fix dead link in urlwrite/urlread docstring (bug #43082).
Nir Krakauer < nkrakauer@ccny.cuny.edu>
parents:
18391
diff
changeset
|
438 s = urlread (\"ftp://ftp.octave.org/pub/README\");\n\ |
6043 | 439 @end example\n\ |
440 \n\ | |
441 The variable @var{success} is 1 if the download was successful,\n\ | |
442 otherwise it is 0 in which case @var{message} contains an error\n\ | |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
443 message.\n\ |
6043 | 444 \n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
445 If no output argument is specified and an error occurs, then the error is\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
446 signaled through Octave's error handling mechanism.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
447 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
448 This function uses libcurl. Curl supports, among others, the HTTP, FTP and\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
449 FILE protocols. Username and password may be specified in the URL@. For\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
450 example:\n\ |
6043 | 451 \n\ |
452 @example\n\ | |
7031 | 453 s = urlread (\"http://user:password@@example.com/file.txt\");\n\ |
6043 | 454 @end example\n\ |
455 \n\ | |
456 GET and POST requests can be specified by @var{method} and @var{param}.\n\ | |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
457 The parameter @var{method} is either @samp{get} or @samp{post} and\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
458 @var{param} is a cell array of parameter and value pairs.\n\ |
10840 | 459 For example:\n\ |
6043 | 460 \n\ |
461 @example\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
462 @group\n\ |
6588 | 463 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
|
464 @{\"query\", \"octave\"@});\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
465 @end group\n\ |
6043 | 466 @end example\n\ |
467 @seealso{urlwrite}\n\ | |
468 @end deftypefn") | |
469 { | |
6588 | 470 // Octave's return value |
6043 | 471 octave_value_list retval; |
472 | |
473 int nargin = args.length (); | |
474 | |
475 // verify arguments | |
19403
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19220
diff
changeset
|
476 if (nargin != 1 && nargin != 3) |
20799
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20726
diff
changeset
|
477 print_usage (); |
6043 | 478 |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
479 std::string url = args(0).xstring_value ("urlread: URL must be a string"); |
19404
c2f4f6eb5907
A few more instances of stricter input validation for strings (bug #42651).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
480 |
6043 | 481 std::string method; |
17554
f0d21e7d4653
avoid Cell arrays in usr_transfer classes
John W. Eaton <jwe@octave.org>
parents:
17553
diff
changeset
|
482 Array<std::string> param; |
6043 | 483 |
484 if (nargin == 3) | |
485 { | |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
486 method = args(1).xstring_value ("urlread: METHOD must be a string"); |
6043 | 487 |
19404
c2f4f6eb5907
A few more instances of stricter input validation for strings (bug #42651).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
488 if (method != "get" && method != "post") |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
489 { |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
490 error ("urlread: METHOD must be \"get\" or \"post\""); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
491 return retval; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
492 } |
6043 | 493 |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
494 param = args(2).xcellstr_value ("urlread: parameters (PARAM) for get and post requests must be given as a cell array of strings"); |
6043 | 495 |
18678
6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents:
18391
diff
changeset
|
496 if (param.numel () % 2 == 1) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
497 { |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
498 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
|
499 return retval; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
500 } |
6043 | 501 } |
502 | |
6986 | 503 std::ostringstream buf; |
6043 | 504 |
17596
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17556
diff
changeset
|
505 url_transfer curl = url_transfer (url, buf); |
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17556
diff
changeset
|
506 |
18287
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
507 if (curl.is_valid ()) |
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
508 { |
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
509 curl.http_action (param, method); |
6043 | 510 |
18329
b522d04382cf
Return all nargout from urlread if requested (bug #41260).
Rik <rik@octave.org>
parents:
18287
diff
changeset
|
511 if (nargout > 0) |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
512 { |
18329
b522d04382cf
Return all nargout from urlread if requested (bug #41260).
Rik <rik@octave.org>
parents:
18287
diff
changeset
|
513 // Return empty string if no error occured. |
b522d04382cf
Return all nargout from urlread if requested (bug #41260).
Rik <rik@octave.org>
parents:
18287
diff
changeset
|
514 retval(2) = curl.good () ? "" : curl.lasterror (); |
b522d04382cf
Return all nargout from urlread if requested (bug #41260).
Rik <rik@octave.org>
parents:
18287
diff
changeset
|
515 retval(1) = curl.good (); |
b522d04382cf
Return all nargout from urlread if requested (bug #41260).
Rik <rik@octave.org>
parents:
18287
diff
changeset
|
516 retval(0) = buf.str (); |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
517 } |
18287
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
518 |
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
519 if (nargout < 2 && ! curl.good ()) |
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
520 error ("urlread: %s", curl.lasterror().c_str()); |
17553
2d01e20abd85
rework error handling for url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17551
diff
changeset
|
521 } |
18287
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
522 else |
20726
25d676f9619c
Preface error() messages with name of function when possible.
Rik <rik@octave.org>
parents:
20716
diff
changeset
|
523 error ("support for URL transfers was disabled when Octave was built"); |
6043 | 524 |
525 return retval; | |
526 } | |
9880 | 527 |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
528 DEFUN (__ftp__, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
529 "-*- texinfo -*-\n\ |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
530 @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
|
531 @deftypefnx {Loadable Function} {@var{handle} =} __ftp__ (@var{host}, @var{username}, @var{password})\n\ |
9880 | 532 Undocumented internal function\n\ |
533 @end deftypefn") | |
534 { | |
535 int nargin = args.length (); | |
536 | |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
537 if (nargin < 1 || nargin > 3) |
20799
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20726
diff
changeset
|
538 print_usage (); |
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20726
diff
changeset
|
539 |
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20726
diff
changeset
|
540 std::string host = args(0).xstring_value ("__ftp__: HOST must be a string"); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
541 |
20799
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20726
diff
changeset
|
542 std::string user = (nargin > 1) |
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20726
diff
changeset
|
543 ? args(1).xstring_value ("__ftp__: USER must be a string") |
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20726
diff
changeset
|
544 : std::string ("anonymous"); |
9880 | 545 |
20799
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20726
diff
changeset
|
546 std::string passwd = (nargin > 2) |
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20726
diff
changeset
|
547 ? args(2).xstring_value ("__ftp__: PASSWD must be a string") |
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20726
diff
changeset
|
548 : std::string (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
549 |
20799
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20726
diff
changeset
|
550 curl_handle ch |
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20726
diff
changeset
|
551 = ch_manager::make_curl_handle (host, user, passwd, octave_stdout); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
552 |
20799
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20726
diff
changeset
|
553 return octave_value (ch.value ()); |
9880 | 554 } |
555 | |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
556 DEFUN (__ftp_pwd__, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
557 "-*- texinfo -*-\n\ |
9880 | 558 @deftypefn {Loadable Function} {} __ftp_pwd__ (@var{handle})\n\ |
559 Undocumented internal function\n\ | |
560 @end deftypefn") | |
561 { | |
562 octave_value retval; | |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
563 |
9880 | 564 int nargin = args.length (); |
565 | |
566 if (nargin != 1) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
567 error ("__ftp_pwd__: incorrect number of arguments"); |
9880 | 568 else |
569 { | |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
570 url_transfer curl = ch_manager::get_object (args(0)); |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
571 |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
572 if (curl.is_valid ()) |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
573 retval = curl.pwd (); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
574 else |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
575 error ("__ftp_pwd__: invalid ftp handle"); |
9880 | 576 } |
577 | |
578 return retval; | |
579 } | |
580 | |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
581 DEFUN (__ftp_cwd__, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
582 "-*- texinfo -*-\n\ |
9880 | 583 @deftypefn {Loadable Function} {} __ftp_cwd__ (@var{handle}, @var{path})\n\ |
584 Undocumented internal function\n\ | |
585 @end deftypefn") | |
586 { | |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
587 octave_value retval; |
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
588 |
9880 | 589 int nargin = args.length (); |
590 | |
591 if (nargin != 1 && nargin != 2) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
592 error ("__ftp_cwd__: incorrect number of arguments"); |
9880 | 593 else |
594 { | |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
595 url_transfer curl = ch_manager::get_object (args(0)); |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
596 |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
597 if (curl.is_valid ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
598 { |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
599 std::string path = ""; |
9880 | 600 |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
601 if (nargin > 1) |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
602 path = args(1).xstring_value ("__ftp_cwd__: PATH must be a string"); |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
603 |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
604 curl.cwd (path); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
605 } |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
606 else |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
607 error ("__ftp_cwd__: invalid ftp handle"); |
9880 | 608 } |
609 | |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
610 return retval; |
9880 | 611 } |
612 | |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
613 DEFUN (__ftp_dir__, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
614 "-*- texinfo -*-\n\ |
9880 | 615 @deftypefn {Loadable Function} {} __ftp_dir__ (@var{handle})\n\ |
616 Undocumented internal function\n\ | |
617 @end deftypefn") | |
618 { | |
619 octave_value retval; | |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
620 |
9880 | 621 int nargin = args.length (); |
622 | |
623 if (nargin != 1) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
624 error ("__ftp_dir__: incorrect number of arguments"); |
9880 | 625 else |
626 { | |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
627 url_transfer curl = ch_manager::get_object (args(0)); |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
628 |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
629 if (curl.is_valid ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
630 { |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
631 if (nargout == 0) |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
632 curl.dir (); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
633 else |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
634 { |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
635 string_vector sv = curl.list (); |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20181
diff
changeset
|
636 octave_idx_type n = sv.numel (); |
9880 | 637 |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
638 if (n == 0) |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
639 { |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
640 string_vector flds (5); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
641 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
642 flds(0) = "name"; |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
643 flds(1) = "date"; |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
644 flds(2) = "bytes"; |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
645 flds(3) = "isdir"; |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
646 flds(4) = "datenum"; |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
647 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
648 retval = octave_map (flds); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
649 } |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
650 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
651 { |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
652 octave_map st; |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
653 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
654 Cell filectime (dim_vector (n, 1)); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
655 Cell filesize (dim_vector (n, 1)); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
656 Cell fileisdir (dim_vector (n, 1)); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
657 Cell filedatenum (dim_vector (n, 1)); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
658 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
659 st.assign ("name", Cell (sv)); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
660 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
661 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
|
662 { |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
663 time_t ftime; |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
664 bool fisdir; |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
665 double fsize; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
666 |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
667 curl.get_fileinfo (sv(i), fsize, ftime, fisdir); |
9880 | 668 |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
669 fileisdir (i) = fisdir; |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
670 filectime (i) = ctime (&ftime); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
671 filesize (i) = fsize; |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
672 filedatenum (i) = double (ftime); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
673 } |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
674 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
675 st.assign ("date", filectime); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
676 st.assign ("bytes", filesize); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
677 st.assign ("isdir", fileisdir); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
678 st.assign ("datenum", filedatenum); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
679 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
680 retval = st; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
681 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
682 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
683 } |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
684 else |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
685 error ("__ftp_dir__: invalid ftp handle"); |
9880 | 686 } |
687 | |
688 return retval; | |
689 } | |
690 | |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
691 DEFUN (__ftp_ascii__, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
692 "-*- texinfo -*-\n\ |
9880 | 693 @deftypefn {Loadable Function} {} __ftp_ascii__ (@var{handle})\n\ |
694 Undocumented internal function\n\ | |
695 @end deftypefn") | |
696 { | |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
697 octave_value retval; |
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
698 |
9880 | 699 int nargin = args.length (); |
700 | |
701 if (nargin != 1) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
702 error ("__ftp_ascii__: incorrect number of arguments"); |
9880 | 703 else |
704 { | |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
705 url_transfer curl = ch_manager::get_object (args(0)); |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
706 |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
707 if (curl.is_valid ()) |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
708 curl.ascii (); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
709 else |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
710 error ("__ftp_ascii__: invalid ftp handle"); |
9880 | 711 } |
712 | |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
713 return retval; |
9880 | 714 } |
715 | |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
716 DEFUN (__ftp_binary__, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
717 "-*- texinfo -*-\n\ |
9880 | 718 @deftypefn {Loadable Function} {} __ftp_binary__ (@var{handle})\n\ |
719 Undocumented internal function\n\ | |
720 @end deftypefn") | |
721 { | |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
722 octave_value retval; |
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
723 |
9880 | 724 int nargin = args.length (); |
725 | |
726 if (nargin != 1) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
727 error ("__ftp_binary__: incorrect number of arguments"); |
9880 | 728 else |
729 { | |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
730 url_transfer curl = ch_manager::get_object (args(0)); |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
731 |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
732 if (curl.is_valid ()) |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
733 curl.binary (); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
734 else |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
735 error ("__ftp_binary__: invalid ftp handle"); |
9880 | 736 } |
737 | |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
738 return retval; |
9880 | 739 } |
740 | |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
741 DEFUN (__ftp_close__, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
742 "-*- texinfo -*-\n\ |
9880 | 743 @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
|
744 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
|
745 @end deftypefn") |
accafe1aee7c
Make use of gripe_disabled_feature() instead of custom error message.
Carnë Draug <carandraug@octave.org>
parents:
15326
diff
changeset
|
746 { |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
747 octave_value retval; |
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
748 |
17318
accafe1aee7c
Make use of gripe_disabled_feature() instead of custom error message.
Carnë Draug <carandraug@octave.org>
parents:
15326
diff
changeset
|
749 int nargin = args.length (); |
9880 | 750 |
17318
accafe1aee7c
Make use of gripe_disabled_feature() instead of custom error message.
Carnë Draug <carandraug@octave.org>
parents:
15326
diff
changeset
|
751 if (nargin != 1) |
accafe1aee7c
Make use of gripe_disabled_feature() instead of custom error message.
Carnë Draug <carandraug@octave.org>
parents:
15326
diff
changeset
|
752 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
|
753 else |
accafe1aee7c
Make use of gripe_disabled_feature() instead of custom error message.
Carnë Draug <carandraug@octave.org>
parents:
15326
diff
changeset
|
754 { |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
755 curl_handle h = ch_manager::lookup (args(0)); |
9880 | 756 |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
757 if (h.ok ()) |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
758 ch_manager::free (h); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
759 else |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
760 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
|
761 } |
9880 | 762 |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
763 return retval; |
17318
accafe1aee7c
Make use of gripe_disabled_feature() instead of custom error message.
Carnë Draug <carandraug@octave.org>
parents:
15326
diff
changeset
|
764 } |
9880 | 765 |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
766 DEFUN (__ftp_mode__, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
767 "-*- texinfo -*-\n\ |
9880 | 768 @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
|
769 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
|
770 @end deftypefn") |
accafe1aee7c
Make use of gripe_disabled_feature() instead of custom error message.
Carnë Draug <carandraug@octave.org>
parents:
15326
diff
changeset
|
771 { |
accafe1aee7c
Make use of gripe_disabled_feature() instead of custom error message.
Carnë Draug <carandraug@octave.org>
parents:
15326
diff
changeset
|
772 octave_value retval; |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
773 |
17318
accafe1aee7c
Make use of gripe_disabled_feature() instead of custom error message.
Carnë Draug <carandraug@octave.org>
parents:
15326
diff
changeset
|
774 int nargin = args.length (); |
9880 | 775 |
17318
accafe1aee7c
Make use of gripe_disabled_feature() instead of custom error message.
Carnë Draug <carandraug@octave.org>
parents:
15326
diff
changeset
|
776 if (nargin != 1) |
accafe1aee7c
Make use of gripe_disabled_feature() instead of custom error message.
Carnë Draug <carandraug@octave.org>
parents:
15326
diff
changeset
|
777 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
|
778 else |
accafe1aee7c
Make use of gripe_disabled_feature() instead of custom error message.
Carnë Draug <carandraug@octave.org>
parents:
15326
diff
changeset
|
779 { |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
780 url_transfer curl = ch_manager::get_object (args(0)); |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
781 |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
782 if (curl.is_valid ()) |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
783 retval = (curl.is_ascii () ? "ascii" : "binary"); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
784 else |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
785 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
|
786 } |
9880 | 787 |
17318
accafe1aee7c
Make use of gripe_disabled_feature() instead of custom error message.
Carnë Draug <carandraug@octave.org>
parents:
15326
diff
changeset
|
788 return retval; |
accafe1aee7c
Make use of gripe_disabled_feature() instead of custom error message.
Carnë Draug <carandraug@octave.org>
parents:
15326
diff
changeset
|
789 } |
9880 | 790 |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
791 DEFUN (__ftp_delete__, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
792 "-*- texinfo -*-\n\ |
9880 | 793 @deftypefn {Loadable Function} {} __ftp_delete__ (@var{handle}, @var{path})\n\ |
794 Undocumented internal function\n\ | |
795 @end deftypefn") | |
796 { | |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
797 octave_value retval; |
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
798 |
9880 | 799 int nargin = args.length (); |
800 | |
801 if (nargin != 2) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
802 error ("__ftp_delete__: incorrect number of arguments"); |
9880 | 803 else |
804 { | |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
805 url_transfer curl = ch_manager::get_object (args(0)); |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
806 |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
807 if (curl.is_valid ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
808 { |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
809 std::string file = args(1).xstring_value ("__ftp_delete__: FILE must be a string"); |
9880 | 810 |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
811 curl.del (file); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
812 } |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
813 else |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
814 error ("__ftp_delete__: invalid ftp handle"); |
9880 | 815 } |
816 | |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
817 return retval; |
9880 | 818 } |
819 | |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
820 DEFUN (__ftp_rmdir__, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
821 "-*- texinfo -*-\n\ |
9880 | 822 @deftypefn {Loadable Function} {} __ftp_rmdir__ (@var{handle}, @var{path})\n\ |
823 Undocumented internal function\n\ | |
824 @end deftypefn") | |
825 { | |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
826 octave_value retval; |
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
827 |
9880 | 828 int nargin = args.length (); |
829 | |
830 if (nargin != 2) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
831 error ("__ftp_rmdir__: incorrect number of arguments"); |
9880 | 832 else |
833 { | |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
834 url_transfer curl = ch_manager::get_object (args(0)); |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
835 |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
836 if (curl.is_valid ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
837 { |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
838 std::string dir = args(1).xstring_value ("__ftp_rmdir__: DIR must be a string"); |
9880 | 839 |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
840 curl.rmdir (dir); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
841 } |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
842 else |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
843 error ("__ftp_rmdir__: invalid ftp handle"); |
9880 | 844 } |
845 | |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
846 return retval; |
9880 | 847 } |
848 | |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
849 DEFUN (__ftp_mkdir__, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
850 "-*- texinfo -*-\n\ |
9880 | 851 @deftypefn {Loadable Function} {} __ftp_mkdir__ (@var{handle}, @var{path})\n\ |
852 Undocumented internal function\n\ | |
853 @end deftypefn") | |
854 { | |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
855 octave_value retval; |
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
856 |
9880 | 857 int nargin = args.length (); |
858 | |
859 if (nargin != 2) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
860 error ("__ftp_mkdir__: incorrect number of arguments"); |
9880 | 861 else |
862 { | |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
863 url_transfer curl = ch_manager::get_object (args(0)); |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
864 |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
865 if (curl.is_valid ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
866 { |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
867 std::string dir = args(1).xstring_value ("__ftp_mkdir__: DIR must be a string"); |
9880 | 868 |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
869 curl.mkdir (dir); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
870 } |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
871 else |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
872 error ("__ftp_mkdir__: invalid ftp handle"); |
9880 | 873 } |
874 | |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
875 return retval; |
9880 | 876 } |
877 | |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
878 DEFUN (__ftp_rename__, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
879 "-*- texinfo -*-\n\ |
9880 | 880 @deftypefn {Loadable Function} {} __ftp_rename__ (@var{handle}, @var{path})\n\ |
881 Undocumented internal function\n\ | |
882 @end deftypefn") | |
883 { | |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
884 octave_value retval; |
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
885 |
9880 | 886 int nargin = args.length (); |
887 | |
888 if (nargin != 3) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
889 error ("__ftp_rename__: incorrect number of arguments"); |
9880 | 890 else |
891 { | |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
892 url_transfer curl = ch_manager::get_object (args(0)); |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
893 |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
894 if (curl.is_valid ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
895 { |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
896 std::string oldname = args(1).xstring_value ("__ftp_rename__: OLDNAME must be a string"); |
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
897 std::string newname = args(2).xstring_value ("__ftp_rename__: NEWNAME must be a string"); |
9880 | 898 |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
899 curl.rename (oldname, newname); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
900 } |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
901 else |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
902 error ("__ftp_rename__: invalid ftp handle"); |
9880 | 903 } |
904 | |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
905 return retval; |
9880 | 906 } |
907 | |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
908 DEFUN (__ftp_mput__, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
909 "-*- texinfo -*-\n\ |
9880 | 910 @deftypefn {Loadable Function} {} __ftp_mput__ (@var{handle}, @var{files})\n\ |
911 Undocumented internal function\n\ | |
912 @end deftypefn") | |
913 { | |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
914 octave_value retval; |
9880 | 915 |
916 int nargin = args.length (); | |
917 | |
918 if (nargin != 2) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
919 error ("__ftp_mput__: incorrect number of arguments"); |
9880 | 920 else |
921 { | |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
922 url_transfer curl = ch_manager::get_object (args(0)); |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
923 |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
924 if (curl.is_valid ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
925 { |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
926 std::string pat = args(1).xstring_value ("__ftp_mput__: PATTERN must be a string"); |
9880 | 927 |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
928 string_vector file_list; |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
929 |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
930 glob_match pattern (file_ops::tilde_expand (pat)); |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
931 string_vector files = pattern.glob (); |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
932 |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
933 for (octave_idx_type i = 0; i < files.numel (); i++) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
934 { |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
935 std::string file = files (i); |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
936 |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
937 file_stat fs (file); |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
938 |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
939 if (! fs.exists ()) |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
940 { |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
941 error ("__ftp__mput: file does not exist"); |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
942 break; |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
943 } |
9880 | 944 |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
945 if (fs.is_dir ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
946 { |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
947 file_list.append (curl.mput_directory ("", file)); |
9880 | 948 |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
949 if (! curl.good ()) |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
950 { |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
951 error ("__ftp_mput__: %s", curl.lasterror().c_str()); |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
952 break; |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
953 } |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
954 } |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
955 else |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
956 { |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
957 // FIXME: Does ascii mode need to be flagged here? |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
958 std::ifstream ifile (file.c_str (), std::ios::in | |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
959 std::ios::binary); |
9880 | 960 |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
961 if (! ifile.is_open ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
962 { |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
963 error ("__ftp_mput__: unable to open file"); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
964 break; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
965 } |
9880 | 966 |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
967 curl.put (file, ifile); |
17553
2d01e20abd85
rework error handling for url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17551
diff
changeset
|
968 |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
969 ifile.close (); |
9880 | 970 |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
971 if (! curl.good ()) |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
972 { |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
973 error ("__ftp_mput__: %s", curl.lasterror().c_str()); |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
974 break; |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
975 } |
9880 | 976 |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
977 file_list.append (file); |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
978 } |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
979 } |
9880 | 980 |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
981 if (nargout > 0) |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
982 retval = file_list; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
983 } |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
984 else |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
985 error ("__ftp_mput__: invalid ftp handle"); |
9880 | 986 } |
987 | |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
988 return retval; |
9880 | 989 } |
990 | |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
991 DEFUN (__ftp_mget__, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
992 "-*- texinfo -*-\n\ |
20716
1ecee53513d7
doc: Peridodic grammar check of documentation.
Rik <rik@octave.org>
parents:
20710
diff
changeset
|
993 @deftypefn {Loadable Function} {} __ftp_mget__ (@var{handle}, @var{pattern})\n\ |
20577
7374a3a6d594
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20560
diff
changeset
|
994 @deftypefnx {Loadable Function} {} __ftp_mget__ (@var{handle}, @var{pattern}, @var{target})\n\ |
9880 | 995 Undocumented internal function\n\ |
996 @end deftypefn") | |
997 { | |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
998 octave_value retval; |
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
999 |
9880 | 1000 int nargin = args.length (); |
1001 | |
1002 if (nargin != 2 && nargin != 3) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
1003 error ("__ftp_mget__: incorrect number of arguments"); |
9880 | 1004 else |
1005 { | |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
1006 url_transfer curl = ch_manager::get_object (args(0)); |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
1007 |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
1008 if (curl.is_valid ()) |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
1009 { |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
1010 std::string file = args(1).xstring_value ("__ftp_mget__: PATTERN must be a string"); |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
1011 std::string target; |
9880 | 1012 |
20710
73800f39da6f
@ftp/mget: honor the TARGET argument
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
20700
diff
changeset
|
1013 if (nargin == 3 && ! args(2).is_empty ()) |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
1014 target = args(2).xstring_value ("__ftp_mget__: TARGET must be a string") + file_ops::dir_sep_str (); |
9880 | 1015 |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
1016 string_vector sv = curl.list (); |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
1017 octave_idx_type n = 0; |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
1018 glob_match pattern (file); |
9880 | 1019 |
17553
2d01e20abd85
rework error handling for url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17551
diff
changeset
|
1020 |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
1021 for (octave_idx_type i = 0; i < sv.numel (); i++) |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
1022 { |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
1023 if (pattern.match (sv(i))) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1024 { |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
1025 n++; |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
1026 |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
1027 time_t ftime; |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
1028 bool fisdir; |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
1029 double fsize; |
9880 | 1030 |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
1031 curl.get_fileinfo (sv(i), fsize, ftime, fisdir); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1032 |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
1033 if (fisdir) |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
1034 curl.mget_directory (sv(i), target); |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
1035 else |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
1036 { |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
1037 std::ofstream ofile ((target + sv(i)).c_str (), |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
1038 std::ios::out | |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
1039 std::ios::binary); |
9880 | 1040 |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
1041 if (! ofile.is_open ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1042 { |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
1043 error ("__ftp_mget__: unable to open file"); |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
1044 break; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1045 } |
9880 | 1046 |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
1047 unwind_protect_safe frame; |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
1048 |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
1049 frame.add_fcn (delete_file, target + sv(i)); |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
1050 |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
1051 curl.get (sv(i), ofile); |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
1052 |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
1053 ofile.close (); |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
1054 |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
1055 if (curl.good ()) |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
1056 frame.discard (); |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
1057 } |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
1058 |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
1059 if (! curl.good ()) |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
1060 { |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
1061 error ("__ftp_mget__: %s", curl.lasterror().c_str()); |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
1062 break; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1063 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1064 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1065 } |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
1066 |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
1067 if (n == 0) |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
1068 error ("__ftp_mget__: file not found"); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1069 } |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
1070 else |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
1071 error ("__ftp_mget__: invalid ftp handle"); |
9880 | 1072 } |
1073 | |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
1074 return retval; |
9880 | 1075 } |