Mercurial > octave
annotate libinterp/corefcn/urlwrite.cc @ 25438:cb1606f78f6b
prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
Using <iostream> brings with it a static initializer for the std::cin,
std::cout, and std::cerr streams. In most cases they are not needed
and should be avoided if possible.
Files affected:
build-aux/mk-opts.pl
libgui/qterminal/libqterminal/win32/QWinTerminalImpl.cpp
libinterp/corefcn/__dsearchn__.cc
libinterp/corefcn/c-file-ptr-stream.cc
libinterp/corefcn/c-file-ptr-stream.h
libinterp/corefcn/daspk.cc
libinterp/corefcn/dasrt.cc
libinterp/corefcn/dassl.cc
libinterp/corefcn/defaults.cc
libinterp/corefcn/defun.cc
libinterp/corefcn/file-io.cc
libinterp/corefcn/ft-text-renderer.cc
libinterp/corefcn/gl-render.cc
libinterp/corefcn/help.cc
libinterp/corefcn/ls-ascii-helper.cc
libinterp/corefcn/ls-hdf5.cc
libinterp/corefcn/ls-hdf5.h
libinterp/corefcn/ls-mat-ascii.cc
libinterp/corefcn/ls-mat4.cc
libinterp/corefcn/ls-mat5.cc
libinterp/corefcn/ls-oct-binary.cc
libinterp/corefcn/ls-oct-text.cc
libinterp/corefcn/lsode.cc
libinterp/corefcn/oct-iostrm.cc
libinterp/corefcn/oct-procbuf.cc
libinterp/corefcn/oct-stdstrm.h
libinterp/corefcn/procstream.cc
libinterp/corefcn/procstream.h
libinterp/corefcn/quad.cc
libinterp/corefcn/symscope.h
libinterp/corefcn/symtab.h
libinterp/corefcn/toplev.cc
libinterp/corefcn/urlwrite.cc
libinterp/corefcn/utils.cc
libinterp/corefcn/zfstream.cc
libinterp/dldfcn/__ode15__.cc
libinterp/dldfcn/convhulln.cc
libinterp/octave-value/ov-base-diag.cc
libinterp/octave-value/ov-base-int.cc
libinterp/octave-value/ov-base-mat.cc
libinterp/octave-value/ov-base-scalar.cc
libinterp/octave-value/ov-base-sparse.cc
libinterp/octave-value/ov-base.cc
libinterp/octave-value/ov-bool-mat.cc
libinterp/octave-value/ov-bool-sparse.cc
libinterp/octave-value/ov-bool.cc
libinterp/octave-value/ov-cell.cc
libinterp/octave-value/ov-ch-mat.cc
libinterp/octave-value/ov-class.cc
libinterp/octave-value/ov-colon.cc
libinterp/octave-value/ov-complex.cc
libinterp/octave-value/ov-cs-list.cc
libinterp/octave-value/ov-cx-mat.cc
libinterp/octave-value/ov-cx-sparse.cc
libinterp/octave-value/ov-fcn-handle.cc
libinterp/octave-value/ov-fcn-inline.cc
libinterp/octave-value/ov-float.cc
libinterp/octave-value/ov-flt-complex.cc
libinterp/octave-value/ov-flt-cx-mat.cc
libinterp/octave-value/ov-flt-re-mat.cc
libinterp/octave-value/ov-int16.cc
libinterp/octave-value/ov-int32.cc
libinterp/octave-value/ov-int64.cc
libinterp/octave-value/ov-int8.cc
libinterp/octave-value/ov-java.cc
libinterp/octave-value/ov-range.cc
libinterp/octave-value/ov-re-mat.cc
libinterp/octave-value/ov-re-sparse.cc
libinterp/octave-value/ov-scalar.cc
libinterp/octave-value/ov-str-mat.cc
libinterp/octave-value/ov-struct.cc
libinterp/octave-value/ov-typeinfo.cc
libinterp/octave-value/ov-uint16.cc
libinterp/octave-value/ov-uint32.cc
libinterp/octave-value/ov-uint64.cc
libinterp/octave-value/ov-uint8.cc
libinterp/octave.cc
libinterp/parse-tree/bp-table.cc
libinterp/parse-tree/lex.h
libinterp/parse-tree/profiler.cc
libinterp/parse-tree/pt-arg-list.cc
libinterp/parse-tree/pt-array-list.cc
libinterp/parse-tree/pt-assign.cc
libinterp/parse-tree/pt-cell.cc
libinterp/parse-tree/pt-const.cc
libinterp/parse-tree/pt-eval.cc
libinterp/parse-tree/pt-exp.cc
libinterp/parse-tree/pt-fcn-handle.cc
libinterp/parse-tree/pt-jit.cc
libinterp/parse-tree/pt-pr-code.cc
libinterp/parse-tree/pt-tm-const.cc
libinterp/parse-tree/pt.cc
liboctave/array/Array.cc
liboctave/array/CColVector.cc
liboctave/array/CDiagMatrix.cc
liboctave/array/CMatrix.cc
liboctave/array/CNDArray.cc
liboctave/array/CRowVector.cc
liboctave/array/CSparse.cc
liboctave/array/DiagArray2.cc
liboctave/array/MArray.cc
liboctave/array/Range.cc
liboctave/array/Sparse.cc
liboctave/array/boolMatrix.cc
liboctave/array/boolSparse.cc
liboctave/array/chMatrix.cc
liboctave/array/dColVector.cc
liboctave/array/dDiagMatrix.cc
liboctave/array/dMatrix.cc
liboctave/array/dNDArray.cc
liboctave/array/dRowVector.cc
liboctave/array/dSparse.cc
liboctave/array/fCColVector.cc
liboctave/array/fCDiagMatrix.cc
liboctave/array/fCMatrix.cc
liboctave/array/fCNDArray.cc
liboctave/array/fCRowVector.cc
liboctave/array/fColVector.cc
liboctave/array/fDiagMatrix.cc
liboctave/array/fMatrix.cc
liboctave/array/fNDArray.cc
liboctave/array/fRowVector.cc
liboctave/array/idx-vector.cc
liboctave/numeric/CollocWt.cc
liboctave/numeric/eigs-base.cc
liboctave/system/file-ops.cc
liboctave/system/oct-time.cc
liboctave/util/cmd-hist.cc
liboctave/util/data-conv.cc
liboctave/util/data-conv.h
liboctave/util/file-info.cc
liboctave/util/lo-utils.cc
liboctave/util/lo-utils.h
liboctave/util/quit.cc
liboctave/util/str-vec.cc
liboctave/util/url-transfer.cc
liboctave/util/url-transfer.h
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 07 Jun 2018 10:11:54 -0400 |
parents | 6652d3823428 |
children | d6050ba12c0c |
rev | line source |
---|---|
6043 | 1 /* |
2 | |
25054
6652d3823428
maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
3 Copyright (C) 2006-2018 Alexander Barth |
9880 | 4 Copyright (C) 2009 David Bateman |
6043 | 5 |
6 This file is part of Octave. | |
7 | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23829
diff
changeset
|
8 Octave is free software: you can redistribute it and/or modify it |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
9 under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23829
diff
changeset
|
10 the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
11 (at your option) any later version. |
6043 | 12 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
13 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
14 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
16 GNU General Public License for more details. |
6043 | 17 |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23829
diff
changeset
|
20 <https://www.gnu.org/licenses/>. |
6043 | 21 |
22 */ | |
23 | |
24 // Author: Alexander Barth <abarth@marine.usf.edu> | |
25 // Adapted-By: jwe | |
26 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21547
diff
changeset
|
27 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
28 # include "config.h" |
6043 | 29 #endif |
30 | |
31 #include <string> | |
32 #include <fstream> | |
33 #include <iomanip> | |
34 | |
9880 | 35 #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
|
36 #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
|
37 #include "file-stat.h" |
6043 | 38 #include "oct-env.h" |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
39 #include "oct-handle.h" |
9880 | 40 #include "glob-match.h" |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
41 #include "url-transfer.h" |
6043 | 42 |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
43 #include "defun.h" |
6043 | 44 #include "error.h" |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
45 #include "interpreter.h" |
9880 | 46 #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
|
47 #include "oct-refcount.h" |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
48 #include "ov-cell.h" |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
49 #include "ovl.h" |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
50 #include "pager.h" |
8151
3725f819b5b3
urlwrite.cc (Furlwrite): delete files we create if download fails
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
51 #include "unwind-prot.h" |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
52 #include "url-handle-manager.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 { |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
57 octave::sys::unlink (file); |
17550
77127a3badaa
move curl_object actions to rep class
John W. Eaton <jwe@octave.org>
parents:
17549
diff
changeset
|
58 } |
6043 | 59 |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
60 DEFUN (urlwrite, args, nargout, |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
61 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
62 @deftypefn {} {} urlwrite (@var{url}, @var{localfile}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
63 @deftypefnx {} {@var{f} =} urlwrite (@var{url}, @var{localfile}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
64 @deftypefnx {} {[@var{f}, @var{success}] =} urlwrite (@var{url}, @var{localfile}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
65 @deftypefnx {} {[@var{f}, @var{success}, @var{message}] =} urlwrite (@var{url}, @var{localfile}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
66 Download a remote file specified by its @var{url} and save it as |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
67 @var{localfile}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
68 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
69 For example: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
70 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
71 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
72 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
73 urlwrite ("ftp://ftp.octave.org/pub/README", |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
74 "README.txt"); |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
75 @end group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
76 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
77 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
78 The full path of the downloaded file is returned in @var{f}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
79 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
80 The variable @var{success} is 1 if the download was successful, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
81 otherwise it is 0 in which case @var{message} contains an error message. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
82 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
83 If no output argument is specified and an error occurs, then the error is |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
84 signaled through Octave's error handling mechanism. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
85 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
86 This function uses libcurl. Curl supports, among others, the HTTP, FTP, and |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
87 FILE protocols. Username and password may be specified in the URL, for |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
88 example: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
89 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
90 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
91 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
92 urlwrite ("http://username:password@@example.com/file.txt", |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
93 "file.txt"); |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
94 @end group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
95 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
96 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
97 GET and POST requests can be specified by @var{method} and @var{param}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
98 The parameter @var{method} is either @samp{get} or @samp{post} and |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
99 @var{param} is a cell array of parameter and value pairs. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
100 For example: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
101 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
102 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
103 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
104 urlwrite ("http://www.google.com/search", "search.html", |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
105 "get", @{"query", "octave"@}); |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
106 @end group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
107 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
108 @seealso{urlread} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
109 @end deftypefn */) |
6043 | 110 { |
111 int nargin = args.length (); | |
112 | |
113 // verify arguments | |
114 if (nargin != 2 && nargin != 4) | |
20799
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20726
diff
changeset
|
115 print_usage (); |
6043 | 116 |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
117 std::string url = args(0).xstring_value ("urlwrite: URL must be a string"); |
6043 | 118 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
119 // name to store the file if download is successful |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
120 std::string filename = args(1).xstring_value ("urlwrite: LOCALFILE must be a string"); |
19404
c2f4f6eb5907
A few more instances of stricter input validation for strings (bug #42651).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
121 |
6043 | 122 std::string method; |
17554
f0d21e7d4653
avoid Cell arrays in usr_transfer classes
John W. Eaton <jwe@octave.org>
parents:
17553
diff
changeset
|
123 Array<std::string> param; |
6043 | 124 |
125 if (nargin == 4) | |
126 { | |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
127 method = args(2).xstring_value ("urlwrite: METHOD must be a string"); |
6043 | 128 |
19404
c2f4f6eb5907
A few more instances of stricter input validation for strings (bug #42651).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
129 if (method != "get" && method != "post") |
23803
90689bdbe048
Use C++11 raw string literals to avoid escaping double quotes.
Rik <rik@octave.org>
parents:
23742
diff
changeset
|
130 error (R"(urlwrite: METHOD must be "get" or "post")"); |
6043 | 131 |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
132 param = args(3).xcellstr_value ("urlwrite: parameters (PARAM) for get and post requests must be given as a cell array of strings"); |
6043 | 133 |
18678
6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents:
18391
diff
changeset
|
134 if (param.numel () % 2 == 1) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20819
diff
changeset
|
135 error ("urlwrite: number of elements in PARAM must be even"); |
6043 | 136 } |
137 | |
8151
3725f819b5b3
urlwrite.cc (Furlwrite): delete files we create if download fails
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
138 // 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
|
139 // 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
|
140 // 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
|
141 |
21736
0504351a45e6
use namespace for file_stat classes
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
142 octave::sys::file_stat fs (filename); |
8151
3725f819b5b3
urlwrite.cc (Furlwrite): delete files we create if download fails
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
143 |
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
|
144 std::ofstream ofile (filename.c_str (), std::ios::out | std::ios::binary); |
6043 | 145 |
6986 | 146 if (! ofile.is_open ()) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20819
diff
changeset
|
147 error ("urlwrite: unable to open file"); |
6043 | 148 |
21743
f4d7d0eb5b0c
use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
149 octave::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
|
150 |
17549
a646665cd574
eliminate unecessary static function in urlwrite.cc
John W. Eaton <jwe@octave.org>
parents:
17548
diff
changeset
|
151 frame.add_fcn (delete_file, filename); |
9880 | 152 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
153 octave::url_transfer url_xfer (url, ofile); |
17596
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17556
diff
changeset
|
154 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
155 octave_value_list retval; |
6043 | 156 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
157 if (! url_xfer.is_valid ()) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
158 error ("support for URL transfers was disabled when Octave was built"); |
17553
2d01e20abd85
rework error handling for url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17551
diff
changeset
|
159 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
160 url_xfer.http_action (param, method); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
161 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
162 ofile.close (); |
18287
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
163 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
164 if (url_xfer.good ()) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
165 frame.discard (); |
18287
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
166 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
167 if (nargout > 0) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
168 { |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
169 if (url_xfer.good ()) |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
170 retval = ovl (octave::sys::env::make_absolute (filename), true, ""); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
171 else |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
172 retval = ovl ("", false, url_xfer.lasterror ()); |
17553
2d01e20abd85
rework error handling for url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17551
diff
changeset
|
173 } |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
174 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
175 if (nargout < 2 && ! url_xfer.good ()) |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
176 error ("urlwrite: %s", url_xfer.lasterror ().c_str ()); |
6043 | 177 |
178 return retval; | |
179 } | |
180 | |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
17554
diff
changeset
|
181 DEFUN (urlread, args, nargout, |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
182 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
183 @deftypefn {} {@var{s} =} urlread (@var{url}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
184 @deftypefnx {} {[@var{s}, @var{success}] =} urlread (@var{url}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
185 @deftypefnx {} {[@var{s}, @var{success}, @var{message}] =} urlread (@var{url}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
186 @deftypefnx {} {[@dots{}] =} urlread (@var{url}, @var{method}, @var{param}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
187 Download a remote file specified by its @var{url} and return its content |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
188 in string @var{s}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
189 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
190 For example: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
191 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
192 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
193 s = urlread ("ftp://ftp.octave.org/pub/README"); |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
194 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
195 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
196 The variable @var{success} is 1 if the download was successful, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
197 otherwise it is 0 in which case @var{message} contains an error |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
198 message. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
199 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
200 If no output argument is specified and an error occurs, then the error is |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
201 signaled through Octave's error handling mechanism. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
202 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
203 This function uses libcurl. Curl supports, among others, the HTTP, FTP, and |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
204 FILE protocols. Username and password may be specified in the URL@. For |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
205 example: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
206 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
207 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
208 s = urlread ("http://user:password@@example.com/file.txt"); |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
209 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
210 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
211 GET and POST requests can be specified by @var{method} and @var{param}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
212 The parameter @var{method} is either @samp{get} or @samp{post} and |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
213 @var{param} is a cell array of parameter and value pairs. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
214 For example: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
215 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
216 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
217 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
218 s = urlread ("http://www.google.com/search", "get", |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
219 @{"query", "octave"@}); |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
220 @end group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
221 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
222 @seealso{urlwrite} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
223 @end deftypefn */) |
6043 | 224 { |
225 int nargin = args.length (); | |
226 | |
227 // verify arguments | |
19403
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19220
diff
changeset
|
228 if (nargin != 1 && nargin != 3) |
20799
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20726
diff
changeset
|
229 print_usage (); |
6043 | 230 |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
231 std::string url = args(0).xstring_value ("urlread: URL must be a string"); |
19404
c2f4f6eb5907
A few more instances of stricter input validation for strings (bug #42651).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
232 |
6043 | 233 std::string method; |
17554
f0d21e7d4653
avoid Cell arrays in usr_transfer classes
John W. Eaton <jwe@octave.org>
parents:
17553
diff
changeset
|
234 Array<std::string> param; |
6043 | 235 |
236 if (nargin == 3) | |
237 { | |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
238 method = args(1).xstring_value ("urlread: METHOD must be a string"); |
6043 | 239 |
19404
c2f4f6eb5907
A few more instances of stricter input validation for strings (bug #42651).
Rik <rik@octave.org>
parents:
19403
diff
changeset
|
240 if (method != "get" && method != "post") |
23803
90689bdbe048
Use C++11 raw string literals to avoid escaping double quotes.
Rik <rik@octave.org>
parents:
23742
diff
changeset
|
241 error (R"(urlread: METHOD must be "get" or "post")"); |
6043 | 242 |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
243 param = args(2).xcellstr_value ("urlread: parameters (PARAM) for get and post requests must be given as a cell array of strings"); |
6043 | 244 |
18678
6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents:
18391
diff
changeset
|
245 if (param.numel () % 2 == 1) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20819
diff
changeset
|
246 error ("urlread: number of elements in PARAM must be even"); |
6043 | 247 } |
248 | |
6986 | 249 std::ostringstream buf; |
6043 | 250 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
251 octave::url_transfer url_xfer = octave::url_transfer (url, buf); |
17596
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17556
diff
changeset
|
252 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
253 if (! url_xfer.is_valid ()) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
254 error ("support for URL transfers was disabled when Octave was built"); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
255 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
256 url_xfer.http_action (param, method); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
257 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
258 octave_value_list retval; |
6043 | 259 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
260 if (nargout > 0) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
261 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
262 // Return empty string if no error occurred. |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
263 retval = ovl (buf.str (), url_xfer.good (), |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
264 url_xfer.good () ? "" : url_xfer.lasterror ()); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
265 } |
18287
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
266 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
267 if (nargout < 2 && ! url_xfer.good ()) |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
268 error ("urlread: %s", url_xfer.lasterror ().c_str ()); |
6043 | 269 |
270 return retval; | |
271 } | |
9880 | 272 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
273 DEFMETHOD (__ftp__, interp, args, , |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
274 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
275 @deftypefn {} {@var{handle} =} __ftp__ (@var{host}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
276 @deftypefnx {} {@var{handle} =} __ftp__ (@var{host}, @var{username}, @var{password}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
277 Undocumented internal function |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
278 @end deftypefn */) |
9880 | 279 { |
280 int nargin = args.length (); | |
281 | |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
282 if (nargin < 1 || nargin > 3) |
20799
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20726
diff
changeset
|
283 print_usage (); |
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20726
diff
changeset
|
284 |
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20726
diff
changeset
|
285 std::string host = args(0).xstring_value ("__ftp__: HOST must be a string"); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
286 |
20799
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20726
diff
changeset
|
287 std::string user = (nargin > 1) |
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20726
diff
changeset
|
288 ? args(1).xstring_value ("__ftp__: USER must be a string") |
23829
01899bdd2a3a
Eliminate unnecessary std::string ("...") constructor calls when "..." suffices.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
289 : "anonymous"; |
9880 | 290 |
20799
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20726
diff
changeset
|
291 std::string passwd = (nargin > 2) |
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20726
diff
changeset
|
292 ? args(2).xstring_value ("__ftp__: PASSWD must be a string") |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
21005
diff
changeset
|
293 : ""; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
294 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
295 octave::url_handle_manager& uhm = interp.get_url_handle_manager (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
296 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
297 octave::url_handle uh = uhm.make_url_handle (host, user, passwd, |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
298 octave_stdout); |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
299 |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
300 return ovl (uh.value ()); |
9880 | 301 } |
302 | |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
303 DEFMETHOD (__ftp_pwd__, interp, args, , |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
304 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
305 @deftypefn {} {} __ftp_pwd__ (@var{handle}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
306 Undocumented internal function |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
307 @end deftypefn */) |
9880 | 308 { |
20819
f428cbe7576f
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20799
diff
changeset
|
309 if (args.length () != 1) |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
310 error ("__ftp_pwd__: incorrect number of arguments"); |
9880 | 311 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
312 octave::url_handle_manager& uhm = interp.get_url_handle_manager (); |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
313 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
314 octave::url_transfer url_xfer = uhm.get_object (args(0)); |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
315 |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
316 if (! url_xfer.is_valid ()) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
317 error ("__ftp_pwd__: invalid ftp handle"); |
9880 | 318 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
319 return ovl (url_xfer.pwd ()); |
9880 | 320 } |
321 | |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
322 DEFMETHOD (__ftp_cwd__, interp, args, , |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
323 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
324 @deftypefn {} {} __ftp_cwd__ (@var{handle}, @var{path}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
325 Undocumented internal function |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
326 @end deftypefn */) |
9880 | 327 { |
328 int nargin = args.length (); | |
329 | |
330 if (nargin != 1 && nargin != 2) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
331 error ("__ftp_cwd__: incorrect number of arguments"); |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
332 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
333 std::string path = ""; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
334 if (nargin > 1) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
335 path = args(1).xstring_value ("__ftp_cwd__: PATH must be a string"); |
9880 | 336 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
337 octave::url_handle_manager& uhm = interp.get_url_handle_manager (); |
9880 | 338 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
339 octave::url_transfer url_xfer = uhm.get_object (args(0)); |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
340 |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
341 if (! url_xfer.is_valid ()) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
342 error ("__ftp_cwd__: invalid ftp handle"); |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
343 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
344 url_xfer.cwd (path); |
9880 | 345 |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
346 return ovl (); |
9880 | 347 } |
348 | |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
349 DEFMETHOD (__ftp_dir__, interp, args, nargout, |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
350 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
351 @deftypefn {} {} __ftp_dir__ (@var{handle}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
352 Undocumented internal function |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
353 @end deftypefn */) |
9880 | 354 { |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
355 if (args.length () != 1) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
356 error ("__ftp_dir__: incorrect number of arguments"); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
357 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
358 octave::url_handle_manager& uhm = interp.get_url_handle_manager (); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
359 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
360 octave::url_transfer url_xfer = uhm.get_object (args(0)); |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
361 |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
362 if (! url_xfer.is_valid ()) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
363 error ("__ftp_dir__: invalid ftp handle"); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
364 |
9880 | 365 octave_value retval; |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
366 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
367 if (nargout == 0) |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
368 url_xfer.dir (); |
9880 | 369 else |
370 { | |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
371 string_vector sv = url_xfer.list (); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
372 octave_idx_type n = sv.numel (); |
9880 | 373 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
374 if (n == 0) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
375 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
376 string_vector flds (5); |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
377 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
378 flds(0) = "name"; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
379 flds(1) = "date"; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
380 flds(2) = "bytes"; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
381 flds(3) = "isdir"; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
382 flds(4) = "datenum"; |
9880 | 383 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
384 retval = octave_map (flds); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
385 } |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
386 else |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
387 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
388 octave_map st; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
389 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
390 Cell filectime (dim_vector (n, 1)); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
391 Cell filesize (dim_vector (n, 1)); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
392 Cell fileisdir (dim_vector (n, 1)); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
393 Cell filedatenum (dim_vector (n, 1)); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
394 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
395 st.assign ("name", Cell (sv)); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
396 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
397 for (octave_idx_type i = 0; i < n; i++) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
398 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
399 time_t ftime; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
400 bool fisdir; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
401 double fsize; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
402 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
403 url_xfer.get_fileinfo (sv(i), fsize, ftime, fisdir); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
404 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
405 fileisdir (i) = fisdir; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
406 filectime (i) = ctime (&ftime); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
407 filesize (i) = fsize; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
408 filedatenum (i) = double (ftime); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
409 } |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
410 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
411 st.assign ("date", filectime); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
412 st.assign ("bytes", filesize); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
413 st.assign ("isdir", fileisdir); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
414 st.assign ("datenum", filedatenum); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
415 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
416 retval = st; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
417 } |
9880 | 418 } |
419 | |
420 return retval; | |
421 } | |
422 | |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
423 DEFMETHOD (__ftp_ascii__, interp, args, , |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
424 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
425 @deftypefn {} {} __ftp_ascii__ (@var{handle}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
426 Undocumented internal function |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
427 @end deftypefn */) |
9880 | 428 { |
20819
f428cbe7576f
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20799
diff
changeset
|
429 if (args.length () != 1) |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
430 error ("__ftp_ascii__: incorrect number of arguments"); |
9880 | 431 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
432 octave::url_handle_manager& uhm = interp.get_url_handle_manager (); |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
433 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
434 octave::url_transfer url_xfer = uhm.get_object (args(0)); |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
435 |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
436 if (! url_xfer.is_valid ()) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
437 error ("__ftp_ascii__: invalid ftp handle"); |
9880 | 438 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
439 url_xfer.ascii (); |
9880 | 440 |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
441 return ovl (); |
9880 | 442 } |
443 | |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
444 DEFMETHOD (__ftp_binary__, interp, args, , |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
445 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
446 @deftypefn {} {} __ftp_binary__ (@var{handle}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
447 Undocumented internal function |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
448 @end deftypefn */) |
9880 | 449 { |
20819
f428cbe7576f
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20799
diff
changeset
|
450 if (args.length () != 1) |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
451 error ("__ftp_binary__: incorrect number of arguments"); |
9880 | 452 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
453 octave::url_handle_manager& uhm = interp.get_url_handle_manager (); |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
454 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
455 octave::url_transfer url_xfer = uhm.get_object (args(0)); |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
456 |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
457 if (! url_xfer.is_valid ()) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
458 error ("__ftp_binary__: invalid ftp handle"); |
9880 | 459 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
460 url_xfer.binary (); |
9880 | 461 |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
462 return ovl (); |
9880 | 463 } |
464 | |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
465 DEFMETHOD (__ftp_close__, interp, args, , |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
466 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
467 @deftypefn {} {} __ftp_close__ (@var{handle}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
468 Undocumented internal function |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
469 @end deftypefn */) |
17318
accafe1aee7c
Make use of gripe_disabled_feature() instead of custom error message.
Carnë Draug <carandraug@octave.org>
parents:
15326
diff
changeset
|
470 { |
20819
f428cbe7576f
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20799
diff
changeset
|
471 if (args.length () != 1) |
17318
accafe1aee7c
Make use of gripe_disabled_feature() instead of custom error message.
Carnë Draug <carandraug@octave.org>
parents:
15326
diff
changeset
|
472 error ("__ftp_close__: incorrect number of arguments"); |
9880 | 473 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
474 octave::url_handle_manager& uhm = interp.get_url_handle_manager (); |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
475 |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
476 octave::url_handle h = uhm.lookup (args(0)); |
9880 | 477 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
478 if (! h.ok ()) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
479 error ("__ftp_close__: invalid ftp handle"); |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
480 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
481 uhm.free (h); |
9880 | 482 |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
483 return ovl (); |
17318
accafe1aee7c
Make use of gripe_disabled_feature() instead of custom error message.
Carnë Draug <carandraug@octave.org>
parents:
15326
diff
changeset
|
484 } |
9880 | 485 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
486 DEFMETHOD (__ftp_mode__, interp, args, , |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
487 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
488 @deftypefn {} {} __ftp_mode__ (@var{handle}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
489 Undocumented internal function |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
490 @end deftypefn */) |
17318
accafe1aee7c
Make use of gripe_disabled_feature() instead of custom error message.
Carnë Draug <carandraug@octave.org>
parents:
15326
diff
changeset
|
491 { |
20819
f428cbe7576f
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20799
diff
changeset
|
492 if (args.length () != 1) |
17318
accafe1aee7c
Make use of gripe_disabled_feature() instead of custom error message.
Carnë Draug <carandraug@octave.org>
parents:
15326
diff
changeset
|
493 error ("__ftp_mode__: incorrect number of arguments"); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
494 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
495 octave::url_handle_manager& uhm = interp.get_url_handle_manager (); |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
496 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
497 octave::url_transfer url_xfer = uhm.get_object (args(0)); |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
498 |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
499 if (! url_xfer.is_valid ()) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
500 error ("__ftp_binary__: invalid ftp handle"); |
9880 | 501 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
502 return ovl (url_xfer.is_ascii () ? "ascii" : "binary"); |
17318
accafe1aee7c
Make use of gripe_disabled_feature() instead of custom error message.
Carnë Draug <carandraug@octave.org>
parents:
15326
diff
changeset
|
503 } |
9880 | 504 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
505 DEFMETHOD (__ftp_delete__, interp, args, , |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
506 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
507 @deftypefn {} {} __ftp_delete__ (@var{handle}, @var{path}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
508 Undocumented internal function |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
509 @end deftypefn */) |
9880 | 510 { |
20819
f428cbe7576f
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20799
diff
changeset
|
511 if (args.length () != 2) |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
512 error ("__ftp_delete__: incorrect number of arguments"); |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
513 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
514 std::string file = args(1).xstring_value ("__ftp_delete__: FILE must be a string"); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
515 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
516 octave::url_handle_manager& uhm = interp.get_url_handle_manager (); |
9880 | 517 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
518 octave::url_transfer url_xfer = uhm.get_object (args(0)); |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
519 |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
520 if (! url_xfer.is_valid ()) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
521 error ("__ftp_delete__: invalid ftp handle"); |
9880 | 522 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
523 url_xfer.del (file); |
9880 | 524 |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
525 return ovl (); |
9880 | 526 } |
527 | |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
528 DEFMETHOD (__ftp_rmdir__, interp, args, , |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
529 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
530 @deftypefn {} {} __ftp_rmdir__ (@var{handle}, @var{path}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
531 Undocumented internal function |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
532 @end deftypefn */) |
9880 | 533 { |
20819
f428cbe7576f
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20799
diff
changeset
|
534 if (args.length () != 2) |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
535 error ("__ftp_rmdir__: incorrect number of arguments"); |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
536 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
537 std::string dir = args(1).xstring_value ("__ftp_rmdir__: DIR must be a string"); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
538 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
539 octave::url_handle_manager& uhm = interp.get_url_handle_manager (); |
9880 | 540 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
541 octave::url_transfer url_xfer = uhm.get_object (args(0)); |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
542 |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
543 if (! url_xfer.is_valid ()) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
544 error ("__ftp_rmdir__: invalid ftp handle"); |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
545 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
546 url_xfer.rmdir (dir); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
547 |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
548 return ovl (); |
9880 | 549 } |
550 | |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
551 DEFMETHOD (__ftp_mkdir__, interp, args, , |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
552 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
553 @deftypefn {} {} __ftp_mkdir__ (@var{handle}, @var{path}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
554 Undocumented internal function |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
555 @end deftypefn */) |
9880 | 556 { |
20819
f428cbe7576f
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20799
diff
changeset
|
557 if (args.length () != 2) |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
558 error ("__ftp_mkdir__: incorrect number of arguments"); |
9880 | 559 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
560 std::string dir = args(1).xstring_value ("__ftp_mkdir__: DIR must be a string"); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
561 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
562 octave::url_handle_manager& uhm = interp.get_url_handle_manager (); |
9880 | 563 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
564 octave::url_transfer url_xfer = uhm.get_object (args(0)); |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
565 |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
566 if (! url_xfer.is_valid ()) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
567 error ("__ftp_mkdir__: invalid ftp handle"); |
9880 | 568 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
569 url_xfer.mkdir (dir); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
570 |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
571 return ovl (); |
9880 | 572 } |
573 | |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
574 DEFMETHOD (__ftp_rename__, interp, args, , |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
575 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
576 @deftypefn {} {} __ftp_rename__ (@var{handle}, @var{path}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
577 Undocumented internal function |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
578 @end deftypefn */) |
9880 | 579 { |
20819
f428cbe7576f
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20799
diff
changeset
|
580 if (args.length () != 3) |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
581 error ("__ftp_rename__: incorrect number of arguments"); |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
582 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
583 std::string oldname = args(1).xstring_value ("__ftp_rename__: OLDNAME must be a string"); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
584 std::string newname = args(2).xstring_value ("__ftp_rename__: NEWNAME must be a string"); |
9880 | 585 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
586 octave::url_handle_manager& uhm = interp.get_url_handle_manager (); |
9880 | 587 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
588 octave::url_transfer url_xfer = uhm.get_object (args(0)); |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
589 |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
590 if (url_xfer.is_valid ()) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
591 error ("__ftp_rename__: invalid ftp handle"); |
9880 | 592 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
593 url_xfer.rename (oldname, newname); |
9880 | 594 |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
595 return ovl (); |
9880 | 596 } |
597 | |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
598 DEFMETHOD (__ftp_mput__, interp, args, nargout, |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
599 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
600 @deftypefn {} {} __ftp_mput__ (@var{handle}, @var{files}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
601 Undocumented internal function |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
602 @end deftypefn */) |
9880 | 603 { |
20819
f428cbe7576f
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20799
diff
changeset
|
604 if (args.length () != 2) |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
605 error ("__ftp_mput__: incorrect number of arguments"); |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
606 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
607 std::string pat = args(1).xstring_value ("__ftp_mput__: PATTERN must be a string"); |
9880 | 608 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
609 octave::url_handle_manager& uhm = interp.get_url_handle_manager (); |
9880 | 610 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
611 octave::url_transfer url_xfer = uhm.get_object (args(0)); |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
612 |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
613 if (! url_xfer.is_valid ()) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
614 error ("__ftp_mput__: invalid ftp handle"); |
9880 | 615 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
616 string_vector file_list; |
9880 | 617 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
618 glob_match pattern (octave::sys::file_ops::tilde_expand (pat)); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
619 string_vector files = pattern.glob (); |
9880 | 620 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
621 for (octave_idx_type i = 0; i < files.numel (); i++) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
622 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
623 std::string file = files(i); |
17553
2d01e20abd85
rework error handling for url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17551
diff
changeset
|
624 |
21736
0504351a45e6
use namespace for file_stat classes
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
625 octave::sys::file_stat fs (file); |
9880 | 626 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
627 if (! fs.exists ()) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
628 error ("__ftp__mput: file does not exist"); |
9880 | 629 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
630 if (fs.is_dir ()) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
631 { |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
632 file_list.append (url_xfer.mput_directory ("", file)); |
9880 | 633 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
634 if (! url_xfer.good ()) |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
635 error ("__ftp_mput__: %s", url_xfer.lasterror ().c_str ()); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
636 } |
17548
92541ff4cc3c
improve implementation of ftp object handles
John W. Eaton <jwe@octave.org>
parents:
17546
diff
changeset
|
637 else |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
638 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
639 // FIXME: Does ascii mode need to be flagged here? |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
640 std::ifstream ifile (file.c_str (), std::ios::in | std::ios::binary); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
641 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
642 if (! ifile.is_open ()) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
643 error ("__ftp_mput__: unable to open file"); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
644 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
645 url_xfer.put (file, ifile); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
646 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
647 ifile.close (); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
648 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
649 if (! url_xfer.good ()) |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
650 error ("__ftp_mput__: %s", url_xfer.lasterror ().c_str ()); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
651 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
652 file_list.append (file); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
653 } |
9880 | 654 } |
655 | |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
656 if (nargout > 0) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
657 return ovl (file_list); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
658 else |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
659 return ovl (); |
9880 | 660 } |
661 | |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
662 DEFMETHOD (__ftp_mget__, interp, args, , |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
663 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
664 @deftypefn {} {} __ftp_mget__ (@var{handle}, @var{pattern}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
665 @deftypefnx {} {} __ftp_mget__ (@var{handle}, @var{pattern}, @var{target}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
666 Undocumented internal function |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
667 @end deftypefn */) |
9880 | 668 { |
669 int nargin = args.length (); | |
670 | |
671 if (nargin != 2 && nargin != 3) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
672 error ("__ftp_mget__: incorrect number of arguments"); |
17551
8fca0bbdd4c1
reorganize curl wrapper class
John W. Eaton <jwe@octave.org>
parents:
17550
diff
changeset
|
673 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
674 std::string file = args(1).xstring_value ("__ftp_mget__: PATTERN must be a string"); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
675 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
676 std::string target; |
9880 | 677 |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23461
diff
changeset
|
678 if (nargin == 3 && ! args(2).isempty ()) |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
679 target = args(2).xstring_value ("__ftp_mget__: TARGET must be a string") + octave::sys::file_ops::dir_sep_str (); |
9880 | 680 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
681 octave::url_handle_manager& uhm = interp.get_url_handle_manager (); |
9880 | 682 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
683 octave::url_transfer url_xfer = uhm.get_object (args(0)); |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
684 |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
685 if (! url_xfer.is_valid ()) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
686 error ("__ftp_mget__: invalid ftp handle"); |
9880 | 687 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
688 string_vector sv = url_xfer.list (); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
689 octave_idx_type n = 0; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
690 glob_match pattern (file); |
17553
2d01e20abd85
rework error handling for url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17551
diff
changeset
|
691 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
692 for (octave_idx_type i = 0; i < sv.numel (); i++) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
693 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
694 if (pattern.match (sv(i))) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
695 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
696 n++; |
9880 | 697 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
698 time_t ftime; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
699 bool fisdir; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
700 double fsize; |
9880 | 701 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
702 url_xfer.get_fileinfo (sv(i), fsize, ftime, fisdir); |
9880 | 703 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
704 if (fisdir) |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
705 url_xfer.mget_directory (sv(i), target); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
706 else |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
707 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
708 std::ofstream ofile ((target + sv(i)).c_str (), |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
709 std::ios::out | |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
710 std::ios::binary); |
9880 | 711 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
712 if (! ofile.is_open ()) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
713 error ("__ftp_mget__: unable to open file"); |
9880 | 714 |
21743
f4d7d0eb5b0c
use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
715 octave::unwind_protect_safe frame; |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
716 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
717 frame.add_fcn (delete_file, target + sv(i)); |
9880 | 718 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
719 url_xfer.get (sv(i), ofile); |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
720 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
721 ofile.close (); |
9880 | 722 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
723 if (url_xfer.good ()) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
724 frame.discard (); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
725 } |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20577
diff
changeset
|
726 |
23742
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
727 if (! url_xfer.good ()) |
1f0daaf81955
don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
728 error ("__ftp_mget__: %s", url_xfer.lasterror().c_str()); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
729 } |
9880 | 730 } |
731 | |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
732 if (n == 0) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
733 error ("__ftp_mget__: file not found"); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20909
diff
changeset
|
734 |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
735 return ovl (); |
9880 | 736 } |