xref: /netbsd-src/share/examples/refuse/ian/libfetch/fetch.3 (revision a5684d07ddc9ba0c28f245cf19fda4c06a613e76)
10920b4f2Sagc.\"-
20920b4f2Sagc.\" Copyright (c) 1998-2004 Dag-Erling Co�dan Sm�rgrav
30920b4f2Sagc.\" All rights reserved.
40920b4f2Sagc.\"
50920b4f2Sagc.\" Redistribution and use in source and binary forms, with or without
60920b4f2Sagc.\" modification, are permitted provided that the following conditions
70920b4f2Sagc.\" are met:
80920b4f2Sagc.\" 1. Redistributions of source code must retain the above copyright
90920b4f2Sagc.\"    notice, this list of conditions and the following disclaimer.
100920b4f2Sagc.\" 2. Redistributions in binary form must reproduce the above copyright
110920b4f2Sagc.\"    notice, this list of conditions and the following disclaimer in the
120920b4f2Sagc.\"    documentation and/or other materials provided with the distribution.
130920b4f2Sagc.\"
140920b4f2Sagc.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
150920b4f2Sagc.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
160920b4f2Sagc.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
170920b4f2Sagc.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
180920b4f2Sagc.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
190920b4f2Sagc.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
200920b4f2Sagc.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
210920b4f2Sagc.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
220920b4f2Sagc.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
230920b4f2Sagc.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
240920b4f2Sagc.\" SUCH DAMAGE.
250920b4f2Sagc.\"
260920b4f2Sagc.\" $FreeBSD: src/lib/libfetch/fetch.3,v 1.63 2007/05/24 20:28:14 des Exp $
270920b4f2Sagc.\"
280920b4f2Sagc.Dd April 22, 2007
290920b4f2Sagc.Dt FETCH 3
300920b4f2Sagc.Os
310920b4f2Sagc.Sh NAME
320920b4f2Sagc.Nm fetchMakeURL ,
330920b4f2Sagc.Nm fetchParseURL ,
340920b4f2Sagc.Nm fetchFreeURL ,
350920b4f2Sagc.Nm fetchXGetURL ,
360920b4f2Sagc.Nm fetchGetURL ,
370920b4f2Sagc.Nm fetchPutURL ,
380920b4f2Sagc.Nm fetchStatURL ,
390920b4f2Sagc.Nm fetchListURL ,
400920b4f2Sagc.Nm fetchXGet ,
410920b4f2Sagc.Nm fetchGet ,
420920b4f2Sagc.Nm fetchPut ,
430920b4f2Sagc.Nm fetchStat ,
440920b4f2Sagc.Nm fetchList ,
450920b4f2Sagc.Nm fetchXGetFile ,
460920b4f2Sagc.Nm fetchGetFile ,
470920b4f2Sagc.Nm fetchPutFile ,
480920b4f2Sagc.Nm fetchStatFile ,
490920b4f2Sagc.Nm fetchListFile ,
500920b4f2Sagc.Nm fetchXGetHTTP ,
510920b4f2Sagc.Nm fetchGetHTTP ,
520920b4f2Sagc.Nm fetchPutHTTP ,
530920b4f2Sagc.Nm fetchStatHTTP ,
540920b4f2Sagc.Nm fetchListHTTP ,
550920b4f2Sagc.Nm fetchXGetFTP ,
560920b4f2Sagc.Nm fetchGetFTP ,
570920b4f2Sagc.Nm fetchPutFTP ,
580920b4f2Sagc.Nm fetchStatFTP ,
590920b4f2Sagc.Nm fetchListFTP
600920b4f2Sagc.Nd file transfer functions
610920b4f2Sagc.Sh LIBRARY
620920b4f2Sagc.Lb libfetch
630920b4f2Sagc.Sh SYNOPSIS
640920b4f2Sagc.In sys/param.h
650920b4f2Sagc.In stdio.h
660920b4f2Sagc.In fetch.h
670920b4f2Sagc.Ft struct url *
680920b4f2Sagc.Fn fetchMakeURL "const char *scheme" "const char *host" "int port" "const char *doc" "const char *user" "const char *pwd"
690920b4f2Sagc.Ft struct url *
700920b4f2Sagc.Fn fetchParseURL "const char *URL"
710920b4f2Sagc.Ft void
720920b4f2Sagc.Fn fetchFreeURL "struct url *u"
730920b4f2Sagc.Ft FILE *
740920b4f2Sagc.Fn fetchXGetURL "const char *URL" "struct url_stat *us" "const char *flags"
750920b4f2Sagc.Ft FILE *
760920b4f2Sagc.Fn fetchGetURL "const char *URL" "const char *flags"
770920b4f2Sagc.Ft FILE *
780920b4f2Sagc.Fn fetchPutURL "const char *URL" "const char *flags"
790920b4f2Sagc.Ft int
800920b4f2Sagc.Fn fetchStatURL "const char *URL" "struct url_stat *us" "const char *flags"
810920b4f2Sagc.Ft struct url_ent *
820920b4f2Sagc.Fn fetchListURL "const char *URL" "const char *flags"
830920b4f2Sagc.Ft FILE *
840920b4f2Sagc.Fn fetchXGet "struct url *u" "struct url_stat *us" "const char *flags"
850920b4f2Sagc.Ft FILE *
860920b4f2Sagc.Fn fetchGet "struct url *u" "const char *flags"
870920b4f2Sagc.Ft FILE *
880920b4f2Sagc.Fn fetchPut "struct url *u" "const char *flags"
890920b4f2Sagc.Ft int
900920b4f2Sagc.Fn fetchStat "struct url *u" "struct url_stat *us" "const char *flags"
910920b4f2Sagc.Ft struct url_ent *
920920b4f2Sagc.Fn fetchList "struct url *u" "const char *flags"
930920b4f2Sagc.Ft FILE *
940920b4f2Sagc.Fn fetchXGetFile "struct url *u" "struct url_stat *us" "const char *flags"
950920b4f2Sagc.Ft FILE *
960920b4f2Sagc.Fn fetchGetFile "struct url *u" "const char *flags"
970920b4f2Sagc.Ft FILE *
980920b4f2Sagc.Fn fetchPutFile "struct url *u" "const char *flags"
990920b4f2Sagc.Ft int
1000920b4f2Sagc.Fn fetchStatFile "struct url *u" "struct url_stat *us" "const char *flags"
1010920b4f2Sagc.Ft struct url_ent *
1020920b4f2Sagc.Fn fetchListFile "struct url *u" "const char *flags"
1030920b4f2Sagc.Ft FILE *
1040920b4f2Sagc.Fn fetchXGetHTTP "struct url *u" "struct url_stat *us" "const char *flags"
1050920b4f2Sagc.Ft FILE *
1060920b4f2Sagc.Fn fetchGetHTTP "struct url *u" "const char *flags"
1070920b4f2Sagc.Ft FILE *
1080920b4f2Sagc.Fn fetchPutHTTP "struct url *u" "const char *flags"
1090920b4f2Sagc.Ft int
1100920b4f2Sagc.Fn fetchStatHTTP "struct url *u" "struct url_stat *us" "const char *flags"
1110920b4f2Sagc.Ft struct url_ent *
1120920b4f2Sagc.Fn fetchListHTTP "struct url *u" "const char *flags"
1130920b4f2Sagc.Ft FILE *
1140920b4f2Sagc.Fn fetchXGetFTP "struct url *u" "struct url_stat *us" "const char *flags"
1150920b4f2Sagc.Ft FILE *
1160920b4f2Sagc.Fn fetchGetFTP "struct url *u" "const char *flags"
1170920b4f2Sagc.Ft FILE *
1180920b4f2Sagc.Fn fetchPutFTP "struct url *u" "const char *flags"
1190920b4f2Sagc.Ft int
1200920b4f2Sagc.Fn fetchStatFTP "struct url *u" "struct url_stat *us" "const char *flags"
1210920b4f2Sagc.Ft struct url_ent *
1220920b4f2Sagc.Fn fetchListFTP "struct url *u" "const char *flags"
1230920b4f2Sagc.Sh DESCRIPTION
1240920b4f2SagcThese functions implement a high-level library for retrieving and
1250920b4f2Sagcuploading files using Uniform Resource Locators (URLs).
1260920b4f2Sagc.Pp
1270920b4f2Sagc.Fn fetchParseURL
1280920b4f2Sagctakes a URL in the form of a null-terminated string and splits it into
1290920b4f2Sagcits components function according to the Common Internet Scheme Syntax
1300920b4f2Sagcdetailed in RFC1738.
1310920b4f2SagcA regular expression which produces this syntax is:
1320920b4f2Sagc.Bd -literal
1330920b4f2Sagc    <scheme>:(//(<user>(:<pwd>)?@)?<host>(:<port>)?)?/(<document>)?
1340920b4f2Sagc.Ed
1350920b4f2Sagc.Pp
1360920b4f2SagcIf the URL does not seem to begin with a scheme name, the following
1370920b4f2Sagcsyntax is assumed:
1380920b4f2Sagc.Bd -literal
1390920b4f2Sagc    ((<user>(:<pwd>)?@)?<host>(:<port>)?)?/(<document>)?
1400920b4f2Sagc.Ed
1410920b4f2Sagc.Pp
1420920b4f2SagcNote that some components of the URL are not necessarily relevant to
1430920b4f2Sagcall URL schemes.
1440920b4f2SagcFor instance, the file scheme only needs the <scheme> and <document>
1450920b4f2Sagccomponents.
1460920b4f2Sagc.Pp
1470920b4f2Sagc.Fn fetchMakeURL
1480920b4f2Sagcand
1490920b4f2Sagc.Fn fetchParseURL
1500920b4f2Sagcreturn a pointer to a
1510920b4f2Sagc.Vt url
1520920b4f2Sagcstructure, which is defined as follows in
1530920b4f2Sagc.In fetch.h :
1540920b4f2Sagc.Bd -literal
1550920b4f2Sagc#define URL_SCHEMELEN 16
1560920b4f2Sagc#define URL_USERLEN 256
1570920b4f2Sagc#define URL_PWDLEN 256
1580920b4f2Sagc
1590920b4f2Sagcstruct url {
1600920b4f2Sagc    char	 scheme[URL_SCHEMELEN+1];
1610920b4f2Sagc    char	 user[URL_USERLEN+1];
1620920b4f2Sagc    char	 pwd[URL_PWDLEN+1];
1630920b4f2Sagc    char	 host[MAXHOSTNAMELEN+1];
1640920b4f2Sagc    int		 port;
1650920b4f2Sagc    char	*doc;
1660920b4f2Sagc    off_t	 offset;
1670920b4f2Sagc    size_t	 length;
1680920b4f2Sagc};
1690920b4f2Sagc.Ed
1700920b4f2Sagc.Pp
1710920b4f2SagcThe pointer returned by
1720920b4f2Sagc.Fn fetchMakeURL
1730920b4f2Sagcor
1740920b4f2Sagc.Fn fetchParseURL
1750920b4f2Sagcshould be freed using
1760920b4f2Sagc.Fn fetchFreeURL .
1770920b4f2Sagc.Pp
1780920b4f2Sagc.Fn fetchXGetURL ,
1790920b4f2Sagc.Fn fetchGetURL ,
1800920b4f2Sagcand
1810920b4f2Sagc.Fn fetchPutURL
1820920b4f2Sagcconstitute the recommended interface to the
1830920b4f2Sagc.Nm fetch
1840920b4f2Sagclibrary.
1850920b4f2SagcThey examine the URL passed to them to determine the transfer
1860920b4f2Sagcmethod, and call the appropriate lower-level functions to perform the
1870920b4f2Sagcactual transfer.
1880920b4f2Sagc.Fn fetchXGetURL
1890920b4f2Sagcalso returns the remote document's metadata in the
1900920b4f2Sagc.Vt url_stat
1910920b4f2Sagcstructure pointed to by the
1920920b4f2Sagc.Fa us
1930920b4f2Sagcargument.
1940920b4f2Sagc.Pp
1950920b4f2SagcThe
1960920b4f2Sagc.Fa flags
1970920b4f2Sagcargument is a string of characters which specify transfer options.
1980920b4f2SagcThe
1990920b4f2Sagcmeaning of the individual flags is scheme-dependent, and is detailed
2000920b4f2Sagcin the appropriate section below.
2010920b4f2Sagc.Pp
2020920b4f2Sagc.Fn fetchStatURL
2030920b4f2Sagcattempts to obtain the requested document's metadata and fill in the
2040920b4f2Sagcstructure pointed to by its second argument.
2050920b4f2SagcThe
2060920b4f2Sagc.Vt url_stat
2070920b4f2Sagcstructure is defined as follows in
2080920b4f2Sagc.In fetch.h :
2090920b4f2Sagc.Bd -literal
2100920b4f2Sagcstruct url_stat {
2110920b4f2Sagc    off_t	 size;
2120920b4f2Sagc    time_t	 atime;
2130920b4f2Sagc    time_t	 mtime;
2140920b4f2Sagc};
2150920b4f2Sagc.Ed
2160920b4f2Sagc.Pp
2170920b4f2SagcIf the size could not be obtained from the server, the
2180920b4f2Sagc.Fa size
2190920b4f2Sagcfield is set to -1.
2200920b4f2SagcIf the modification time could not be obtained from the server, the
2210920b4f2Sagc.Fa mtime
2220920b4f2Sagcfield is set to the epoch.
2230920b4f2SagcIf the access time could not be obtained from the server, the
2240920b4f2Sagc.Fa atime
2250920b4f2Sagcfield is set to the modification time.
2260920b4f2Sagc.Pp
2270920b4f2Sagc.Fn fetchListURL
2280920b4f2Sagcattempts to list the contents of the directory pointed to by the URL
2290920b4f2Sagcprovided.
2300920b4f2SagcIf successful, it returns a malloced array of
2310920b4f2Sagc.Vt url_ent
2320920b4f2Sagcstructures.
2330920b4f2SagcThe
2340920b4f2Sagc.Vt url_ent
2350920b4f2Sagcstructure is defined as follows in
2360920b4f2Sagc.In fetch.h :
2370920b4f2Sagc.Bd -literal
2380920b4f2Sagcstruct url_ent {
2390920b4f2Sagc    char         name[MAXPATHLEN];
2400920b4f2Sagc    struct url_stat stat;
2410920b4f2Sagc};
2420920b4f2Sagc.Ed
2430920b4f2Sagc.Pp
2440920b4f2SagcThe list is terminated by an entry with an empty name.
2450920b4f2Sagc.Pp
2460920b4f2SagcThe pointer returned by
2470920b4f2Sagc.Fn fetchListURL
2480920b4f2Sagcshould be freed using
2490920b4f2Sagc.Fn free .
2500920b4f2Sagc.Pp
2510920b4f2Sagc.Fn fetchXGet ,
2520920b4f2Sagc.Fn fetchGet ,
2530920b4f2Sagc.Fn fetchPut
2540920b4f2Sagcand
2550920b4f2Sagc.Fn fetchStat
2560920b4f2Sagcare similar to
2570920b4f2Sagc.Fn fetchXGetURL ,
2580920b4f2Sagc.Fn fetchGetURL ,
2590920b4f2Sagc.Fn fetchPutURL
2600920b4f2Sagcand
2610920b4f2Sagc.Fn fetchStatURL ,
2620920b4f2Sagcexcept that they expect a pre-parsed URL in the form of a pointer to
2630920b4f2Sagca
2640920b4f2Sagc.Vt struct url
2650920b4f2Sagcrather than a string.
2660920b4f2Sagc.Pp
2670920b4f2SagcAll of the
2680920b4f2Sagc.Fn fetchXGetXXX ,
2690920b4f2Sagc.Fn fetchGetXXX
2700920b4f2Sagcand
2710920b4f2Sagc.Fn fetchPutXXX
2720920b4f2Sagcfunctions return a pointer to a stream which can be used to read or
2730920b4f2Sagcwrite data from or to the requested document, respectively.
2740920b4f2SagcNote that
2750920b4f2Sagcalthough the implementation details of the individual access methods
2760920b4f2Sagcvary, it can generally be assumed that a stream returned by one of the
2770920b4f2Sagc.Fn fetchXGetXXX
2780920b4f2Sagcor
2790920b4f2Sagc.Fn fetchGetXXX
2800920b4f2Sagcfunctions is read-only, and that a stream returned by one of the
2810920b4f2Sagc.Fn fetchPutXXX
2820920b4f2Sagcfunctions is write-only.
2830920b4f2Sagc.Sh FILE SCHEME
2840920b4f2Sagc.Fn fetchXGetFile ,
2850920b4f2Sagc.Fn fetchGetFile
2860920b4f2Sagcand
2870920b4f2Sagc.Fn fetchPutFile
2880920b4f2Sagcprovide access to documents which are files in a locally mounted file
2890920b4f2Sagcsystem.
2900920b4f2SagcOnly the <document> component of the URL is used.
2910920b4f2Sagc.Pp
2920920b4f2Sagc.Fn fetchXGetFile
2930920b4f2Sagcand
2940920b4f2Sagc.Fn fetchGetFile
2950920b4f2Sagcdo not accept any flags.
2960920b4f2Sagc.Pp
2970920b4f2Sagc.Fn fetchPutFile
2980920b4f2Sagcaccepts the
2990920b4f2Sagc.Ql a
3000920b4f2Sagc(append to file) flag.
3010920b4f2SagcIf that flag is specified, the data written to
3020920b4f2Sagcthe stream returned by
3030920b4f2Sagc.Fn fetchPutFile
3040920b4f2Sagcwill be appended to the previous contents of the file, instead of
3050920b4f2Sagcreplacing them.
3060920b4f2Sagc.Sh FTP SCHEME
3070920b4f2Sagc.Fn fetchXGetFTP ,
3080920b4f2Sagc.Fn fetchGetFTP
3090920b4f2Sagcand
3100920b4f2Sagc.Fn fetchPutFTP
3110920b4f2Sagcimplement the FTP protocol as described in RFC959.
3120920b4f2Sagc.Pp
3130920b4f2SagcIf the
3140920b4f2Sagc.Ql p
3150920b4f2Sagc(passive) flag is specified, a passive (rather than active) connection
3160920b4f2Sagcwill be attempted.
3170920b4f2Sagc.Pp
3180920b4f2SagcIf the
3190920b4f2Sagc.Ql l
3200920b4f2Sagc(low) flag is specified, data sockets will be allocated in the low (or
3210920b4f2Sagcdefault) port range instead of the high port range (see
3220920b4f2Sagc.Xr ip 4 ) .
3230920b4f2Sagc.Pp
3240920b4f2SagcIf the
3250920b4f2Sagc.Ql d
3260920b4f2Sagc(direct) flag is specified,
3270920b4f2Sagc.Fn fetchXGetFTP ,
3280920b4f2Sagc.Fn fetchGetFTP
3290920b4f2Sagcand
3300920b4f2Sagc.Fn fetchPutFTP
3310920b4f2Sagcwill use a direct connection even if a proxy server is defined.
3320920b4f2Sagc.Pp
3330920b4f2SagcIf no user name or password is given, the
3340920b4f2Sagc.Nm fetch
3350920b4f2Sagclibrary will attempt an anonymous login, with user name "anonymous"
3360920b4f2Sagcand password "anonymous@<hostname>".
3370920b4f2Sagc.Sh HTTP SCHEME
3380920b4f2SagcThe
3390920b4f2Sagc.Fn fetchXGetHTTP ,
3400920b4f2Sagc.Fn fetchGetHTTP
3410920b4f2Sagcand
3420920b4f2Sagc.Fn fetchPutHTTP
3430920b4f2Sagcfunctions implement the HTTP/1.1 protocol.
3440920b4f2SagcWith a little luck, there is
3450920b4f2Sagceven a chance that they comply with RFC2616 and RFC2617.
3460920b4f2Sagc.Pp
3470920b4f2SagcIf the
3480920b4f2Sagc.Ql d
3490920b4f2Sagc(direct) flag is specified,
3500920b4f2Sagc.Fn fetchXGetHTTP ,
3510920b4f2Sagc.Fn fetchGetHTTP
3520920b4f2Sagcand
3530920b4f2Sagc.Fn fetchPutHTTP
3540920b4f2Sagcwill use a direct connection even if a proxy server is defined.
3550920b4f2Sagc.Pp
3560920b4f2SagcSince there seems to be no good way of implementing the HTTP PUT
3570920b4f2Sagcmethod in a manner consistent with the rest of the
3580920b4f2Sagc.Nm fetch
3590920b4f2Sagclibrary,
3600920b4f2Sagc.Fn fetchPutHTTP
3610920b4f2Sagcis currently unimplemented.
3620920b4f2Sagc.Sh AUTHENTICATION
3630920b4f2SagcApart from setting the appropriate environment variables and
3640920b4f2Sagcspecifying the user name and password in the URL or the
3650920b4f2Sagc.Vt struct url ,
3660920b4f2Sagcthe calling program has the option of defining an authentication
3670920b4f2Sagcfunction with the following prototype:
3680920b4f2Sagc.Pp
3690920b4f2Sagc.Ft int
3700920b4f2Sagc.Fn myAuthMethod "struct url *u"
3710920b4f2Sagc.Pp
3720920b4f2SagcThe callback function should fill in the
3730920b4f2Sagc.Fa user
3740920b4f2Sagcand
3750920b4f2Sagc.Fa pwd
3760920b4f2Sagcfields in the provided
3770920b4f2Sagc.Vt struct url
3780920b4f2Sagcand return 0 on success, or any other value to indicate failure.
3790920b4f2Sagc.Pp
3800920b4f2SagcTo register the authentication callback, simply set
3810920b4f2Sagc.Va fetchAuthMethod
3820920b4f2Sagcto point at it.
3830920b4f2SagcThe callback will be used whenever a site requires authentication and
3840920b4f2Sagcthe appropriate environment variables are not set.
3850920b4f2Sagc.Pp
3860920b4f2SagcThis interface is experimental and may be subject to change.
3870920b4f2Sagc.Sh RETURN VALUES
3880920b4f2Sagc.Fn fetchParseURL
3890920b4f2Sagcreturns a pointer to a
3900920b4f2Sagc.Vt struct url
3910920b4f2Sagccontaining the individual components of the URL.
3920920b4f2SagcIf it is
3930920b4f2Sagcunable to allocate memory, or the URL is syntactically incorrect,
3940920b4f2Sagc.Fn fetchParseURL
3950920b4f2Sagcreturns a NULL pointer.
3960920b4f2Sagc.Pp
3970920b4f2SagcThe
3980920b4f2Sagc.Fn fetchStat
3990920b4f2Sagcfunctions return 0 on success and -1 on failure.
4000920b4f2Sagc.Pp
4010920b4f2SagcAll other functions return a stream pointer which may be used to
4020920b4f2Sagcaccess the requested document, or NULL if an error occurred.
4030920b4f2Sagc.Pp
4040920b4f2SagcThe following error codes are defined in
4050920b4f2Sagc.In fetch.h :
4060920b4f2Sagc.Bl -tag -width 18n
4070920b4f2Sagc.It Bq Er FETCH_ABORT
4080920b4f2SagcOperation aborted
4090920b4f2Sagc.It Bq Er FETCH_AUTH
4100920b4f2SagcAuthentication failed
4110920b4f2Sagc.It Bq Er FETCH_DOWN
4120920b4f2SagcService unavailable
4130920b4f2Sagc.It Bq Er FETCH_EXISTS
4140920b4f2SagcFile exists
4150920b4f2Sagc.It Bq Er FETCH_FULL
4160920b4f2SagcFile system full
4170920b4f2Sagc.It Bq Er FETCH_INFO
4180920b4f2SagcInformational response
4190920b4f2Sagc.It Bq Er FETCH_MEMORY
4200920b4f2SagcInsufficient memory
4210920b4f2Sagc.It Bq Er FETCH_MOVED
4220920b4f2SagcFile has moved
4230920b4f2Sagc.It Bq Er FETCH_NETWORK
4240920b4f2SagcNetwork error
4250920b4f2Sagc.It Bq Er FETCH_OK
4260920b4f2SagcNo error
4270920b4f2Sagc.It Bq Er FETCH_PROTO
4280920b4f2SagcProtocol error
4290920b4f2Sagc.It Bq Er FETCH_RESOLV
4300920b4f2SagcResolver error
4310920b4f2Sagc.It Bq Er FETCH_SERVER
4320920b4f2SagcServer error
4330920b4f2Sagc.It Bq Er FETCH_TEMP
4340920b4f2SagcTemporary error
4350920b4f2Sagc.It Bq Er FETCH_TIMEOUT
4360920b4f2SagcOperation timed out
4370920b4f2Sagc.It Bq Er FETCH_UNAVAIL
4380920b4f2SagcFile is not available
4390920b4f2Sagc.It Bq Er FETCH_UNKNOWN
4400920b4f2SagcUnknown error
4410920b4f2Sagc.It Bq Er FETCH_URL
4420920b4f2SagcInvalid URL
4430920b4f2Sagc.El
4440920b4f2Sagc.Pp
4450920b4f2SagcThe accompanying error message includes a protocol-specific error code
4460920b4f2Sagcand message, e.g.\& "File is not available (404 Not Found)"
4470920b4f2Sagc.Sh ENVIRONMENT
4480920b4f2Sagc.Bl -tag -width ".Ev FETCH_BIND_ADDRESS"
4490920b4f2Sagc.It Ev FETCH_BIND_ADDRESS
4500920b4f2SagcSpecifies a hostname or IP address to which sockets used for outgoing
4510920b4f2Sagcconnections will be bound.
4520920b4f2Sagc.It Ev FTP_LOGIN
4530920b4f2SagcDefault FTP login if none was provided in the URL.
4540920b4f2Sagc.It Ev FTP_PASSIVE_MODE
4550920b4f2SagcIf set to anything but
4560920b4f2Sagc.Ql no ,
4570920b4f2Sagcforces the FTP code to use passive mode.
4580920b4f2Sagc.It Ev FTP_PASSWORD
4590920b4f2SagcDefault FTP password if the remote server requests one and none was
4600920b4f2Sagcprovided in the URL.
4610920b4f2Sagc.It Ev FTP_PROXY
4620920b4f2SagcURL of the proxy to use for FTP requests.
4630920b4f2SagcThe document part is ignored.
4640920b4f2SagcFTP and HTTP proxies are supported; if no scheme is specified, FTP is
4650920b4f2Sagcassumed.
4660920b4f2SagcIf the proxy is an FTP proxy,
4670920b4f2Sagc.Nm libfetch
4680920b4f2Sagcwill send
4690920b4f2Sagc.Ql user@host
4700920b4f2Sagcas user name to the proxy, where
4710920b4f2Sagc.Ql user
4720920b4f2Sagcis the real user name, and
4730920b4f2Sagc.Ql host
4740920b4f2Sagcis the name of the FTP server.
4750920b4f2Sagc.Pp
4760920b4f2SagcIf this variable is set to an empty string, no proxy will be used for
4770920b4f2SagcFTP requests, even if the
4780920b4f2Sagc.Ev HTTP_PROXY
4790920b4f2Sagcvariable is set.
4800920b4f2Sagc.It Ev ftp_proxy
4810920b4f2SagcSame as
4820920b4f2Sagc.Ev FTP_PROXY ,
4830920b4f2Sagcfor compatibility.
4840920b4f2Sagc.It Ev HTTP_AUTH
4850920b4f2SagcSpecifies HTTP authorization parameters as a colon-separated list of
4860920b4f2Sagcitems.
4870920b4f2SagcThe first and second item are the authorization scheme and realm
4880920b4f2Sagcrespectively; further items are scheme-dependent.
4890920b4f2SagcCurrently, only basic authorization is supported.
4900920b4f2Sagc.Pp
4910920b4f2SagcBasic authorization requires two parameters: the user name and
4920920b4f2Sagcpassword, in that order.
4930920b4f2Sagc.Pp
4940920b4f2SagcThis variable is only used if the server requires authorization and
4950920b4f2Sagcno user name or password was specified in the URL.
4960920b4f2Sagc.It Ev HTTP_PROXY
4970920b4f2SagcURL of the proxy to use for HTTP requests.
4980920b4f2SagcThe document part is ignored.
4990920b4f2SagcOnly HTTP proxies are supported for HTTP requests.
5000920b4f2SagcIf no port number is specified, the default is 3128.
5010920b4f2Sagc.Pp
5020920b4f2SagcNote that this proxy will also be used for FTP documents, unless the
5030920b4f2Sagc.Ev FTP_PROXY
5040920b4f2Sagcvariable is set.
5050920b4f2Sagc.It Ev http_proxy
5060920b4f2SagcSame as
5070920b4f2Sagc.Ev HTTP_PROXY ,
5080920b4f2Sagcfor compatibility.
5090920b4f2Sagc.It Ev HTTP_PROXY_AUTH
5100920b4f2SagcSpecifies authorization parameters for the HTTP proxy in the same
5110920b4f2Sagcformat as the
5120920b4f2Sagc.Ev HTTP_AUTH
5130920b4f2Sagcvariable.
5140920b4f2Sagc.Pp
5150920b4f2SagcThis variable is used if and only if connected to an HTTP proxy, and
5160920b4f2Sagcis ignored if a user and/or a password were specified in the proxy
5170920b4f2SagcURL.
5180920b4f2Sagc.It Ev HTTP_REFERER
5190920b4f2SagcSpecifies the referrer URL to use for HTTP requests.
5200920b4f2SagcIf set to
5210920b4f2Sagc.Dq auto ,
5220920b4f2Sagcthe document URL will be used as referrer URL.
5230920b4f2Sagc.It Ev HTTP_USER_AGENT
5240920b4f2SagcSpecifies the User-Agent string to use for HTTP requests.
5250920b4f2SagcThis can be useful when working with HTTP origin or proxy servers that
5260920b4f2Sagcdifferentiate between user agents.
5270920b4f2Sagc.It Ev NETRC
5280920b4f2SagcSpecifies a file to use instead of
5290920b4f2Sagc.Pa ~/.netrc
5300920b4f2Sagcto look up login names and passwords for FTP sites.
5310920b4f2SagcSee
5320920b4f2Sagc.Xr ftp 1
5330920b4f2Sagcfor a description of the file format.
5340920b4f2SagcThis feature is experimental.
5350920b4f2Sagc.El
5360920b4f2Sagc.Sh EXAMPLES
5370920b4f2SagcTo access a proxy server on
5380920b4f2Sagc.Pa proxy.example.com
5390920b4f2Sagcport 8080, set the
5400920b4f2Sagc.Ev HTTP_PROXY
5410920b4f2Sagcenvironment variable in a manner similar to this:
5420920b4f2Sagc.Pp
5430920b4f2Sagc.Dl HTTP_PROXY=http://proxy.example.com:8080
5440920b4f2Sagc.Pp
5450920b4f2SagcIf the proxy server requires authentication, there are
5460920b4f2Sagctwo options available for passing the authentication data.
5470920b4f2SagcThe first method is by using the proxy URL:
5480920b4f2Sagc.Pp
5490920b4f2Sagc.Dl HTTP_PROXY=http://<user>:<pwd>@proxy.example.com:8080
5500920b4f2Sagc.Pp
5510920b4f2SagcThe second method is by using the
5520920b4f2Sagc.Ev HTTP_PROXY_AUTH
5530920b4f2Sagcenvironment variable:
5540920b4f2Sagc.Bd -literal -offset indent
5550920b4f2SagcHTTP_PROXY=http://proxy.example.com:8080
5560920b4f2SagcHTTP_PROXY_AUTH=basic:*:<user>:<pwd>
5570920b4f2Sagc.Ed
5580920b4f2Sagc.Sh SEE ALSO
5590920b4f2Sagc.Xr fetch 1 ,
5600920b4f2Sagc.Xr ftpio 3 ,
5610920b4f2Sagc.Xr ip 4
5620920b4f2Sagc.Rs
5630920b4f2Sagc.%A J. Postel
5640920b4f2Sagc.%A J. K. Reynolds
5650920b4f2Sagc.%D October 1985
5660920b4f2Sagc.%B File Transfer Protocol
5670920b4f2Sagc.%O RFC959
5680920b4f2Sagc.Re
5690920b4f2Sagc.Rs
5700920b4f2Sagc.%A P. Deutsch
5710920b4f2Sagc.%A A. Emtage
5720920b4f2Sagc.%A A. Marine.
5730920b4f2Sagc.%D May 1994
5740920b4f2Sagc.%T How to Use Anonymous FTP
5750920b4f2Sagc.%O RFC1635
5760920b4f2Sagc.Re
5770920b4f2Sagc.Rs
5780920b4f2Sagc.%A T. Berners-Lee
5790920b4f2Sagc.%A L. Masinter
5800920b4f2Sagc.%A M. McCahill
5810920b4f2Sagc.%D December 1994
5820920b4f2Sagc.%T Uniform Resource Locators (URL)
5830920b4f2Sagc.%O RFC1738
5840920b4f2Sagc.Re
5850920b4f2Sagc.Rs
5860920b4f2Sagc.%A R. Fielding
5870920b4f2Sagc.%A J. Gettys
5880920b4f2Sagc.%A J. Mogul
5890920b4f2Sagc.%A H. Frystyk
5900920b4f2Sagc.%A L. Masinter
5910920b4f2Sagc.%A P. Leach
5920920b4f2Sagc.%A T. Berners-Lee
5930920b4f2Sagc.%D January 1999
5940920b4f2Sagc.%B Hypertext Transfer Protocol -- HTTP/1.1
5950920b4f2Sagc.%O RFC2616
5960920b4f2Sagc.Re
5970920b4f2Sagc.Rs
5980920b4f2Sagc.%A J. Franks
5990920b4f2Sagc.%A P. Hallam-Baker
6000920b4f2Sagc.%A J. Hostetler
6010920b4f2Sagc.%A S. Lawrence
6020920b4f2Sagc.%A P. Leach
6030920b4f2Sagc.%A A. Luotonen
6040920b4f2Sagc.%A L. Stewart
6050920b4f2Sagc.%D June 1999
6060920b4f2Sagc.%B HTTP Authentication: Basic and Digest Access Authentication
6070920b4f2Sagc.%O RFC2617
6080920b4f2Sagc.Re
6090920b4f2Sagc.Sh HISTORY
6100920b4f2SagcThe
6110920b4f2Sagc.Nm fetch
6120920b4f2Sagclibrary first appeared in
6130920b4f2Sagc.Fx 3.0 .
6140920b4f2Sagc.Sh AUTHORS
6150920b4f2Sagc.An -nosplit
6160920b4f2SagcThe
6170920b4f2Sagc.Nm fetch
6180920b4f2Sagclibrary was mostly written by
619*a5684d07Swiz.An Dag-Erling Sm\(/orgrav Aq Mt des@FreeBSD.org
6200920b4f2Sagcwith numerous suggestions from
621*a5684d07Swiz.An Jordan K. Hubbard Aq Mt jkh@FreeBSD.org ,
622*a5684d07Swiz.An Eugene Skepner Aq Mt eu@qub.com
6230920b4f2Sagcand other
6240920b4f2Sagc.Fx
6250920b4f2Sagcdevelopers.
6260920b4f2SagcIt replaces the older
6270920b4f2Sagc.Nm ftpio
6280920b4f2Sagclibrary written by
629*a5684d07Swiz.An Poul-Henning Kamp Aq Mt phk@FreeBSD.org
6300920b4f2Sagcand
631*a5684d07Swiz.An Jordan K. Hubbard Aq Mt jkh@FreeBSD.org .
6320920b4f2Sagc.Pp
6330920b4f2SagcThis manual page was written by
634*a5684d07Swiz.An Dag-Erling Sm\(/orgrav Aq Mt des@FreeBSD.org .
6350920b4f2Sagc.Sh BUGS
6360920b4f2SagcSome parts of the library are not yet implemented.
6370920b4f2SagcThe most notable
6380920b4f2Sagcexamples of this are
6390920b4f2Sagc.Fn fetchPutHTTP ,
6400920b4f2Sagc.Fn fetchListHTTP ,
6410920b4f2Sagc.Fn fetchListFTP
6420920b4f2Sagcand FTP proxy support.
6430920b4f2Sagc.Pp
6440920b4f2SagcThere is no way to select a proxy at run-time other than setting the
6450920b4f2Sagc.Ev HTTP_PROXY
6460920b4f2Sagcor
6470920b4f2Sagc.Ev FTP_PROXY
6480920b4f2Sagcenvironment variables as appropriate.
6490920b4f2Sagc.Pp
6500920b4f2Sagc.Nm libfetch
6510920b4f2Sagcdoes not understand or obey 305 (Use Proxy) replies.
6520920b4f2Sagc.Pp
6530920b4f2SagcError numbers are unique only within a certain context; the error
6540920b4f2Sagccodes used for FTP and HTTP overlap, as do those used for resolver and
6550920b4f2Sagcsystem errors.
6560920b4f2SagcFor instance, error code 202 means "Command not
6570920b4f2Sagcimplemented, superfluous at this site" in an FTP context and
6580920b4f2Sagc"Accepted" in an HTTP context.
6590920b4f2Sagc.Pp
6600920b4f2Sagc.Fn fetchStatFTP
6610920b4f2Sagcdoes not check that the result of an MDTM command is a valid date.
6620920b4f2Sagc.Pp
6630920b4f2SagcThe man page is incomplete, poorly written and produces badly
6640920b4f2Sagcformatted text.
6650920b4f2Sagc.Pp
6660920b4f2SagcThe error reporting mechanism is unsatisfactory.
6670920b4f2Sagc.Pp
6680920b4f2SagcSome parts of the code are not fully reentrant.
669