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