fetchMakeURL fetchParseURL fetchFreeURL fetchXGetURL fetchGetURL fetchPutURL fetchStatURL fetchListURL fetchXGet fetchGet fetchPut fetchStat fetchList fetchXGetFile fetchGetFile fetchPutFile fetchStatFile fetchListFile fetchXGetHTTP fetchGetHTTP fetchPutHTTP fetchStatHTTP fetchListHTTP fetchXGetFTP fetchGetFTP fetchPutFTP fetchStatFTP fetchListFTP - file transfer functions
Lb libfetch
fetchParseURL ();
takes a URL in the form of a null-terminated string and splits it into
its components function according to the Common Internet Scheme Syntax
detailed in RFC1738.
A regular expression which produces this syntax is:
<scheme>:(//(<user>(:<pwd>)?@)?<host>(:<port>)?)?/(<document>)?
If the URL does not seem to begin with a scheme name, the following syntax is assumed:
((<user>(:<pwd>)?@)?<host>(:<port>)?)?/(<document>)?
Note that some components of the URL are not necessarily relevant to all URL schemes. For instance, the file scheme only needs the <scheme> and <document> components.
fetchMakeURL ();
and
fetchParseURL ();
return a pointer to a
Vt url
structure, which is defined as follows in
In fetch.h :
#define URL_SCHEMELEN 16 #define URL_USERLEN 256 #define URL_PWDLEN 256 struct url { char scheme[URL_SCHEMELEN+1]; char user[URL_USERLEN+1]; char pwd[URL_PWDLEN+1]; char host[MAXHOSTNAMELEN+1]; int port; char *doc; off_t offset; size_t length; };
The pointer returned by
fetchMakeURL ();
or
fetchParseURL ();
should be freed using
fetchFreeURL (.);
fetchXGetURL (,);
fetchGetURL (,);
and
fetchPutURL ();
constitute the recommended interface to the
fetch
library.
They examine the URL passed to them to determine the transfer
method, and call the appropriate lower-level functions to perform the
actual transfer.
fetchXGetURL ();
also returns the remote document's metadata in the
Vt url_stat
structure pointed to by the
Fa us
argument.
The Fa flags argument is a string of characters which specify transfer options. The meaning of the individual flags is scheme-dependent, and is detailed in the appropriate section below.
fetchStatURL ();
attempts to obtain the requested document's metadata and fill in the
structure pointed to by its second argument.
The
Vt url_stat
structure is defined as follows in
In fetch.h :
struct url_stat { off_t size; time_t atime; time_t mtime; };
If the size could not be obtained from the server, the Fa size field is set to -1. If the modification time could not be obtained from the server, the Fa mtime field is set to the epoch. If the access time could not be obtained from the server, the Fa atime field is set to the modification time.
fetchListURL ();
attempts to list the contents of the directory pointed to by the URL
provided.
If successful, it returns a malloced array of
Vt url_ent
structures.
The
Vt url_ent
structure is defined as follows in
In fetch.h :
struct url_ent { char name[PATH_MAX]; struct url_stat stat; };
The list is terminated by an entry with an empty name.
The pointer returned by
fetchListURL ();
should be freed using
free (.);
fetchXGet (,);
fetchGet (,);
fetchPut ();
and
fetchStat ();
are similar to
fetchXGetURL (,);
fetchGetURL (,);
fetchPutURL ();
and
fetchStatURL (,);
except that they expect a pre-parsed URL in the form of a pointer to
a
Vt struct url
rather than a string.
All of the
fetchXGetXXX (,);
fetchGetXXX ();
and
fetchPutXXX ();
functions return a pointer to a stream which can be used to read or
write data from or to the requested document, respectively.
Note that
although the implementation details of the individual access methods
vary, it can generally be assumed that a stream returned by one of the
fetchXGetXXX ();
or
fetchGetXXX ();
functions is read-only, and that a stream returned by one of the
fetchPutXXX ();
functions is write-only.
fetchXGetFile ();
and
fetchGetFile ();
do not accept any flags.
fetchPutFile ();
accepts the
`a'
(append to file) flag.
If that flag is specified, the data written to
the stream returned by
fetchPutFile ();
will be appended to the previous contents of the file, instead of
replacing them.
If the `p' (passive) flag is specified, a passive (rather than active) connection will be attempted.
If the `l' (low) flag is specified, data sockets will be allocated in the low (or default) port range instead of the high port range (see ip(4)).
If the
`d'
(direct) flag is specified,
fetchXGetFTP (,);
fetchGetFTP ();
and
fetchPutFTP ();
will use a direct connection even if a proxy server is defined.
If no user name or password is given, the fetch library will attempt an anonymous login, with user name "anonymous" and password "anonymous@<hostname>".
If the
`d'
(direct) flag is specified,
fetchXGetHTTP (,);
fetchGetHTTP ();
and
fetchPutHTTP ();
will use a direct connection even if a proxy server is defined.
Since there seems to be no good way of implementing the HTTP PUT
method in a manner consistent with the rest of the
fetch
library,
fetchPutHTTP ();
is currently unimplemented.
int
myAuthMethod (struct url *u);
The callback function should fill in the Fa user and Fa pwd fields in the provided Vt struct url and return 0 on success, or any other value to indicate failure.
To register the authentication callback, simply set fetchAuthMethod to point at it. The callback will be used whenever a site requires authentication and the appropriate environment variables are not set.
This interface is experimental and may be subject to change.
The
fetchStat ();
functions return 0 on success and -1 on failure.
All other functions return a stream pointer which may be used to access the requested document, or NULL if an error occurred.
The following error codes are defined in In fetch.h :
The accompanying error message includes a protocol-specific error code and message, e.g. "File is not available (404 Not Found)"
If this variable is set to an empty string, no proxy will be used for FTP requests, even if the HTTP_PROXY variable is set.
Basic authorization requires two parameters: the user name and password, in that order.
This variable is only used if the server requires authorization and no user name or password was specified in the URL.
Note that this proxy will also be used for FTP documents, unless the FTP_PROXY variable is set.
This variable is used if and only if connected to an HTTP proxy, and is ignored if a user and/or a password were specified in the proxy URL.
HTTP_PROXY=http://proxy.example.com:8080
If the proxy server requires authentication, there are two options available for passing the authentication data. The first method is by using the proxy URL:
HTTP_PROXY=http://<user>:<pwd>@proxy.example.com:8080
The second method is by using the HTTP_PROXY_AUTH environment variable:
HTTP_PROXY=http://proxy.example.com:8080 HTTP_PROXY_AUTH=basic:*:<user>:<pwd>
To disable the use of a proxy for an HTTP server running on the local host, define NO_PROXY as follows:
NO_PROXY=localhost,127.0.0.1
This manual page was written by An Dag-Erling Sm/orgrav Aq des@FreeBSD.org .
There is no way to select a proxy at run-time other than setting the HTTP_PROXY or FTP_PROXY environment variables as appropriate.
libfetch does not understand or obey 305 (Use Proxy) replies.
Error numbers are unique only within a certain context; the error codes used for FTP and HTTP overlap, as do those used for resolver and system errors. For instance, error code 202 means "Command not implemented, superfluous at this site" in an FTP context and "Accepted" in an HTTP context.
fetchStatFTP ();
does not check that the result of an MDTM command is a valid date.
The man page is incomplete, poorly written and produces badly formatted text.
The error reporting mechanism is unsatisfactory.
Some parts of the code are not fully reentrant.
Закладки на сайте Проследить за страницей |
Created 1996-2024 by Maxim Chirkov Добавить, Поддержать, Вебмастеру |