28 #if defined (HAVE_CONFIG_H)
68 : handle_map (), handle_free_list (),
69 next_handle (-1.0 - (rand () + 1.0) / (RAND_MAX + 2.0)) { }
73 static void create_instance (
void);
83 error (
"unable to create ch_manager!");
92 return instance_ok () ? instance->do_get_handle () :
curl_handle ();
98 instance->do_free (h);
103 return instance_ok () ? instance->do_lookup (val) :
curl_handle ();
114 return get_object (
lookup (val));
119 return get_object (
lookup (val));
132 return instance_ok ()
133 ? instance->do_make_curl_handle (host, user, passwd, os)
139 return instance_ok () ? instance->do_handle_list () :
Matrix ();
146 typedef std::map<curl_handle, octave::url_transfer>::iterator
iterator;
147 typedef std::map<curl_handle, octave::url_transfer>::const_iterator
const_iterator;
169 return (p != handle_map.end ()) ? p->first :
curl_handle ();
174 iterator
p = (h.
ok () ? handle_map.find (h) : handle_map.end ());
189 error (
"support for URL transfers was disabled when Octave was built");
201 for (const_iterator
p = handle_map.begin ();
p != handle_map.end ();
p++)
224 static double maxrand = RAND_MAX + 2.0;
226 return (rand () + 1.0) / maxrand;
263 error (
"ch_manager::free: invalid object %g", h.
value ());
334 if (nargin != 2 && nargin != 4)
347 method =
args(2).xstring_value (
"urlwrite: METHOD must be a string");
349 if (method !=
"get" && method !=
"post")
350 error (
"urlwrite: METHOD must be \"get\" or \"post\"");
352 param =
args(3).xcellstr_value (
"urlwrite: parameters (PARAM) for get and post requests must be given as a cell array of strings");
354 if (param.
numel () % 2 == 1)
355 error (
"urlwrite: number of elements in PARAM must be even");
364 std::ofstream
ofile (filename.c_str (), std::ios::out | std::ios::binary);
367 error (
"urlwrite: unable to open file");
378 error (
"support for URL transfers was disabled when Octave was built");
445 int nargin =
args.length ();
448 if (nargin != 1 && nargin != 3)
451 std::string url =
args(0).xstring_value (
"urlread: URL must be a string");
458 method =
args(1).xstring_value (
"urlread: METHOD must be a string");
460 if (method !=
"get" && method !=
"post")
461 error (
"urlread: METHOD must be \"get\" or \"post\"");
463 param =
args(2).xcellstr_value (
"urlread: parameters (PARAM) for get and post requests must be given as a cell array of strings");
465 if (param.
numel () % 2 == 1)
466 error (
"urlread: number of elements in PARAM must be even");
469 std::ostringstream buf;
474 error (
"support for URL transfers was disabled when Octave was built");
483 retval =
ovl (buf.str (), curl.
good (),
500 int nargin =
args.length ();
502 if (nargin < 1 || nargin > 3)
505 std::string host =
args(0).xstring_value (
"__ftp__: HOST must be a string");
508 ?
args(1).xstring_value (
"__ftp__: USER must be a string")
512 ?
args(2).xstring_value (
"__ftp__: PASSWD must be a string")
527 if (
args.length () != 1)
528 error (
"__ftp_pwd__: incorrect number of arguments");
533 error (
"__ftp_pwd__: invalid ftp handle");
544 int nargin =
args.length ();
546 if (nargin != 1 && nargin != 2)
547 error (
"__ftp_cwd__: incorrect number of arguments");
551 path =
args(1).xstring_value (
"__ftp_cwd__: PATH must be a string");
556 error (
"__ftp_cwd__: invalid ftp handle");
569 if (
args.length () != 1)
570 error (
"__ftp_dir__: incorrect number of arguments");
575 error (
"__ftp_dir__: invalid ftp handle");
617 fileisdir (
i) = fisdir;
618 filectime (
i) = ctime (&ftime);
619 filesize (
i) = fsize;
620 filedatenum (
i) =
double (ftime);
623 st.
assign (
"date", filectime);
624 st.
assign (
"bytes", filesize);
625 st.
assign (
"isdir", fileisdir);
626 st.
assign (
"datenum", filedatenum);
641 if (
args.length () != 1)
642 error (
"__ftp_ascii__: incorrect number of arguments");
647 error (
"__ftp_ascii__: invalid ftp handle");
660 if (
args.length () != 1)
661 error (
"__ftp_binary__: incorrect number of arguments");
666 error (
"__ftp_binary__: invalid ftp handle");
679 if (
args.length () != 1)
680 error (
"__ftp_close__: incorrect number of arguments");
685 error (
"__ftp_close__: invalid ftp handle");
698 if (
args.length () != 1)
699 error (
"__ftp_mode__: incorrect number of arguments");
704 error (
"__ftp_binary__: invalid ftp handle");
706 return ovl (curl.
is_ascii () ?
"ascii" :
"binary");
715 if (
args.length () != 2)
716 error (
"__ftp_delete__: incorrect number of arguments");
723 error (
"__ftp_delete__: invalid ftp handle");
736 if (
args.length () != 2)
737 error (
"__ftp_rmdir__: incorrect number of arguments");
739 std::string dir =
args(1).xstring_value (
"__ftp_rmdir__: DIR must be a string");
744 error (
"__ftp_rmdir__: invalid ftp handle");
757 if (
args.length () != 2)
758 error (
"__ftp_mkdir__: incorrect number of arguments");
760 std::string dir =
args(1).xstring_value (
"__ftp_mkdir__: DIR must be a string");
765 error (
"__ftp_mkdir__: invalid ftp handle");
778 if (
args.length () != 3)
779 error (
"__ftp_rename__: incorrect number of arguments");
781 std::string oldname =
args(1).xstring_value (
"__ftp_rename__: OLDNAME must be a string");
782 std::string newname =
args(2).xstring_value (
"__ftp_rename__: NEWNAME must be a string");
787 error (
"__ftp_rename__: invalid ftp handle");
789 curl.
rename (oldname, newname);
800 if (
args.length () != 2)
801 error (
"__ftp_mput__: incorrect number of arguments");
803 std::string pat =
args(1).xstring_value (
"__ftp_mput__: PATTERN must be a string");
808 error (
"__ftp_mput__: invalid ftp handle");
822 error (
"__ftp__mput: file does not exist");
834 std::ifstream ifile (file.c_str (), std::ios::in | std::ios::binary);
836 if (! ifile.is_open ())
837 error (
"__ftp_mput__: unable to open file");
839 curl.
put (file, ifile);
851 return ovl (file_list);
863 int nargin =
args.length ();
865 if (nargin != 2 && nargin != 3)
866 error (
"__ftp_mget__: incorrect number of arguments");
872 if (nargin == 3 && !
args(2).is_empty ())
878 error (
"__ftp_mget__: invalid ftp handle");
886 if (pattern.
match (sv(
i)))
900 std::ofstream
ofile ((target + sv(
i)).c_str (),
904 if (! ofile.is_open ())
905 error (
"__ftp_mget__: unable to open file");
911 curl.
get (sv(
i), ofile);
925 error (
"__ftp_mget__: file not found");
static std::string dir_sep_str(void)
For example cd octave end example noindent changes the current working directory to file
void assign(const std::string &k, const Cell &val)
static octave::url_transfer get_object(const octave_value &val)
OCTAVE_EXPORT octave_value_list isa nd deftypefn *return ovl(args(0).is_integer_type())
int unlink(const std::string &name)
OCTINTERP_API void print_usage(void)
void mkdir(const std::string &path)
octave_idx_type numel(void) const
Number of elements in the array.
curl_handle do_lookup(double val)
static ch_manager * instance
identity matrix If supplied two scalar respectively For allows like xample val
void rename(const std::string &oldname, const std::string &newname)
bool is_ascii(void) const
bool is_valid(void) const
static Matrix handle_list(void)
#define DEFUN(name, args_name, nargout_name, doc)
void error(const char *fmt,...)
octave_idx_type lookup(const T *x, octave_idx_type n, T y)
std::map< curl_handle, octave::url_transfer >::iterator iterator
static octave::url_transfer get_object(double val)
void put(const std::string &file, std::istream &is)
static double make_handle_fraction(void)
curl_handle do_get_handle(void)
static std::string tilde_expand(const std::string &)
octave_handle curl_handle
std::set< curl_handle >::const_iterator const_free_list_iterator
void mget_directory(const std::string &directory, const std::string &target)
std::map< curl_handle, octave::url_transfer >::const_iterator const_iterator
static octave::url_transfer get_object(const curl_handle &h)
static std::string make_absolute(const std::string &s, const std::string &dot_path=get_current_directory())
static curl_handle make_curl_handle(const std::string &host, const std::string &user, const std::string &passwd, std::ostream &os)
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function xample nargout(@histc)
void add_fcn(void(*fcn)(void))
static bool instance_ok(void)
bool is_real_scalar(void) const
string_vector mput_directory(const std::string &base, const std::string &directory)
static void create_instance(void)
std::string lasterror(void) const
std::set< curl_handle > handle_free_list
static curl_handle lookup(const octave_value &val)
static void cleanup_instance(void)
string_vector & append(const std::string &s)
void do_free(const curl_handle &h)
void rmdir(const std::string &path)
bool match(const std::string &str) const
void get_fileinfo(const std::string &filename, double &filesize, time_t &filetime, bool &fileisdir)
std::map< curl_handle, octave::url_transfer > handle_map
Array< std::string > param
static curl_handle get_handle(void)
std::set< curl_handle >::iterator free_list_iterator
octave::url_transfer do_get_object(const curl_handle &h)
void get(const std::string &file, std::ostream &os)
octave::unwind_protect frame
std::ofstream ofile(filename.c_str(), std::ios::out|std::ios::binary)
static curl_handle lookup(double val)
void cwd(const std::string &path)
void http_action(const Array< std::string > ¶m, const std::string &action)
void del(const std::string &file)
otherwise an error message is printed The permission mask is a UNIX concept used when creating new objects on a file system such as files
=val(i)}if ode{val(i)}occurs in table i
is longer than or if then or only for unique occurrences of the complete pattern(false).The default is true.If a cell array of strings ar
static void delete_file(const std::string &file)
issues an error eealso double
static void free(const curl_handle &h)
octave::sys::file_stat fs(filename)
double double_value(bool frc_str_conv=false) const
curl_handle do_make_curl_handle(const std::string &host, const std::string &user, const std::string &passwd, std::ostream &os)
Vector representing the dimensions (size) of an Array.
Matrix do_handle_list(void)
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
string_vector glob(void) const