Mercurial > hg > octave-jordi
annotate libinterp/corefcn/urlwrite.cc @ 20709:73800f39da6f
@ftp/mget: honor the TARGET argument
* @ftp/mget.m: call __ftp_mget__ with a third argument that defaults to ""
* @ftp/mget.m: rephrase doc for TARGET argument
* urlwrite.cc (F__ftp_mget__): add trailing dirsep only if the target argument
is not empty.
author | Pantxo Diribarne <pantxo.diribarne@gmail.com> |
---|---|
date | Tue, 17 Nov 2015 22:04:42 +0100 |
parents | 68e3a747ca02 |
children | 1ecee53513d7 |
rev | line source |
---|---|
6043 | 1 // urlwrite and urlread, a curl front-end for octave |
2 /* | |
3 | |
19696
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19596
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 { |
20427
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20231
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 |
18286
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 ()) |
20678
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
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 |
18286
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
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\ |
20171
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19696
diff
changeset
|
293 @var{localfile}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19696
diff
changeset
|
294 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19696
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\ |
19159
432ffa35de13
doc: Fix dead link in urlwrite/urlread docstring (bug #43082).
Nir Krakauer < nkrakauer@ccny.cuny.edu>
parents:
18390
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\ | |
20171
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19696
diff
changeset
|
304 The full path of the downloaded file is returned in @var{f}.\n\ |
6043 | 305 \n\ |
20171
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19696
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:
19696
diff
changeset
|
307 otherwise it is 0 in which case @var{message} contains an error message.\n\ |
20180
aa36fb998a4d
maint: Remove unnecessary whitespace at end of lines.
Rik <rik@octave.org>
parents:
20171
diff
changeset
|
308 \n\ |
20171
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19696
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:
19696
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:
19696
diff
changeset
|
311 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19696
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:
19696
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:
19696
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\ | |
20171
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19696
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:
19696
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) | |
343 { | |
344 print_usage (); | |
345 return retval; | |
346 } | |
347 | |
20699
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20680
diff
changeset
|
348 std::string url = args(0).xstring_value ("urlwrite: URL must be a string"); |
6043 | 349 |
19403
c2f4f6eb5907
A few more instances of stricter input validation for strings (bug #42651).
Rik <rik@octave.org>
parents:
19402
diff
changeset
|
350 // name to store the file if download is succesful |
20699
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20680
diff
changeset
|
351 std::string filename = args(1).xstring_value ("urlwrite: LOCALFILE must be a string"); |
19403
c2f4f6eb5907
A few more instances of stricter input validation for strings (bug #42651).
Rik <rik@octave.org>
parents:
19402
diff
changeset
|
352 |
6043 | 353 std::string method; |
17554
f0d21e7d4653
avoid Cell arrays in usr_transfer classes
John W. Eaton <jwe@octave.org>
parents:
17553
diff
changeset
|
354 Array<std::string> param; |
6043 | 355 |
356 if (nargin == 4) | |
357 { | |
20699
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20680
diff
changeset
|
358 method = args(2).xstring_value ("urlwrite: METHOD must be a string"); |
6043 | 359 |
19403
c2f4f6eb5907
A few more instances of stricter input validation for strings (bug #42651).
Rik <rik@octave.org>
parents:
19402
diff
changeset
|
360 if (method != "get" && method != "post") |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
361 { |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
362 error ("urlwrite: METHOD must be \"get\" or \"post\""); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
363 return retval; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
364 } |
6043 | 365 |
20699
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20680
diff
changeset
|
366 param = args(3).xcellstr_value ("urlwrite: parameters (PARAM) for get and post requests must be given as a cell array of strings"); |
6043 | 367 |
18677
6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents:
18390
diff
changeset
|
368 if (param.numel () % 2 == 1) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
369 { |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
370 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
|
371 return retval; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
372 } |
6043 | 373 } |
374 | |
8151
3725f819b5b3
urlwrite.cc (Furlwrite): delete files we create if download fails
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
375 // 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
|
376 // 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
|
377 // 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
|
378 |
3725f819b5b3
urlwrite.cc (Furlwrite): delete files we create if download fails
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
379 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
|
380 |
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
|
381 std::ofstream ofile (filename.c_str (), std::ios::out | std::ios::binary); |
6043 | 382 |
6986 | 383 if (! ofile.is_open ()) |
6043 | 384 { |
385 error ("urlwrite: unable to open file"); | |
386 return retval; | |
387 } | |
388 | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9918
diff
changeset
|
389 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
|
390 |
17549
a646665cd574
eliminate unecessary static function in urlwrite.cc
John W. Eaton <jwe@octave.org>
parents:
17548
diff
changeset
|
391 frame.add_fcn (delete_file, filename); |
9880 | 392 |
17596
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17556
diff
changeset
|
393 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
|
394 |
18390
af04b9d9f7ed
allow urlwrite to work again
John W. Eaton <jwe@octave.org>
parents:
18328
diff
changeset
|
395 if (curl.is_valid ()) |
18286
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
396 { |
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
397 curl.http_action (param, method); |
6043 | 398 |
18286
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
399 ofile.close (); |
17553
2d01e20abd85
rework error handling for url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17551
diff
changeset
|
400 |
2d01e20abd85
rework error handling for url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17551
diff
changeset
|
401 if (curl.good ()) |
18286
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
402 frame.discard (); |
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
403 |
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
404 if (nargout > 0) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
405 { |
18286
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
406 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
|
407 { |
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
408 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
|
409 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
|
410 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
|
411 } |
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
412 else |
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
413 { |
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
414 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
|
415 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
|
416 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
|
417 } |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
418 } |
18286
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
419 |
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
420 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
|
421 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
|
422 } |
18286
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
423 else |
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
424 error ("support for url transfers was disabled when Octave was built"); |
6043 | 425 |
426 return retval; | |
427 } | |
428 | |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
429 DEFUN (urlread, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
430 "-*- texinfo -*-\n\ |
10840 | 431 @deftypefn {Loadable Function} {@var{s} =} urlread (@var{url})\n\ |
6043 | 432 @deftypefnx {Loadable Function} {[@var{s}, @var{success}] =} urlread (@var{url})\n\ |
6549 | 433 @deftypefnx {Loadable Function} {[@var{s}, @var{success}, @var{message}] =} urlread (@var{url})\n\ |
6547 | 434 @deftypefnx {Loadable Function} {[@dots{}] =} urlread (@var{url}, @var{method}, @var{param})\n\ |
9880 | 435 Download a remote file specified by its @var{url} and return its content\n\ |
20171
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19696
diff
changeset
|
436 in string @var{s}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19696
diff
changeset
|
437 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19696
diff
changeset
|
438 For example:\n\ |
6043 | 439 \n\ |
440 @example\n\ | |
19159
432ffa35de13
doc: Fix dead link in urlwrite/urlread docstring (bug #43082).
Nir Krakauer < nkrakauer@ccny.cuny.edu>
parents:
18390
diff
changeset
|
441 s = urlread (\"ftp://ftp.octave.org/pub/README\");\n\ |
6043 | 442 @end example\n\ |
443 \n\ | |
444 The variable @var{success} is 1 if the download was successful,\n\ | |
445 otherwise it is 0 in which case @var{message} contains an error\n\ | |
20171
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19696
diff
changeset
|
446 message.\n\ |
6043 | 447 \n\ |
20171
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19696
diff
changeset
|
448 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:
19696
diff
changeset
|
449 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:
19696
diff
changeset
|
450 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19696
diff
changeset
|
451 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:
19696
diff
changeset
|
452 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:
19696
diff
changeset
|
453 example:\n\ |
6043 | 454 \n\ |
455 @example\n\ | |
7031 | 456 s = urlread (\"http://user:password@@example.com/file.txt\");\n\ |
6043 | 457 @end example\n\ |
458 \n\ | |
459 GET and POST requests can be specified by @var{method} and @var{param}.\n\ | |
20171
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19696
diff
changeset
|
460 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:
19696
diff
changeset
|
461 @var{param} is a cell array of parameter and value pairs.\n\ |
10840 | 462 For example:\n\ |
6043 | 463 \n\ |
464 @example\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
465 @group\n\ |
6588 | 466 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
|
467 @{\"query\", \"octave\"@});\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
468 @end group\n\ |
6043 | 469 @end example\n\ |
470 @seealso{urlwrite}\n\ | |
471 @end deftypefn") | |
472 { | |
6588 | 473 // Octave's return value |
6043 | 474 octave_value_list retval; |
475 | |
476 int nargin = args.length (); | |
477 | |
478 // verify arguments | |
19402
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19219
diff
changeset
|
479 if (nargin != 1 && nargin != 3) |
6043 | 480 { |
481 print_usage (); | |
482 return retval; | |
483 } | |
484 | |
20699
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20680
diff
changeset
|
485 std::string url = args(0).xstring_value ("urlread: URL must be a string"); |
19403
c2f4f6eb5907
A few more instances of stricter input validation for strings (bug #42651).
Rik <rik@octave.org>
parents:
19402
diff
changeset
|
486 |
6043 | 487 std::string method; |
17554
f0d21e7d4653
avoid Cell arrays in usr_transfer classes
John W. Eaton <jwe@octave.org>
parents:
17553
diff
changeset
|
488 Array<std::string> param; |
6043 | 489 |
490 if (nargin == 3) | |
491 { | |
20699
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20680
diff
changeset
|
492 method = args(1).xstring_value ("urlread: METHOD must be a string"); |
6043 | 493 |
19403
c2f4f6eb5907
A few more instances of stricter input validation for strings (bug #42651).
Rik <rik@octave.org>
parents:
19402
diff
changeset
|
494 if (method != "get" && method != "post") |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
495 { |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
496 error ("urlread: METHOD must be \"get\" or \"post\""); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
497 return retval; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
498 } |
6043 | 499 |
20699
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20680
diff
changeset
|
500 param = args(2).xcellstr_value ("urlread: parameters (PARAM) for get and post requests must be given as a cell array of strings"); |
6043 | 501 |
18677
6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents:
18390
diff
changeset
|
502 if (param.numel () % 2 == 1) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
503 { |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
504 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
|
505 return retval; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
506 } |
6043 | 507 } |
508 | |
6986 | 509 std::ostringstream buf; |
6043 | 510 |
17596
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17556
diff
changeset
|
511 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
|
512 |
18286
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
513 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
|
514 { |
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
515 curl.http_action (param, method); |
6043 | 516 |
18328
b522d04382cf
Return all nargout from urlread if requested (bug #41260).
Rik <rik@octave.org>
parents:
18286
diff
changeset
|
517 if (nargout > 0) |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
518 { |
18328
b522d04382cf
Return all nargout from urlread if requested (bug #41260).
Rik <rik@octave.org>
parents:
18286
diff
changeset
|
519 // Return empty string if no error occured. |
b522d04382cf
Return all nargout from urlread if requested (bug #41260).
Rik <rik@octave.org>
parents:
18286
diff
changeset
|
520 retval(2) = curl.good () ? "" : curl.lasterror (); |
b522d04382cf
Return all nargout from urlread if requested (bug #41260).
Rik <rik@octave.org>
parents:
18286
diff
changeset
|
521 retval(1) = curl.good (); |
b522d04382cf
Return all nargout from urlread if requested (bug #41260).
Rik <rik@octave.org>
parents:
18286
diff
changeset
|
522 retval(0) = buf.str (); |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
523 } |
18286
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
524 |
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
525 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
|
526 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
|
527 } |
18286
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
528 else |
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
529 error ("support for url transfers was disabled when Octave was built"); |
6043 | 530 |
531 return retval; | |
532 } | |
9880 | 533 |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
534 DEFUN (__ftp__, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
535 "-*- texinfo -*-\n\ |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
536 @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
|
537 @deftypefnx {Loadable Function} {@var{handle} =} __ftp__ (@var{host}, @var{username}, @var{password})\n\ |
9880 | 538 Undocumented internal function\n\ |
539 @end deftypefn") | |
540 { | |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
541 octave_value retval; |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
542 |
9880 | 543 int nargin = args.length (); |
544 std::string host; | |
545 std::string user = "anonymous"; | |
546 std::string passwd = ""; | |
547 | |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
548 if (nargin < 1 || nargin > 3) |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
549 { |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
550 print_usage (); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
551 return retval; |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
552 } |
9880 | 553 else |
554 { | |
20699
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20680
diff
changeset
|
555 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
|
556 |
9880 | 557 if (nargin > 1) |
20699
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20680
diff
changeset
|
558 user = args(1).xstring_value ("__ftp__: USER must be a string"); |
9880 | 559 |
560 if (nargin > 2) | |
20699
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20680
diff
changeset
|
561 passwd = args(2).xstring_value ("__ftp__: PASSWD must be a string"); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
562 |
20559
56fee8f84fe7
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20427
diff
changeset
|
563 curl_handle ch |
56fee8f84fe7
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20427
diff
changeset
|
564 = 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
|
565 |
20559
56fee8f84fe7
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20427
diff
changeset
|
566 retval = ch.value (); |
9880 | 567 } |
568 | |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
569 return retval; |
9880 | 570 } |
571 | |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
572 DEFUN (__ftp_pwd__, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
573 "-*- texinfo -*-\n\ |
9880 | 574 @deftypefn {Loadable Function} {} __ftp_pwd__ (@var{handle})\n\ |
575 Undocumented internal function\n\ | |
576 @end deftypefn") | |
577 { | |
578 octave_value retval; | |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
579 |
9880 | 580 int nargin = args.length (); |
581 | |
582 if (nargin != 1) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
583 error ("__ftp_pwd__: incorrect number of arguments"); |
9880 | 584 else |
585 { | |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
586 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
|
587 |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
588 if (curl.is_valid ()) |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
589 retval = curl.pwd (); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
590 else |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
591 error ("__ftp_pwd__: invalid ftp handle"); |
9880 | 592 } |
593 | |
594 return retval; | |
595 } | |
596 | |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
597 DEFUN (__ftp_cwd__, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
598 "-*- texinfo -*-\n\ |
9880 | 599 @deftypefn {Loadable Function} {} __ftp_cwd__ (@var{handle}, @var{path})\n\ |
600 Undocumented internal function\n\ | |
601 @end deftypefn") | |
602 { | |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
603 octave_value retval; |
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
604 |
9880 | 605 int nargin = args.length (); |
606 | |
607 if (nargin != 1 && nargin != 2) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
608 error ("__ftp_cwd__: incorrect number of arguments"); |
9880 | 609 else |
610 { | |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
611 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
|
612 |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
613 if (curl.is_valid ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
614 { |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
615 std::string path = ""; |
9880 | 616 |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
617 if (nargin > 1) |
20699
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20680
diff
changeset
|
618 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
|
619 |
20678
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
620 curl.cwd (path); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
621 } |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
622 else |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
623 error ("__ftp_cwd__: invalid ftp handle"); |
9880 | 624 } |
625 | |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
626 return retval; |
9880 | 627 } |
628 | |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
629 DEFUN (__ftp_dir__, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
630 "-*- texinfo -*-\n\ |
9880 | 631 @deftypefn {Loadable Function} {} __ftp_dir__ (@var{handle})\n\ |
632 Undocumented internal function\n\ | |
633 @end deftypefn") | |
634 { | |
635 octave_value retval; | |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
636 |
9880 | 637 int nargin = args.length (); |
638 | |
639 if (nargin != 1) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
640 error ("__ftp_dir__: incorrect number of arguments"); |
9880 | 641 else |
642 { | |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
643 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
|
644 |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
645 if (curl.is_valid ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
646 { |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
647 if (nargout == 0) |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
648 curl.dir (); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
649 else |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
650 { |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
651 string_vector sv = curl.list (); |
20231
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20180
diff
changeset
|
652 octave_idx_type n = sv.numel (); |
9880 | 653 |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
654 if (n == 0) |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
655 { |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
656 string_vector flds (5); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
657 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
658 flds(0) = "name"; |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
659 flds(1) = "date"; |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
660 flds(2) = "bytes"; |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
661 flds(3) = "isdir"; |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
662 flds(4) = "datenum"; |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
663 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
664 retval = octave_map (flds); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
665 } |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
666 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
667 { |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
668 octave_map st; |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
669 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
670 Cell filectime (dim_vector (n, 1)); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
671 Cell filesize (dim_vector (n, 1)); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
672 Cell fileisdir (dim_vector (n, 1)); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
673 Cell filedatenum (dim_vector (n, 1)); |
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 ("name", Cell (sv)); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
676 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
677 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
|
678 { |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
679 time_t ftime; |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
680 bool fisdir; |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
681 double fsize; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
682 |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
683 curl.get_fileinfo (sv(i), fsize, ftime, fisdir); |
9880 | 684 |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
685 fileisdir (i) = fisdir; |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
686 filectime (i) = ctime (&ftime); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
687 filesize (i) = fsize; |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
688 filedatenum (i) = double (ftime); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
689 } |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
690 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
691 st.assign ("date", filectime); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
692 st.assign ("bytes", filesize); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
693 st.assign ("isdir", fileisdir); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
694 st.assign ("datenum", filedatenum); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
695 |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
696 retval = st; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
697 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
698 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
699 } |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
700 else |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
701 error ("__ftp_dir__: invalid ftp handle"); |
9880 | 702 } |
703 | |
704 return retval; | |
705 } | |
706 | |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
707 DEFUN (__ftp_ascii__, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
708 "-*- texinfo -*-\n\ |
9880 | 709 @deftypefn {Loadable Function} {} __ftp_ascii__ (@var{handle})\n\ |
710 Undocumented internal function\n\ | |
711 @end deftypefn") | |
712 { | |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
713 octave_value retval; |
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
714 |
9880 | 715 int nargin = args.length (); |
716 | |
717 if (nargin != 1) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
718 error ("__ftp_ascii__: incorrect number of arguments"); |
9880 | 719 else |
720 { | |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
721 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
|
722 |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
723 if (curl.is_valid ()) |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
724 curl.ascii (); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
725 else |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
726 error ("__ftp_ascii__: invalid ftp handle"); |
9880 | 727 } |
728 | |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
729 return retval; |
9880 | 730 } |
731 | |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
732 DEFUN (__ftp_binary__, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
733 "-*- texinfo -*-\n\ |
9880 | 734 @deftypefn {Loadable Function} {} __ftp_binary__ (@var{handle})\n\ |
735 Undocumented internal function\n\ | |
736 @end deftypefn") | |
737 { | |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
738 octave_value retval; |
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
739 |
9880 | 740 int nargin = args.length (); |
741 | |
742 if (nargin != 1) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
743 error ("__ftp_binary__: incorrect number of arguments"); |
9880 | 744 else |
745 { | |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
746 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
|
747 |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
748 if (curl.is_valid ()) |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
749 curl.binary (); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
750 else |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
751 error ("__ftp_binary__: invalid ftp handle"); |
9880 | 752 } |
753 | |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
754 return retval; |
9880 | 755 } |
756 | |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
757 DEFUN (__ftp_close__, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
758 "-*- texinfo -*-\n\ |
9880 | 759 @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
|
760 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
|
761 @end deftypefn") |
accafe1aee7c
Make use of gripe_disabled_feature() instead of custom error message.
Carnë Draug <carandraug@octave.org>
parents:
15326
diff
changeset
|
762 { |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
763 octave_value retval; |
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
764 |
17318
accafe1aee7c
Make use of gripe_disabled_feature() instead of custom error message.
Carnë Draug <carandraug@octave.org>
parents:
15326
diff
changeset
|
765 int nargin = args.length (); |
9880 | 766 |
17318
accafe1aee7c
Make use of gripe_disabled_feature() instead of custom error message.
Carnë Draug <carandraug@octave.org>
parents:
15326
diff
changeset
|
767 if (nargin != 1) |
accafe1aee7c
Make use of gripe_disabled_feature() instead of custom error message.
Carnë Draug <carandraug@octave.org>
parents:
15326
diff
changeset
|
768 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
|
769 else |
accafe1aee7c
Make use of gripe_disabled_feature() instead of custom error message.
Carnë Draug <carandraug@octave.org>
parents:
15326
diff
changeset
|
770 { |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
771 curl_handle h = ch_manager::lookup (args(0)); |
9880 | 772 |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
773 if (h.ok ()) |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
774 ch_manager::free (h); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
775 else |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
776 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
|
777 } |
9880 | 778 |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
779 return retval; |
17318
accafe1aee7c
Make use of gripe_disabled_feature() instead of custom error message.
Carnë Draug <carandraug@octave.org>
parents:
15326
diff
changeset
|
780 } |
9880 | 781 |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
782 DEFUN (__ftp_mode__, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
783 "-*- texinfo -*-\n\ |
9880 | 784 @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
|
785 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
|
786 @end deftypefn") |
accafe1aee7c
Make use of gripe_disabled_feature() instead of custom error message.
Carnë Draug <carandraug@octave.org>
parents:
15326
diff
changeset
|
787 { |
accafe1aee7c
Make use of gripe_disabled_feature() instead of custom error message.
Carnë Draug <carandraug@octave.org>
parents:
15326
diff
changeset
|
788 octave_value retval; |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
789 |
17318
accafe1aee7c
Make use of gripe_disabled_feature() instead of custom error message.
Carnë Draug <carandraug@octave.org>
parents:
15326
diff
changeset
|
790 int nargin = args.length (); |
9880 | 791 |
17318
accafe1aee7c
Make use of gripe_disabled_feature() instead of custom error message.
Carnë Draug <carandraug@octave.org>
parents:
15326
diff
changeset
|
792 if (nargin != 1) |
accafe1aee7c
Make use of gripe_disabled_feature() instead of custom error message.
Carnë Draug <carandraug@octave.org>
parents:
15326
diff
changeset
|
793 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
|
794 else |
accafe1aee7c
Make use of gripe_disabled_feature() instead of custom error message.
Carnë Draug <carandraug@octave.org>
parents:
15326
diff
changeset
|
795 { |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
796 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
|
797 |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
798 if (curl.is_valid ()) |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
799 retval = (curl.is_ascii () ? "ascii" : "binary"); |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
800 else |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
801 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
|
802 } |
9880 | 803 |
17318
accafe1aee7c
Make use of gripe_disabled_feature() instead of custom error message.
Carnë Draug <carandraug@octave.org>
parents:
15326
diff
changeset
|
804 return retval; |
accafe1aee7c
Make use of gripe_disabled_feature() instead of custom error message.
Carnë Draug <carandraug@octave.org>
parents:
15326
diff
changeset
|
805 } |
9880 | 806 |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
807 DEFUN (__ftp_delete__, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
808 "-*- texinfo -*-\n\ |
9880 | 809 @deftypefn {Loadable Function} {} __ftp_delete__ (@var{handle}, @var{path})\n\ |
810 Undocumented internal function\n\ | |
811 @end deftypefn") | |
812 { | |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
813 octave_value retval; |
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
814 |
9880 | 815 int nargin = args.length (); |
816 | |
817 if (nargin != 2) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
818 error ("__ftp_delete__: incorrect number of arguments"); |
9880 | 819 else |
820 { | |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
821 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
|
822 |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
823 if (curl.is_valid ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
824 { |
20699
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20680
diff
changeset
|
825 std::string file = args(1).xstring_value ("__ftp_delete__: FILE must be a string"); |
9880 | 826 |
20678
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
827 curl.del (file); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
828 } |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
829 else |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
830 error ("__ftp_delete__: invalid ftp handle"); |
9880 | 831 } |
832 | |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
833 return retval; |
9880 | 834 } |
835 | |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
836 DEFUN (__ftp_rmdir__, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
837 "-*- texinfo -*-\n\ |
9880 | 838 @deftypefn {Loadable Function} {} __ftp_rmdir__ (@var{handle}, @var{path})\n\ |
839 Undocumented internal function\n\ | |
840 @end deftypefn") | |
841 { | |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
842 octave_value retval; |
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
843 |
9880 | 844 int nargin = args.length (); |
845 | |
846 if (nargin != 2) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
847 error ("__ftp_rmdir__: incorrect number of arguments"); |
9880 | 848 else |
849 { | |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
850 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
|
851 |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
852 if (curl.is_valid ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
853 { |
20699
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20680
diff
changeset
|
854 std::string dir = args(1).xstring_value ("__ftp_rmdir__: DIR must be a string"); |
9880 | 855 |
20678
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
856 curl.rmdir (dir); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
857 } |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
858 else |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
859 error ("__ftp_rmdir__: invalid ftp handle"); |
9880 | 860 } |
861 | |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
862 return retval; |
9880 | 863 } |
864 | |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
865 DEFUN (__ftp_mkdir__, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
866 "-*- texinfo -*-\n\ |
9880 | 867 @deftypefn {Loadable Function} {} __ftp_mkdir__ (@var{handle}, @var{path})\n\ |
868 Undocumented internal function\n\ | |
869 @end deftypefn") | |
870 { | |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
871 octave_value retval; |
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
872 |
9880 | 873 int nargin = args.length (); |
874 | |
875 if (nargin != 2) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
876 error ("__ftp_mkdir__: incorrect number of arguments"); |
9880 | 877 else |
878 { | |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
879 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
|
880 |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
881 if (curl.is_valid ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
882 { |
20699
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20680
diff
changeset
|
883 std::string dir = args(1).xstring_value ("__ftp_mkdir__: DIR must be a string"); |
9880 | 884 |
20678
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
885 curl.mkdir (dir); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
886 } |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
887 else |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
888 error ("__ftp_mkdir__: invalid ftp handle"); |
9880 | 889 } |
890 | |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
891 return retval; |
9880 | 892 } |
893 | |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
894 DEFUN (__ftp_rename__, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
895 "-*- texinfo -*-\n\ |
9880 | 896 @deftypefn {Loadable Function} {} __ftp_rename__ (@var{handle}, @var{path})\n\ |
897 Undocumented internal function\n\ | |
898 @end deftypefn") | |
899 { | |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
900 octave_value retval; |
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
901 |
9880 | 902 int nargin = args.length (); |
903 | |
904 if (nargin != 3) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
905 error ("__ftp_rename__: incorrect number of arguments"); |
9880 | 906 else |
907 { | |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
908 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
|
909 |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
910 if (curl.is_valid ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
911 { |
20699
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20680
diff
changeset
|
912 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:
20680
diff
changeset
|
913 std::string newname = args(2).xstring_value ("__ftp_rename__: NEWNAME must be a string"); |
9880 | 914 |
20678
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
915 curl.rename (oldname, newname); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
916 } |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
917 else |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
918 error ("__ftp_rename__: invalid ftp handle"); |
9880 | 919 } |
920 | |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
921 return retval; |
9880 | 922 } |
923 | |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
924 DEFUN (__ftp_mput__, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
925 "-*- texinfo -*-\n\ |
9880 | 926 @deftypefn {Loadable Function} {} __ftp_mput__ (@var{handle}, @var{files})\n\ |
927 Undocumented internal function\n\ | |
928 @end deftypefn") | |
929 { | |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
930 octave_value retval; |
9880 | 931 |
932 int nargin = args.length (); | |
933 | |
934 if (nargin != 2) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
935 error ("__ftp_mput__: incorrect number of arguments"); |
9880 | 936 else |
937 { | |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
938 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
|
939 |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
940 if (curl.is_valid ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
941 { |
20699
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20680
diff
changeset
|
942 std::string pat = args(1).xstring_value ("__ftp_mput__: PATTERN must be a string"); |
9880 | 943 |
20678
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
944 string_vector file_list; |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
945 |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
946 glob_match pattern (file_ops::tilde_expand (pat)); |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
947 string_vector files = pattern.glob (); |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
948 |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
949 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
|
950 { |
20678
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
951 std::string file = files (i); |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
952 |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
953 file_stat fs (file); |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
954 |
20678
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
955 if (! fs.exists ()) |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
956 { |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
957 error ("__ftp__mput: file does not exist"); |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
958 break; |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
959 } |
9880 | 960 |
20678
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
961 if (fs.is_dir ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
962 { |
20678
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
963 file_list.append (curl.mput_directory ("", file)); |
9880 | 964 |
20678
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
965 if (! curl.good ()) |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
966 { |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
967 error ("__ftp_mput__: %s", curl.lasterror().c_str()); |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
968 break; |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
969 } |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
970 } |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
971 else |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
972 { |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
973 // FIXME: Does ascii mode need to be flagged here? |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
974 std::ifstream ifile (file.c_str (), std::ios::in | |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
975 std::ios::binary); |
9880 | 976 |
20678
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
977 if (! ifile.is_open ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
978 { |
20678
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
979 error ("__ftp_mput__: unable to open file"); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
980 break; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
981 } |
9880 | 982 |
20678
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
983 curl.put (file, ifile); |
17553
2d01e20abd85
rework error handling for url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17551
diff
changeset
|
984 |
20678
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
985 ifile.close (); |
9880 | 986 |
20678
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
987 if (! curl.good ()) |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
988 { |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
989 error ("__ftp_mput__: %s", curl.lasterror().c_str()); |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
990 break; |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
991 } |
9880 | 992 |
20678
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
993 file_list.append (file); |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
994 } |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
995 } |
9880 | 996 |
20678
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
997 if (nargout > 0) |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
998 retval = file_list; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
999 } |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
1000 else |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
1001 error ("__ftp_mput__: invalid ftp handle"); |
9880 | 1002 } |
1003 | |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
1004 return retval; |
9880 | 1005 } |
1006 | |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
1007 DEFUN (__ftp_mget__, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1008 "-*- texinfo -*-\n\ |
20576
7374a3a6d594
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20559
diff
changeset
|
1009 @deftypefn {Loadable Function} {} __ftp_mget__ (@var{handle}, @var{pattern})\n\ |
7374a3a6d594
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20559
diff
changeset
|
1010 @deftypefnx {Loadable Function} {} __ftp_mget__ (@var{handle}, @var{pattern}, @var{target})\n\ |
9880 | 1011 Undocumented internal function\n\ |
1012 @end deftypefn") | |
1013 { | |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
1014 octave_value retval; |
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
1015 |
9880 | 1016 int nargin = args.length (); |
1017 | |
1018 if (nargin != 2 && nargin != 3) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
1019 error ("__ftp_mget__: incorrect number of arguments"); |
9880 | 1020 else |
1021 { | |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
1022 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
|
1023 |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
1024 if (curl.is_valid ()) |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
1025 { |
20699
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20680
diff
changeset
|
1026 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
|
1027 std::string target; |
9880 | 1028 |
20709
73800f39da6f
@ftp/mget: honor the TARGET argument
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
20699
diff
changeset
|
1029 if (nargin == 3 && ! args(2).is_empty ()) |
20699
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20680
diff
changeset
|
1030 target = args(2).xstring_value ("__ftp_mget__: TARGET must be a string") + file_ops::dir_sep_str (); |
9880 | 1031 |
20678
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
1032 string_vector sv = curl.list (); |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
1033 octave_idx_type n = 0; |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
1034 glob_match pattern (file); |
9880 | 1035 |
17553
2d01e20abd85
rework error handling for url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17551
diff
changeset
|
1036 |
20678
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
1037 for (octave_idx_type i = 0; i < sv.numel (); i++) |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
1038 { |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
1039 if (pattern.match (sv(i))) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1040 { |
20678
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
1041 n++; |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
1042 |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
1043 time_t ftime; |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
1044 bool fisdir; |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
1045 double fsize; |
9880 | 1046 |
20678
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
1047 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
|
1048 |
20678
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
1049 if (fisdir) |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
1050 curl.mget_directory (sv(i), target); |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
1051 else |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
1052 { |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
1053 std::ofstream ofile ((target + sv(i)).c_str (), |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
1054 std::ios::out | |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
1055 std::ios::binary); |
9880 | 1056 |
20678
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
1057 if (! ofile.is_open ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1058 { |
20678
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
1059 error ("__ftp_mget__: unable to open file"); |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
1060 break; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1061 } |
9880 | 1062 |
20678
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
1063 unwind_protect_safe frame; |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
1064 |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
1065 frame.add_fcn (delete_file, target + sv(i)); |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
1066 |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
1067 curl.get (sv(i), ofile); |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
1068 |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
1069 ofile.close (); |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
1070 |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
1071 if (curl.good ()) |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
1072 frame.discard (); |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
1073 } |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
1074 |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
1075 if (! curl.good ()) |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
1076 { |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
1077 error ("__ftp_mget__: %s", curl.lasterror().c_str()); |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
1078 break; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1079 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1080 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1081 } |
20678
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
1082 |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
1083 if (n == 0) |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20576
diff
changeset
|
1084 error ("__ftp_mget__: file not found"); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1085 } |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
1086 else |
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
1087 error ("__ftp_mget__: invalid ftp handle"); |
9880 | 1088 } |
1089 | |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
1090 return retval; |
9880 | 1091 } |