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