Mercurial > hg > octave-nkf
annotate liboctave/util/url-transfer.cc @ 20442:a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
* liboctave/array/Array.h (Array::length): deprecate for ::numel.
* liboctave/array/Sparse.h (Sparse::length): deprecate for ::numel.
* libgui/graphics/QtHandlesUtils.cc, libgui/src/octave-qt-link.cc,
libinterp/corefcn/Cell.cc, libinterp/corefcn/__contourc__.cc,
libinterp/corefcn/__pchip_deriv__.cc, libinterp/corefcn/__qp__.cc,
libinterp/corefcn/cellfun.cc, libinterp/corefcn/daspk.cc,
libinterp/corefcn/dasrt.cc, libinterp/corefcn/dassl.cc,
libinterp/corefcn/data.cc, libinterp/corefcn/filter.cc,
libinterp/corefcn/find.cc, libinterp/corefcn/gl-render.cc,
libinterp/corefcn/gl-render.h, libinterp/corefcn/graphics.cc,
libinterp/corefcn/graphics.in.h, libinterp/corefcn/help.cc,
libinterp/corefcn/hex2num.cc, libinterp/corefcn/input.cc,
libinterp/corefcn/load-path.cc, libinterp/corefcn/load-save.cc,
libinterp/corefcn/ls-oct-ascii.h, libinterp/corefcn/lsode.cc,
libinterp/corefcn/matrix_type.cc, libinterp/corefcn/oct-hist.cc,
libinterp/corefcn/oct-map.cc, libinterp/corefcn/oct-map.h,
libinterp/corefcn/oct-obj.h, libinterp/corefcn/oct-stream.cc,
libinterp/corefcn/oct-stream.h, libinterp/corefcn/pr-output.cc,
libinterp/corefcn/quadcc.cc, libinterp/corefcn/rand.cc,
libinterp/corefcn/regexp.cc, libinterp/corefcn/strfns.cc,
libinterp/corefcn/sub2ind.cc, libinterp/corefcn/symtab.h,
libinterp/corefcn/syscalls.cc, libinterp/corefcn/tsearch.cc,
libinterp/corefcn/urlwrite.cc, libinterp/corefcn/utils.cc,
libinterp/corefcn/variables.cc, libinterp/corefcn/xdiv.cc,
libinterp/corefcn/xpow.cc, libinterp/dldfcn/__glpk__.cc,
libinterp/dldfcn/__init_fltk__.cc, libinterp/dldfcn/__magick_read__.cc,
libinterp/dldfcn/audiodevinfo.cc, libinterp/dldfcn/ccolamd.cc,
libinterp/dldfcn/colamd.cc, libinterp/octave-value/ov-cell.cc,
libinterp/octave-value/ov-class.cc, libinterp/octave-value/ov-class.h,
libinterp/octave-value/ov-fcn-inline.cc, libinterp/octave-value/ov-java.cc,
libinterp/octave-value/ov-perm.cc, libinterp/octave-value/ov-struct.cc,
libinterp/octave-value/ov-typeinfo.cc, libinterp/octave-value/ov.cc,
libinterp/operators/op-int.h, libinterp/parse-tree/pt-pr-code.cc,
liboctave/array/Array-util.cc, liboctave/array/Array.cc,
liboctave/array/CColVector.cc, liboctave/array/CDiagMatrix.cc,
liboctave/array/CMatrix.cc, liboctave/array/CRowVector.cc,
liboctave/array/DiagArray2.cc, liboctave/array/DiagArray2.h,
liboctave/array/MArray.cc, liboctave/array/PermMatrix.cc,
liboctave/array/PermMatrix.h, liboctave/array/Sparse.cc,
liboctave/array/boolMatrix.cc, liboctave/array/chMatrix.cc,
liboctave/array/chNDArray.cc, liboctave/array/dColVector.cc,
liboctave/array/dDiagMatrix.cc, liboctave/array/dMatrix.cc,
liboctave/array/dRowVector.cc, liboctave/array/fCColVector.cc,
liboctave/array/fCDiagMatrix.cc, liboctave/array/fCMatrix.cc,
liboctave/array/fCRowVector.cc, liboctave/array/fColVector.cc,
liboctave/array/fDiagMatrix.cc, liboctave/array/fMatrix.cc,
liboctave/array/fRowVector.cc, liboctave/array/idx-vector.cc,
liboctave/array/intNDArray.cc, liboctave/numeric/CmplxCHOL.cc,
liboctave/numeric/CmplxLU.cc, liboctave/numeric/CmplxQR.cc,
liboctave/numeric/DASPK.cc, liboctave/numeric/DASRT.cc,
liboctave/numeric/DASSL.cc, liboctave/numeric/LSODE.cc,
liboctave/numeric/ODES.cc, liboctave/numeric/ODES.h,
liboctave/numeric/base-dae.h, liboctave/numeric/base-lu.cc,
liboctave/numeric/dbleCHOL.cc, liboctave/numeric/dbleLU.cc,
liboctave/numeric/dbleQR.cc, liboctave/numeric/eigs-base.cc,
liboctave/numeric/fCmplxCHOL.cc, liboctave/numeric/fCmplxLU.cc,
liboctave/numeric/fCmplxQR.cc, liboctave/numeric/floatCHOL.cc,
liboctave/numeric/floatLU.cc, liboctave/numeric/floatQR.cc,
liboctave/numeric/lo-specfun.cc, liboctave/numeric/oct-rand.cc,
liboctave/numeric/oct-spparms.cc, liboctave/numeric/sparse-base-chol.cc,
liboctave/operators/mx-inlines.cc, liboctave/system/file-ops.cc,
liboctave/util/glob-match.h, liboctave/util/kpse.cc,
liboctave/util/lo-regexp.cc, liboctave/util/oct-glob.cc,
liboctave/util/pathsearch.cc, liboctave/util/str-vec.cc,
liboctave/util/str-vec.h, liboctave/util/url-transfer.cc: replace all usage
of Array::length() and Sparse::length() with ::numel().
author | Carnë Draug <carandraug@octave.org> |
---|---|
date | Sat, 30 May 2015 03:14:07 +0100 |
parents | 4197fc428c7d |
children |
rev | line source |
---|---|
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1 /* |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
2 |
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
18312
diff
changeset
|
3 Copyright (C) 2013-2015 John W. Eaton |
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
18312
diff
changeset
|
4 Copyright (C) 2006-2015 Alexander Barth |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
5 Copyright (C) 2009 David Bateman |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
6 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
7 This file is part of Octave. |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
8 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
9 Octave is free software; you can redistribute it and/or modify it |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
10 under the terms of the GNU General Public License as published by the |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
11 Free Software Foundation; either version 3 of the License, or (at your |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
12 option) any later version. |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
13 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
14 Octave is distributed in the hope that it will be useful, but WITHOUT |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
17 for more details. |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
18 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
19 You should have received a copy of the GNU General Public License |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
20 along with Octave; see the file COPYING. If not, see |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
21 <http://www.gnu.org/licenses/>. |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
22 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
23 */ |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
24 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
25 // Author: Alexander Barth <abarth@marine.usf.edu> |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
26 // Author: jwe |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
27 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
28 #ifdef HAVE_CONFIG_H |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
29 #include <config.h> |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
30 #endif |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
31 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
32 #include <fstream> |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
33 #include <iomanip> |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
34 #include <iostream> |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
35 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
36 #include "dir-ops.h" |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
37 #include "file-ops.h" |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
38 #include "file-stat.h" |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
39 #include "unwind-prot.h" |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
40 #include "url-transfer.h" |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
41 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
42 #ifdef HAVE_CURL |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
43 #include <curl/curl.h> |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
44 #include <curl/curlver.h> |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
45 #include <curl/easy.h> |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
46 #endif |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
47 |
17596
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
48 void |
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
49 base_url_transfer::delete_file (const std::string& file) |
17557
58039875767d
move function definition out of header file
John W. Eaton <jwe@octave.org>
parents:
17555
diff
changeset
|
50 { |
58039875767d
move function definition out of header file
John W. Eaton <jwe@octave.org>
parents:
17555
diff
changeset
|
51 octave_unlink (file); |
58039875767d
move function definition out of header file
John W. Eaton <jwe@octave.org>
parents:
17555
diff
changeset
|
52 } |
58039875767d
move function definition out of header file
John W. Eaton <jwe@octave.org>
parents:
17555
diff
changeset
|
53 |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
54 void |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
55 base_url_transfer::mget_directory (const std::string& directory, |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
56 const std::string& target) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
57 { |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
58 std::string sep = file_ops::dir_sep_str (); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
59 file_stat fs (directory); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
60 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
61 if (!fs || !fs.is_dir ()) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
62 { |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
63 std::string msg; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
64 int status = octave_mkdir (directory, 0777, msg); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
65 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
66 if (status < 0) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
67 { |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
68 ok = false; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
69 errmsg = "__ftp_mget__: can not create directory '" |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
70 + target + sep + directory + "': " + msg; |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
71 return; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
72 } |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
73 } |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
74 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
75 cwd (directory); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
76 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
77 if (good ()) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
78 { |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
79 unwind_protect_safe frame; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
80 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
81 frame.add_fcn (reset_path, this); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
82 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
83 string_vector sv = list (); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
84 |
20442
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19898
diff
changeset
|
85 for (octave_idx_type i = 0; i < sv.numel (); i++) |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
86 { |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
87 time_t ftime; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
88 bool fisdir; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
89 double fsize; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
90 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
91 get_fileinfo (sv(i), fsize, ftime, fisdir); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
92 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
93 if (fisdir) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
94 mget_directory (sv(i), target + directory + sep); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
95 else |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
96 { |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
97 std::string realfile = target + directory + sep + sv(i); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
98 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
99 std::ofstream ofile (realfile.c_str (), |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
100 std::ios::out | std::ios::binary); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
101 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
102 if (! ofile.is_open ()) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
103 { |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
104 ok = false; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
105 errmsg = "__ftp_mget__: unable to open file"; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
106 break; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
107 } |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
108 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
109 unwind_protect_safe frame2; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
110 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
111 frame2.add_fcn (delete_file, realfile); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
112 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
113 get (sv(i), ofile); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
114 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
115 ofile.close (); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
116 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
117 if (good ()) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
118 frame2.discard (); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
119 } |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
120 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
121 if (! good ()) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
122 break; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
123 } |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
124 } |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
125 } |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
126 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
127 string_vector |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
128 base_url_transfer::mput_directory (const std::string& base, |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
129 const std::string& directory) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
130 { |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
131 string_vector file_list; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
132 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
133 std::string realdir |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
134 = (base.length () == 0 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
135 ? directory : base + file_ops::dir_sep_str () + directory); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
136 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
137 mkdir (directory); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
138 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
139 if (! good ()) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
140 return file_list; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
141 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
142 cwd (directory); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
143 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
144 if (good ()) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
145 { |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
146 unwind_protect_safe frame; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
147 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
148 frame.add_fcn (reset_path, this); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
149 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
150 dir_entry dirlist (realdir); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
151 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
152 if (dirlist) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
153 { |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
154 string_vector files = dirlist.read (); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
155 |
20442
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19898
diff
changeset
|
156 for (octave_idx_type i = 0; i < files.numel (); i++) |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
157 { |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
158 std::string file = files (i); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
159 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
160 if (file == "." || file == "..") |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
161 continue; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
162 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
163 std::string realfile = realdir + file_ops::dir_sep_str () + file; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
164 file_stat fs (realfile); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
165 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
166 if (! fs.exists ()) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
167 { |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
168 ok = false; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
169 errmsg = "__ftp__mput: file '" + realfile |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
170 + "' does not exist"; |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
171 break; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
172 } |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
173 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
174 if (fs.is_dir ()) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
175 { |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
176 file_list.append (mput_directory (realdir, file)); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
177 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
178 if (! good ()) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
179 break; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
180 } |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
181 else |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
182 { |
17861
870f3e12e163
maint: Use phrase "FIXME:" for problem areas in code.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
183 // FIXME: Does ascii mode need to be flagged here? |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
184 std::ifstream ifile (realfile.c_str (), std::ios::in | |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
185 std::ios::binary); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
186 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
187 if (! ifile.is_open ()) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
188 { |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
189 ok = false; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
190 errmsg = "__ftp_mput__: unable to open file '" |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
191 + realfile + "'"; |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
192 break; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
193 } |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
194 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
195 put (file, ifile); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
196 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
197 ifile.close (); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
198 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
199 if (! good ()) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
200 break; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
201 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
202 file_list.append (realfile); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
203 } |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
204 } |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
205 } |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
206 else |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
207 { |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
208 ok = false; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
209 errmsg = "__ftp_mput__: can not read the directory '" |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
210 + realdir + "'"; |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
211 } |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
212 } |
17597
e5932e528721
* url-transfer.cc (base_url_transfer::mput_directory): Return file list.
John W. Eaton <jwe@octave.org>
parents:
17596
diff
changeset
|
213 |
e5932e528721
* url-transfer.cc (base_url_transfer::mput_directory): Return file list.
John W. Eaton <jwe@octave.org>
parents:
17596
diff
changeset
|
214 return file_list; |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
215 } |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
216 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
217 #if defined (HAVE_CURL) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
218 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
219 static int |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
220 write_data (void *buffer, size_t size, size_t nmemb, void *streamp) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
221 { |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
222 std::ostream& stream = *(static_cast<std::ostream*> (streamp)); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
223 stream.write (static_cast<const char*> (buffer), size*nmemb); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
224 return (stream.fail () ? 0 : size * nmemb); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
225 } |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
226 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
227 static int |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
228 read_data (void *buffer, size_t size, size_t nmemb, void *streamp) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
229 { |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
230 std::istream& stream = *(static_cast<std::istream*> (streamp)); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
231 stream.read (static_cast<char*> (buffer), size*nmemb); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
232 if (stream.eof ()) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
233 return stream.gcount (); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
234 else |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
235 return (stream.fail () ? 0 : size * nmemb); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
236 } |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
237 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
238 static size_t |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
239 throw_away (void *, size_t size, size_t nmemb, void *) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
240 { |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
241 return static_cast<size_t>(size * nmemb); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
242 } |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
243 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
244 // I'd love to rewrite this as a private method of the url_transfer |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
245 // class, but you can't pass the va_list from the wrapper SETOPT to |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
246 // the curl_easy_setopt function. |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
247 #define SETOPT(option, parameter) \ |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
248 do \ |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
249 { \ |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
250 CURLcode res = curl_easy_setopt (curl, option, parameter); \ |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
251 if (res != CURLE_OK) \ |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
252 { \ |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
253 ok = false; \ |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
254 errmsg = curl_easy_strerror (res); \ |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
255 return; \ |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
256 } \ |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
257 } \ |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
258 while (0) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
259 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
260 // Same as above but with a return value. |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
261 #define SETOPTR(option, parameter) \ |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
262 do \ |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
263 { \ |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
264 CURLcode res = curl_easy_setopt (curl, option, parameter); \ |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
265 if (res != CURLE_OK) \ |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
266 { \ |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
267 ok = false; \ |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
268 errmsg = curl_easy_strerror (res); \ |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
269 return retval; \ |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
270 } \ |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
271 } \ |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
272 while (0) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
273 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
274 class curl_transfer : public base_url_transfer |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
275 { |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
276 public: |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
277 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
278 curl_transfer (void) |
17614
ce7b9abf6600
Keep a copy of url string for older cURL libraries
Mike Miller <mtmiller@ieee.org>
parents:
17601
diff
changeset
|
279 : base_url_transfer (), curl (curl_easy_init ()), errnum (), url (), |
ce7b9abf6600
Keep a copy of url string for older cURL libraries
Mike Miller <mtmiller@ieee.org>
parents:
17601
diff
changeset
|
280 userpwd () |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
281 { |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
282 if (curl) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
283 valid = true; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
284 else |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
285 errmsg = "can not create curl object"; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
286 } |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
287 |
17596
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
288 curl_transfer (const std::string& host, const std::string& user_arg, |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
289 const std::string& passwd, std::ostream& os) |
17596
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
290 : base_url_transfer (host, user_arg, passwd, os), |
17614
ce7b9abf6600
Keep a copy of url string for older cURL libraries
Mike Miller <mtmiller@ieee.org>
parents:
17601
diff
changeset
|
291 curl (curl_easy_init ()), errnum (), url (), userpwd () |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
292 { |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
293 if (curl) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
294 valid = true; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
295 else |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
296 { |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
297 errmsg = "can not create curl object"; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
298 return; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
299 } |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
300 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
301 init (user_arg, passwd, std::cin, os); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
302 |
17614
ce7b9abf6600
Keep a copy of url string for older cURL libraries
Mike Miller <mtmiller@ieee.org>
parents:
17601
diff
changeset
|
303 url = "ftp://" + host; |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
304 SETOPT (CURLOPT_URL, url.c_str ()); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
305 |
17596
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
306 // Set up the link, with no transfer. |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
307 perform (); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
308 } |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
309 |
17630
484c9a6f4f27
maint: Fix compiler shadowed variable warning in curl_transfer constructor.
Rik <rik@octave.org>
parents:
17614
diff
changeset
|
310 curl_transfer (const std::string& url_str, std::ostream& os) |
484c9a6f4f27
maint: Fix compiler shadowed variable warning in curl_transfer constructor.
Rik <rik@octave.org>
parents:
17614
diff
changeset
|
311 : base_url_transfer (url_str, os), curl (curl_easy_init ()), errnum (), |
17614
ce7b9abf6600
Keep a copy of url string for older cURL libraries
Mike Miller <mtmiller@ieee.org>
parents:
17601
diff
changeset
|
312 url (), userpwd () |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
313 { |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
314 if (curl) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
315 valid = true; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
316 else |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
317 { |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
318 errmsg = "can not create curl object"; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
319 return; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
320 } |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
321 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
322 init ("", "", std::cin, os); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
323 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
324 SETOPT (CURLOPT_NOBODY, 0); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
325 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
326 // Restore the default HTTP request method to GET after setting |
17596
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
327 // NOBODY to true (in the init method) and back to false (above). |
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
328 // This is needed for backward compatibility with versions of |
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
329 // libcurl < 7.18.2. |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
330 SETOPT (CURLOPT_HTTPGET, 1); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
331 } |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
332 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
333 ~curl_transfer (void) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
334 { |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
335 if (curl) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
336 curl_easy_cleanup (curl); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
337 } |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
338 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
339 void perform (void) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
340 { |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
341 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
342 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
343 errnum = curl_easy_perform (curl); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
344 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
345 if (errnum != CURLE_OK) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
346 { |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
347 ok = false; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
348 errmsg = curl_easy_strerror (errnum); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
349 } |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
350 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
351 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
352 } |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
353 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
354 std::string lasterror (void) const |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
355 { |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
356 return std::string (curl_easy_strerror (errnum)); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
357 } |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
358 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
359 std::ostream& set_ostream (std::ostream& os) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
360 { |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
361 std::ostream& retval = *curr_ostream; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
362 curr_ostream = &os; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
363 SETOPTR (CURLOPT_WRITEDATA, static_cast<void*> (curr_ostream)); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
364 return retval; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
365 } |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
366 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
367 std::istream& set_istream (std::istream& is) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
368 { |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
369 std::istream& retval = *curr_istream; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
370 curr_istream = &is; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
371 SETOPTR (CURLOPT_READDATA, static_cast<void*> (curr_istream)); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
372 return retval; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
373 } |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
374 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
375 void ascii (void) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
376 { |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
377 ascii_mode = true; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
378 SETOPT (CURLOPT_TRANSFERTEXT, 1); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
379 } |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
380 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
381 void binary (void) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
382 { |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
383 ascii_mode = false; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
384 SETOPT (CURLOPT_TRANSFERTEXT, 0); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
385 } |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
386 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
387 void cwd (const std::string& path) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
388 { |
17595
4b65355a31f2
avoid some code duplication in url-transfer ftp methods
John W. Eaton <jwe@octave.org>
parents:
17563
diff
changeset
|
389 ftp_file_or_dir_action (path, "cwd"); |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
390 } |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
391 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
392 void del (const std::string& file) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
393 { |
17595
4b65355a31f2
avoid some code duplication in url-transfer ftp methods
John W. Eaton <jwe@octave.org>
parents:
17563
diff
changeset
|
394 ftp_file_or_dir_action (file, "dele"); |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
395 } |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
396 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
397 void rmdir (const std::string& path) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
398 { |
17595
4b65355a31f2
avoid some code duplication in url-transfer ftp methods
John W. Eaton <jwe@octave.org>
parents:
17563
diff
changeset
|
399 ftp_file_or_dir_action (path, "rmd"); |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
400 } |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
401 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
402 void mkdir (const std::string& path) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
403 { |
17595
4b65355a31f2
avoid some code duplication in url-transfer ftp methods
John W. Eaton <jwe@octave.org>
parents:
17563
diff
changeset
|
404 ftp_file_or_dir_action (path, "mkd"); |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
405 } |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
406 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
407 void rename (const std::string& oldname, const std::string& newname) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
408 { |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
409 struct curl_slist *slist = 0; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
410 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
411 unwind_protect frame; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
412 frame.add_fcn (curl_slist_free_all, slist); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
413 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
414 std::string cmd = "rnfr " + oldname; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
415 slist = curl_slist_append (slist, cmd.c_str ()); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
416 cmd = "rnto " + newname; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
417 slist = curl_slist_append (slist, cmd.c_str ()); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
418 SETOPT (CURLOPT_POSTQUOTE, slist); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
419 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
420 perform (); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
421 if (! good ()) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
422 return; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
423 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
424 SETOPT (CURLOPT_POSTQUOTE, 0); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
425 } |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
426 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
427 void put (const std::string& file, std::istream& is) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
428 { |
17614
ce7b9abf6600
Keep a copy of url string for older cURL libraries
Mike Miller <mtmiller@ieee.org>
parents:
17601
diff
changeset
|
429 url = "ftp://" + host_or_url + "/" + file; |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
430 SETOPT (CURLOPT_URL, url.c_str ()); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
431 SETOPT (CURLOPT_UPLOAD, 1); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
432 SETOPT (CURLOPT_NOBODY, 0); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
433 std::istream& old_is = set_istream (is); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
434 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
435 perform (); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
436 if (! good ()) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
437 return; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
438 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
439 set_istream (old_is); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
440 SETOPT (CURLOPT_NOBODY, 1); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
441 SETOPT (CURLOPT_UPLOAD, 0); |
17596
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
442 url = "ftp://" + host_or_url; |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
443 SETOPT (CURLOPT_URL, url.c_str ()); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
444 } |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
445 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
446 void get (const std::string& file, std::ostream& os) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
447 { |
17614
ce7b9abf6600
Keep a copy of url string for older cURL libraries
Mike Miller <mtmiller@ieee.org>
parents:
17601
diff
changeset
|
448 url = "ftp://" + host_or_url + "/" + file; |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
449 SETOPT (CURLOPT_URL, url.c_str ()); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
450 SETOPT (CURLOPT_NOBODY, 0); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
451 std::ostream& old_os = set_ostream (os); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
452 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
453 perform (); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
454 if (! good ()) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
455 return; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
456 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
457 set_ostream (old_os); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
458 SETOPT (CURLOPT_NOBODY, 1); |
17596
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
459 url = "ftp://" + host_or_url; |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
460 SETOPT (CURLOPT_URL, url.c_str ()); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
461 } |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
462 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
463 void dir (void) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
464 { |
17614
ce7b9abf6600
Keep a copy of url string for older cURL libraries
Mike Miller <mtmiller@ieee.org>
parents:
17601
diff
changeset
|
465 url = "ftp://" + host_or_url + "/"; |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
466 SETOPT (CURLOPT_URL, url.c_str ()); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
467 SETOPT (CURLOPT_NOBODY, 0); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
468 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
469 perform (); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
470 if (! good ()) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
471 return; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
472 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
473 SETOPT (CURLOPT_NOBODY, 1); |
17596
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
474 url = "ftp://" + host_or_url; |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
475 SETOPT (CURLOPT_URL, url.c_str ()); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
476 } |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
477 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
478 string_vector list (void) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
479 { |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
480 string_vector retval; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
481 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
482 std::ostringstream buf; |
17614
ce7b9abf6600
Keep a copy of url string for older cURL libraries
Mike Miller <mtmiller@ieee.org>
parents:
17601
diff
changeset
|
483 url = "ftp://" + host_or_url + "/"; |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
484 SETOPTR (CURLOPT_WRITEDATA, static_cast<void*> (&buf)); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
485 SETOPTR (CURLOPT_URL, url.c_str ()); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
486 SETOPTR (CURLOPT_DIRLISTONLY, 1); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
487 SETOPTR (CURLOPT_NOBODY, 0); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
488 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
489 perform (); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
490 if (! good ()) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
491 return retval; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
492 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
493 SETOPTR (CURLOPT_NOBODY, 1); |
17596
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
494 url = "ftp://" + host_or_url; |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
495 SETOPTR (CURLOPT_WRITEDATA, static_cast<void*> (curr_ostream)); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
496 SETOPTR (CURLOPT_DIRLISTONLY, 0); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
497 SETOPTR (CURLOPT_URL, url.c_str ()); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
498 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
499 // Count number of directory entries |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
500 std::string str = buf.str (); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
501 octave_idx_type n = 0; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
502 size_t pos = 0; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
503 while (true) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
504 { |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
505 pos = str.find_first_of ('\n', pos); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
506 if (pos == std::string::npos) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
507 break; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
508 pos++; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
509 n++; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
510 } |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
511 retval.resize (n); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
512 pos = 0; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
513 for (octave_idx_type i = 0; i < n; i++) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
514 { |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
515 size_t newpos = str.find_first_of ('\n', pos); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
516 if (newpos == std::string::npos) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
517 break; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
518 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
519 retval(i) = str.substr(pos, newpos - pos); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
520 pos = newpos + 1; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
521 } |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
522 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
523 return retval; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
524 } |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
525 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
526 void get_fileinfo (const std::string& filename, double& filesize, |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
527 time_t& filetime, bool& fileisdir) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
528 { |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
529 std::string path = pwd (); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
530 |
17614
ce7b9abf6600
Keep a copy of url string for older cURL libraries
Mike Miller <mtmiller@ieee.org>
parents:
17601
diff
changeset
|
531 url = "ftp://" + host_or_url + "/" + path + "/" + filename; |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
532 SETOPT (CURLOPT_URL, url.c_str ()); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
533 SETOPT (CURLOPT_FILETIME, 1); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
534 SETOPT (CURLOPT_HEADERFUNCTION, throw_away); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
535 SETOPT (CURLOPT_WRITEFUNCTION, throw_away); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
536 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
537 // FIXME |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
538 // The MDTM command fails for a directory on the servers I tested |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
539 // so this is a means of testing for directories. It also means |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
540 // I can't get the date of directories! |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
541 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
542 perform (); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
543 if (! good ()) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
544 { |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
545 fileisdir = true; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
546 filetime = -1; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
547 filesize = 0; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
548 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
549 return; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
550 } |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
551 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
552 fileisdir = false; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
553 time_t ft; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
554 curl_easy_getinfo (curl, CURLINFO_FILETIME, &ft); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
555 filetime = ft; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
556 double fs; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
557 curl_easy_getinfo (curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &fs); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
558 filesize = fs; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
559 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
560 SETOPT (CURLOPT_WRITEFUNCTION, write_data); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
561 SETOPT (CURLOPT_HEADERFUNCTION, 0); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
562 SETOPT (CURLOPT_FILETIME, 0); |
17596
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
563 url = "ftp://" + host_or_url; |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
564 SETOPT (CURLOPT_URL, url.c_str ()); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
565 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
566 // The MDTM command seems to reset the path to the root with the |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
567 // servers I tested with, so cd again into the correct path. Make |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
568 // the path absolute so that this will work even with servers that |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
569 // don't end up in the root after an MDTM command. |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
570 cwd ("/" + path); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
571 } |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
572 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
573 std::string pwd (void) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
574 { |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
575 std::string retval; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
576 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
577 struct curl_slist *slist = 0; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
578 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
579 unwind_protect frame; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
580 frame.add_fcn (curl_slist_free_all, slist); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
581 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
582 slist = curl_slist_append (slist, "pwd"); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
583 SETOPTR (CURLOPT_POSTQUOTE, slist); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
584 SETOPTR (CURLOPT_HEADERFUNCTION, write_data); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
585 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
586 std::ostringstream buf; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
587 SETOPTR (CURLOPT_WRITEHEADER, static_cast<void *>(&buf)); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
588 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
589 perform (); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
590 if (! good ()) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
591 return retval; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
592 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
593 retval = buf.str (); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
594 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
595 // Can I assume that the path is alway in "" on the last line |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
596 size_t pos2 = retval.rfind ('"'); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
597 size_t pos1 = retval.rfind ('"', pos2 - 1); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
598 retval = retval.substr (pos1 + 1, pos2 - pos1 - 1); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
599 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
600 SETOPTR (CURLOPT_HEADERFUNCTION, 0); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
601 SETOPTR (CURLOPT_WRITEHEADER, 0); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
602 SETOPTR (CURLOPT_POSTQUOTE, 0); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
603 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
604 return retval; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
605 } |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
606 |
17596
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
607 void http_get (const Array<std::string>& param) |
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
608 { |
17614
ce7b9abf6600
Keep a copy of url string for older cURL libraries
Mike Miller <mtmiller@ieee.org>
parents:
17601
diff
changeset
|
609 url = host_or_url; |
17596
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
610 |
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
611 std::string query_string = form_query_string (param); |
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
612 |
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
613 if (! query_string.empty ()) |
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
614 url += "?" + query_string; |
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
615 |
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
616 SETOPT (CURLOPT_URL, url.c_str ()); |
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
617 |
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
618 perform (); |
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
619 } |
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
620 |
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
621 void http_post (const Array<std::string>& param) |
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
622 { |
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
623 SETOPT (CURLOPT_URL, host_or_url.c_str ()); |
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
624 |
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
625 std::string query_string = form_query_string (param); |
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
626 |
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
627 SETOPT (CURLOPT_POSTFIELDS, query_string.c_str ()); |
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
628 |
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
629 perform (); |
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
630 } |
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
631 |
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
632 void http_action (const Array<std::string>& param, const std::string& action) |
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
633 { |
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
634 if (action.empty () || action == "get") |
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
635 http_get (param); |
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
636 else if (action == "post") |
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
637 http_post (param); |
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
638 else |
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
639 { |
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
640 ok = false; |
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
641 errmsg = "curl_transfer: unknown http action"; |
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
642 } |
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
643 } |
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
644 |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
645 private: |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
646 |
17601
9e507e30c9ea
keep a copy of user+password data for older cURL libraries
John W. Eaton <jwe@octave.org>
parents:
17598
diff
changeset
|
647 // Pointer to cURL object. |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
648 CURL *curl; |
17601
9e507e30c9ea
keep a copy of user+password data for older cURL libraries
John W. Eaton <jwe@octave.org>
parents:
17598
diff
changeset
|
649 |
9e507e30c9ea
keep a copy of user+password data for older cURL libraries
John W. Eaton <jwe@octave.org>
parents:
17598
diff
changeset
|
650 // cURL error code. |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
651 CURLcode errnum; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
652 |
17601
9e507e30c9ea
keep a copy of user+password data for older cURL libraries
John W. Eaton <jwe@octave.org>
parents:
17598
diff
changeset
|
653 // The cURL library changed the curl_easy_setopt call to make an |
9e507e30c9ea
keep a copy of user+password data for older cURL libraries
John W. Eaton <jwe@octave.org>
parents:
17598
diff
changeset
|
654 // internal copy of string parameters in version 7.17.0. Prior |
9e507e30c9ea
keep a copy of user+password data for older cURL libraries
John W. Eaton <jwe@octave.org>
parents:
17598
diff
changeset
|
655 // versions only held a pointer to a string provided by the caller |
9e507e30c9ea
keep a copy of user+password data for older cURL libraries
John W. Eaton <jwe@octave.org>
parents:
17598
diff
changeset
|
656 // that must persist for the lifetime of the CURL handle. |
9e507e30c9ea
keep a copy of user+password data for older cURL libraries
John W. Eaton <jwe@octave.org>
parents:
17598
diff
changeset
|
657 // |
9e507e30c9ea
keep a copy of user+password data for older cURL libraries
John W. Eaton <jwe@octave.org>
parents:
17598
diff
changeset
|
658 // The associated API did not change, only the behavior of the library |
9e507e30c9ea
keep a copy of user+password data for older cURL libraries
John W. Eaton <jwe@octave.org>
parents:
17598
diff
changeset
|
659 // implementing the function call. |
9e507e30c9ea
keep a copy of user+password data for older cURL libraries
John W. Eaton <jwe@octave.org>
parents:
17598
diff
changeset
|
660 // |
9e507e30c9ea
keep a copy of user+password data for older cURL libraries
John W. Eaton <jwe@octave.org>
parents:
17598
diff
changeset
|
661 // To be compatible with any version of cURL, the caller must keep a |
9e507e30c9ea
keep a copy of user+password data for older cURL libraries
John W. Eaton <jwe@octave.org>
parents:
17598
diff
changeset
|
662 // copy of all string parameters associated with a CURL handle until |
9e507e30c9ea
keep a copy of user+password data for older cURL libraries
John W. Eaton <jwe@octave.org>
parents:
17598
diff
changeset
|
663 // the handle is released. The curl_handle::curl_handle_rep class |
9e507e30c9ea
keep a copy of user+password data for older cURL libraries
John W. Eaton <jwe@octave.org>
parents:
17598
diff
changeset
|
664 // contains the pointer to the CURL handle and so is the best |
9e507e30c9ea
keep a copy of user+password data for older cURL libraries
John W. Eaton <jwe@octave.org>
parents:
17598
diff
changeset
|
665 // candidate for storing the strings as well. (bug #36717) |
17614
ce7b9abf6600
Keep a copy of url string for older cURL libraries
Mike Miller <mtmiller@ieee.org>
parents:
17601
diff
changeset
|
666 std::string url; |
17601
9e507e30c9ea
keep a copy of user+password data for older cURL libraries
John W. Eaton <jwe@octave.org>
parents:
17598
diff
changeset
|
667 std::string userpwd; |
9e507e30c9ea
keep a copy of user+password data for older cURL libraries
John W. Eaton <jwe@octave.org>
parents:
17598
diff
changeset
|
668 |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
669 // No copying! |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
670 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
671 curl_transfer (const curl_transfer&); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
672 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
673 curl_transfer& operator = (const curl_transfer&); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
674 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
675 void init (const std::string& user, const std::string& passwd, |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
676 std::istream& is, std::ostream& os) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
677 { |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
678 // No data transfer by default |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
679 SETOPT (CURLOPT_NOBODY, 1); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
680 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
681 // Set the username and password |
17601
9e507e30c9ea
keep a copy of user+password data for older cURL libraries
John W. Eaton <jwe@octave.org>
parents:
17598
diff
changeset
|
682 userpwd = user; |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
683 if (! passwd.empty ()) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
684 userpwd += ":" + passwd; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
685 if (! userpwd.empty ()) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
686 SETOPT (CURLOPT_USERPWD, userpwd.c_str ()); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
687 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
688 // Define our callback to get called when there's data to be written. |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
689 SETOPT (CURLOPT_WRITEFUNCTION, write_data); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
690 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
691 // Set a pointer to our struct to pass to the callback. |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
692 SETOPT (CURLOPT_WRITEDATA, static_cast<void*> (&os)); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
693 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
694 // Define our callback to get called when there's data to be read |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
695 SETOPT (CURLOPT_READFUNCTION, read_data); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
696 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
697 // Set a pointer to our struct to pass to the callback. |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
698 SETOPT (CURLOPT_READDATA, static_cast<void*> (&is)); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
699 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
700 // Follow redirects. |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
701 SETOPT (CURLOPT_FOLLOWLOCATION, true); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
702 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
703 // Don't use EPSV since connecting to sites that don't support it |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
704 // will hang for some time (3 minutes?) before moving on to try PASV |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
705 // instead. |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
706 SETOPT (CURLOPT_FTP_USE_EPSV, false); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
707 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
708 SETOPT (CURLOPT_NOPROGRESS, true); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
709 SETOPT (CURLOPT_FAILONERROR, true); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
710 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
711 SETOPT (CURLOPT_POSTQUOTE, 0); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
712 SETOPT (CURLOPT_QUOTE, 0); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
713 } |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
714 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
715 std::string form_query_string (const Array<std::string>& param) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
716 { |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
717 std::ostringstream query; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
718 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
719 for (int i = 0; i < param.numel (); i += 2) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
720 { |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
721 std::string name = param(i); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
722 std::string text = param(i+1); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
723 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
724 // Encode strings. |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
725 char *enc_name = curl_easy_escape (curl, name.c_str (), |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
726 name.length ()); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
727 char *enc_text = curl_easy_escape (curl, text.c_str (), |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
728 text.length ()); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
729 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
730 query << enc_name << "=" << enc_text; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
731 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
732 curl_free (enc_name); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
733 curl_free (enc_text); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
734 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
735 if (i < param.numel ()-1) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
736 query << "&"; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
737 } |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
738 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
739 query.flush (); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
740 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
741 return query.str (); |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
742 } |
17595
4b65355a31f2
avoid some code duplication in url-transfer ftp methods
John W. Eaton <jwe@octave.org>
parents:
17563
diff
changeset
|
743 |
4b65355a31f2
avoid some code duplication in url-transfer ftp methods
John W. Eaton <jwe@octave.org>
parents:
17563
diff
changeset
|
744 void ftp_file_or_dir_action (const std::string& file_or_dir, |
4b65355a31f2
avoid some code duplication in url-transfer ftp methods
John W. Eaton <jwe@octave.org>
parents:
17563
diff
changeset
|
745 const std::string& action) |
4b65355a31f2
avoid some code duplication in url-transfer ftp methods
John W. Eaton <jwe@octave.org>
parents:
17563
diff
changeset
|
746 { |
4b65355a31f2
avoid some code duplication in url-transfer ftp methods
John W. Eaton <jwe@octave.org>
parents:
17563
diff
changeset
|
747 struct curl_slist *slist = 0; |
4b65355a31f2
avoid some code duplication in url-transfer ftp methods
John W. Eaton <jwe@octave.org>
parents:
17563
diff
changeset
|
748 |
4b65355a31f2
avoid some code duplication in url-transfer ftp methods
John W. Eaton <jwe@octave.org>
parents:
17563
diff
changeset
|
749 unwind_protect frame; |
4b65355a31f2
avoid some code duplication in url-transfer ftp methods
John W. Eaton <jwe@octave.org>
parents:
17563
diff
changeset
|
750 |
4b65355a31f2
avoid some code duplication in url-transfer ftp methods
John W. Eaton <jwe@octave.org>
parents:
17563
diff
changeset
|
751 frame.add_fcn (curl_slist_free_all, slist); |
4b65355a31f2
avoid some code duplication in url-transfer ftp methods
John W. Eaton <jwe@octave.org>
parents:
17563
diff
changeset
|
752 |
4b65355a31f2
avoid some code duplication in url-transfer ftp methods
John W. Eaton <jwe@octave.org>
parents:
17563
diff
changeset
|
753 std::string cmd = action + " " + file_or_dir; |
4b65355a31f2
avoid some code duplication in url-transfer ftp methods
John W. Eaton <jwe@octave.org>
parents:
17563
diff
changeset
|
754 |
4b65355a31f2
avoid some code duplication in url-transfer ftp methods
John W. Eaton <jwe@octave.org>
parents:
17563
diff
changeset
|
755 slist = curl_slist_append (slist, cmd.c_str ()); |
4b65355a31f2
avoid some code duplication in url-transfer ftp methods
John W. Eaton <jwe@octave.org>
parents:
17563
diff
changeset
|
756 |
4b65355a31f2
avoid some code duplication in url-transfer ftp methods
John W. Eaton <jwe@octave.org>
parents:
17563
diff
changeset
|
757 SETOPT (CURLOPT_POSTQUOTE, slist); |
4b65355a31f2
avoid some code duplication in url-transfer ftp methods
John W. Eaton <jwe@octave.org>
parents:
17563
diff
changeset
|
758 |
4b65355a31f2
avoid some code duplication in url-transfer ftp methods
John W. Eaton <jwe@octave.org>
parents:
17563
diff
changeset
|
759 perform (); |
4b65355a31f2
avoid some code duplication in url-transfer ftp methods
John W. Eaton <jwe@octave.org>
parents:
17563
diff
changeset
|
760 |
4b65355a31f2
avoid some code duplication in url-transfer ftp methods
John W. Eaton <jwe@octave.org>
parents:
17563
diff
changeset
|
761 if (! good ()) |
4b65355a31f2
avoid some code duplication in url-transfer ftp methods
John W. Eaton <jwe@octave.org>
parents:
17563
diff
changeset
|
762 return; |
4b65355a31f2
avoid some code duplication in url-transfer ftp methods
John W. Eaton <jwe@octave.org>
parents:
17563
diff
changeset
|
763 |
4b65355a31f2
avoid some code duplication in url-transfer ftp methods
John W. Eaton <jwe@octave.org>
parents:
17563
diff
changeset
|
764 SETOPT (CURLOPT_POSTQUOTE, 0); |
4b65355a31f2
avoid some code duplication in url-transfer ftp methods
John W. Eaton <jwe@octave.org>
parents:
17563
diff
changeset
|
765 } |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
766 }; |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
767 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
768 #undef SETOPT |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
769 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
770 #endif |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
771 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
772 #if defined (HAVE_CURL) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
773 # define REP_CLASS curl_transfer |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
774 #else |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
775 # define REP_CLASS base_url_transfer |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
776 #endif |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
777 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
778 url_transfer::url_transfer (void) : rep (new REP_CLASS ()) |
18312
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
779 { } |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
780 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
781 url_transfer::url_transfer (const std::string& host, const std::string& user, |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
782 const std::string& passwd, std::ostream& os) |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
783 : rep (new REP_CLASS (host, user, passwd, os)) |
18312
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
784 { } |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
785 |
17596
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
786 url_transfer::url_transfer (const std::string& url, std::ostream& os) |
43b9181340fb
separate object creation from http actions in url_transfer class
John W. Eaton <jwe@octave.org>
parents:
17595
diff
changeset
|
787 : rep (new REP_CLASS (url, os)) |
18312
9a43d8d6e29e
avoid startup crash if curl library is not available (bug #41067)
John W. Eaton <jwe@octave.org>
parents:
17861
diff
changeset
|
788 { } |
17555
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
789 |
0946b0e06544
move url_transfer classes to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
790 #undef REP_CLASS |