14ca1ab94SDag-Erling Smørgrav.\" Copyright (c) 1998 Dag-Erling Co�dan Sm�rgrav 24ca1ab94SDag-Erling Smørgrav.\" All rights reserved. 34ca1ab94SDag-Erling Smørgrav.\" 44ca1ab94SDag-Erling Smørgrav.\" Redistribution and use in source and binary forms, with or without 54ca1ab94SDag-Erling Smørgrav.\" modification, are permitted provided that the following conditions 64ca1ab94SDag-Erling Smørgrav.\" are met: 74ca1ab94SDag-Erling Smørgrav.\" 1. Redistributions of source code must retain the above copyright 84ca1ab94SDag-Erling Smørgrav.\" notice, this list of conditions and the following disclaimer. 94ca1ab94SDag-Erling Smørgrav.\" 2. Redistributions in binary form must reproduce the above copyright 104ca1ab94SDag-Erling Smørgrav.\" notice, this list of conditions and the following disclaimer in the 114ca1ab94SDag-Erling Smørgrav.\" documentation and/or other materials provided with the distribution. 124ca1ab94SDag-Erling Smørgrav.\" 134ca1ab94SDag-Erling Smørgrav.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 144ca1ab94SDag-Erling Smørgrav.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 154ca1ab94SDag-Erling Smørgrav.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 164ca1ab94SDag-Erling Smørgrav.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 174ca1ab94SDag-Erling Smørgrav.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 184ca1ab94SDag-Erling Smørgrav.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 194ca1ab94SDag-Erling Smørgrav.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 204ca1ab94SDag-Erling Smørgrav.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 214ca1ab94SDag-Erling Smørgrav.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 224ca1ab94SDag-Erling Smørgrav.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 234ca1ab94SDag-Erling Smørgrav.\" SUCH DAMAGE. 244ca1ab94SDag-Erling Smørgrav.\" 25842a95ccSDag-Erling Smørgrav.\" $Id: fetch.3,v 1.2 1998/09/26 20:42:44 des Exp $ 264ca1ab94SDag-Erling Smørgrav.\" 274ca1ab94SDag-Erling Smørgrav.Dd July 1, 1998 284ca1ab94SDag-Erling Smørgrav.Dt FETCH 3 294ca1ab94SDag-Erling Smørgrav.Os 304ca1ab94SDag-Erling Smørgrav.Sh NAME 314ca1ab94SDag-Erling Smørgrav.Nm fetchGetURL , 324ca1ab94SDag-Erling Smørgrav.Nm fetchPutURL , 33db5f8cebSDag-Erling Smørgrav.Nm fetchParseURL , 34db5f8cebSDag-Erling Smørgrav.Nm fetchGet , 35db5f8cebSDag-Erling Smørgrav.Nm fetchPut , 364ca1ab94SDag-Erling Smørgrav.Nm fetchGetFile , 374ca1ab94SDag-Erling Smørgrav.Nm fetchPutFile , 384ca1ab94SDag-Erling Smørgrav.Nm fetchGetHTTP , 394ca1ab94SDag-Erling Smørgrav.Nm fetchPutHTTP , 404ca1ab94SDag-Erling Smørgrav.Nm fetchGetFTP , 414ca1ab94SDag-Erling Smørgrav.Nm fetchPutFTP 424ca1ab94SDag-Erling Smørgrav.Nd file transfer library 434ca1ab94SDag-Erling Smørgrav.Sh SYNOPSIS 444ca1ab94SDag-Erling Smørgrav.Fd #include <fetch.h> 45db5f8cebSDag-Erling Smørgrav.Ft FILE * 46db5f8cebSDag-Erling Smørgrav.Fn fetchGetURL "char *URL" "char *flags" 47db5f8cebSDag-Erling Smørgrav.Ft FILE * 48db5f8cebSDag-Erling Smørgrav.Fn fetchPutURL "char *URL" "char *flags" 494ca1ab94SDag-Erling Smørgrav.Ft url_t * 504ca1ab94SDag-Erling Smørgrav.Fn fetchParseURL "char *URL" "char *flags" 514ca1ab94SDag-Erling Smørgrav.Ft FILE * 52db5f8cebSDag-Erling Smørgrav.Fn fetchGet "url_t *URL" "char *flags" 53db5f8cebSDag-Erling Smørgrav.Ft FILE * 54db5f8cebSDag-Erling Smørgrav.Fn fetchPut "url_t *URL" "char *flags" 55db5f8cebSDag-Erling Smørgrav.Ft FILE * 564ca1ab94SDag-Erling Smørgrav.Fn fetchGetFile "url_t *u" "char *flags" 574ca1ab94SDag-Erling Smørgrav.Ft FILE * 584ca1ab94SDag-Erling Smørgrav.Fn fetchPutFile "url_t *u" "char *flags" 594ca1ab94SDag-Erling Smørgrav.Ft FILE * 604ca1ab94SDag-Erling Smørgrav.Fn fetchGetHTTP "url_t *u" "char *flags" 614ca1ab94SDag-Erling Smørgrav.Ft FILE * 624ca1ab94SDag-Erling Smørgrav.Fn fetchPutHTTP "url_t *u" "char *flags" 634ca1ab94SDag-Erling Smørgrav.Ft FILE * 644ca1ab94SDag-Erling Smørgrav.Fn fetchGetFTP "url_t *u" "char *flags" 654ca1ab94SDag-Erling Smørgrav.Ft FILE * 664ca1ab94SDag-Erling Smørgrav.Fn fetchPutFTP "url_t *u" "char *flags" 67842a95ccSDag-Erling Smørgrav.Vt extern int fetchLastErrCode; 68842a95ccSDag-Erling Smørgrav.Vt extern const char *fetchLastErrText; 694ca1ab94SDag-Erling Smørgrav.Sh DESCRIPTION 704ca1ab94SDag-Erling SmørgravThese functions implement a high-level library for retrieving and 714ca1ab94SDag-Erling Smørgravuploading files using Uniform Resource Locators (URLs). 724ca1ab94SDag-Erling Smørgrav.Pp 73db5f8cebSDag-Erling Smørgrav.Fn fetchGetURL 74db5f8cebSDag-Erling Smørgravand 75db5f8cebSDag-Erling Smørgrav.Fn fetchPutURL 76db5f8cebSDag-Erling Smørgravconstitute the recommended interface to the 77db5f8cebSDag-Erling Smørgrav.Nm fetch 78db5f8cebSDag-Erling Smørgravlibrary. They examine the URL passed to them to determine the transfer 79db5f8cebSDag-Erling Smørgravmethod, and call the appropriate lower-level functions to perform the 80db5f8cebSDag-Erling Smørgravactual transfer. The 81db5f8cebSDag-Erling Smørgrav.Fa flags 82db5f8cebSDag-Erling Smørgravargument is a string of characters which specify transfer options. The 83db5f8cebSDag-Erling Smørgravmeaning of the individual flags is scheme-dependent, and is detailed 84db5f8cebSDag-Erling Smørgravin the appropriate section below. 85db5f8cebSDag-Erling Smørgrav.Pp 864ca1ab94SDag-Erling Smørgrav.Fn fetchParseURL 874ca1ab94SDag-Erling Smørgravtakes a URL in the form of a null-terminated string and splits it into 884ca1ab94SDag-Erling Smørgravits components function according to the Common Internet Scheme Syntax 894ca1ab94SDag-Erling Smørgravdetailed in RFC1738. A regular expression which produces this syntax 904ca1ab94SDag-Erling Smørgravis: 914ca1ab94SDag-Erling Smørgrav.Bd -literal 924ca1ab94SDag-Erling Smørgrav <scheme>:(//(<user>(:<pwd>)?@)?<host>(:<port>)?)?/(<document>)? 934ca1ab94SDag-Erling Smørgrav.Ed 944ca1ab94SDag-Erling Smørgrav.Pp 954ca1ab94SDag-Erling SmørgravNote that some components of the URL are not necessarily relevant to 964ca1ab94SDag-Erling Smørgravall URL schemes. For instance, the file scheme only needs the <scheme> 974ca1ab94SDag-Erling Smørgravand <document> components. 984ca1ab94SDag-Erling Smørgrav.Pp 994ca1ab94SDag-Erling SmørgravThe pointer returned by 1004ca1ab94SDag-Erling Smørgrav.Fn fetchParseURL 1014ca1ab94SDag-Erling Smørgravshould be freed using 102842a95ccSDag-Erling Smørgrav.Fn free . 1034ca1ab94SDag-Erling Smørgrav.Pp 104db5f8cebSDag-Erling Smørgrav.Fn fetchGet 105db5f8cebSDag-Erling Smørgravand 106db5f8cebSDag-Erling Smørgrav.Fn fetchPut 107db5f8cebSDag-Erling Smørgravare similar to 1084ca1ab94SDag-Erling Smørgrav.Fn fetchGetURL 1094ca1ab94SDag-Erling Smørgravand 110db5f8cebSDag-Erling Smørgrav.Fn fetchPutURL , 111db5f8cebSDag-Erling Smørgravexcept that they expect a pre-parsed URL in the form of a pointer to 112db5f8cebSDag-Erling Smørgravan 113db5f8cebSDag-Erling Smørgrav.Fa url_t 114db5f8cebSDag-Erling Smørgravstructure rather than a string. 1154ca1ab94SDag-Erling Smørgrav.Pp 1164ca1ab94SDag-Erling SmørgravAll of the 1174ca1ab94SDag-Erling Smørgrav.Fn fetchGetXXX 1184ca1ab94SDag-Erling Smørgravand 1194ca1ab94SDag-Erling Smørgrav.Fn fetchPutXXX 1204ca1ab94SDag-Erling Smørgravfunctions return a pointer to a stream which can be used to read or 121db5f8cebSDag-Erling Smørgravwrite data from or to the requested document, respectively. Note that 1224ca1ab94SDag-Erling Smørgravalthough the implementation details of the individual access methods 1234ca1ab94SDag-Erling Smørgravvary, it can generally be assumed that a stream returned by one of the 1244ca1ab94SDag-Erling Smørgrav.Fn fetchGetXXX 1254ca1ab94SDag-Erling Smørgravfunctions is read-only, and that a stream returned by one of the 1264ca1ab94SDag-Erling Smørgrav.Fn fetchPutXXX 1274ca1ab94SDag-Erling Smørgravfunctions is write-only. 1284ca1ab94SDag-Erling Smørgrav.Sh FILE SCHEME 1294ca1ab94SDag-Erling Smørgrav.Fn fetchGetFile 1304ca1ab94SDag-Erling Smørgravand 1314ca1ab94SDag-Erling Smørgrav.Fn fetchPutFile 1324ca1ab94SDag-Erling Smørgravprovide access to documents which are files in a locally mounted file 1334ca1ab94SDag-Erling Smørgravsystem. Only the <document> component of the URL is used. 1344ca1ab94SDag-Erling Smørgrav.Pp 1354ca1ab94SDag-Erling Smørgrav.Fn fetchGetFile 1364ca1ab94SDag-Erling Smørgravdoes not accept any flags. 1374ca1ab94SDag-Erling Smørgrav.Pp 1384ca1ab94SDag-Erling Smørgrav.Fn fetchPutFile 1394ca1ab94SDag-Erling Smørgravaccepts the 1404ca1ab94SDag-Erling Smørgrav.Fa a 1414ca1ab94SDag-Erling Smørgrav(append to file) flag. If that flag is specified, the data written to 1424ca1ab94SDag-Erling Smørgravthe stream returned by 1434ca1ab94SDag-Erling Smørgrav.Fn fetchPutFile 1444ca1ab94SDag-Erling Smørgravwill be appended to the previous contents of the file, instead of 1454ca1ab94SDag-Erling Smørgravreplacing them. 1464ca1ab94SDag-Erling Smørgrav.Sh FTP SCHEME 1474ca1ab94SDag-Erling Smørgrav.Fn fetchGetFTP 1484ca1ab94SDag-Erling Smørgravand 1494ca1ab94SDag-Erling Smørgrav.Fn fetchPutFTP 1504ca1ab94SDag-Erling Smørgravimplement the FTP protocol as described in RFC959. 1514ca1ab94SDag-Erling Smørgrav.Pp 1524ca1ab94SDag-Erling SmørgravIf the 1534ca1ab94SDag-Erling Smørgrav.Fa p 1544ca1ab94SDag-Erling Smørgrav(passive) flag is specified, a passive (rather than active) connection 1554ca1ab94SDag-Erling Smørgravwill be attempted. 1564ca1ab94SDag-Erling Smørgrav.Pp 1574ca1ab94SDag-Erling SmørgravIf no user name or password is given, the 1584ca1ab94SDag-Erling Smørgrav.Nm fetch 1594ca1ab94SDag-Erling Smørgravlibrary will attempt an anonymous login, with user name "ftp" and 1604ca1ab94SDag-Erling Smørgravpassword "ftp". 1614ca1ab94SDag-Erling Smørgrav.Sh HTTP SCHEME 1624ca1ab94SDag-Erling SmørgravThe 1634ca1ab94SDag-Erling Smørgrav.Fn fetchGetHTTP 1644ca1ab94SDag-Erling Smørgravand 1654ca1ab94SDag-Erling Smørgrav.Fn fetchPutHTTP 1664ca1ab94SDag-Erling Smørgravfunctions implement the HTTP/1.1 protocol. With a little luck, there's 1674ca1ab94SDag-Erling Smørgraveven a chance that they comply with RFC2068. 1684ca1ab94SDag-Erling Smørgrav.Pp 1694ca1ab94SDag-Erling SmørgravSince there seems to be no good way of implementing the HTTP PUT 1704ca1ab94SDag-Erling Smørgravmethod in a manner consistent with the rest of the 1714ca1ab94SDag-Erling Smørgrav.Nm fetch 1724ca1ab94SDag-Erling Smørgravlibrary, 1734ca1ab94SDag-Erling Smørgrav.Fn fetchPutHTTP 1744ca1ab94SDag-Erling Smørgravis currently unimplemented. 1754ca1ab94SDag-Erling Smørgrav.Sh RETURN VALUES 1764ca1ab94SDag-Erling Smørgrav.Fn fetchParseURL 1774ca1ab94SDag-Erling Smørgravreturns a pointer to a 1784ca1ab94SDag-Erling Smørgrav.Fa url_t 1794ca1ab94SDag-Erling Smørgravstructure containing the individual components of the URL. If it is 1804ca1ab94SDag-Erling Smørgravunable to allocate memory, or the URL is syntactically incorrect, 1814ca1ab94SDag-Erling Smørgrav.Fn fetchParseURL 1824ca1ab94SDag-Erling Smørgravreturns a NULL pointer. 1834ca1ab94SDag-Erling Smørgrav.Pp 1844ca1ab94SDag-Erling SmørgravAll other functions return a stream pointer which may be used to 185842a95ccSDag-Erling Smørgravaccess the requested document, or NULL if an error occurred. In the 186842a95ccSDag-Erling Smørgravlatter case, the variables 187842a95ccSDag-Erling Smørgrav.Va fetchLastErrCode 188842a95ccSDag-Erling Smørgravand 189842a95ccSDag-Erling Smørgrav.Va fetchLastErrText 190842a95ccSDag-Erling Smørgravare set to appropriately descriptive values. 1914ca1ab94SDag-Erling Smørgrav.Sh ENVIRONMENT 192db5f8cebSDag-Erling SmørgravThe FTP and HTTP related functions use the 1934ca1ab94SDag-Erling Smørgrav.Ev HTTP_PROXY 1944ca1ab94SDag-Erling Smørgravand 1954ca1ab94SDag-Erling Smørgrav.Ev FTP_PROXY 1964ca1ab94SDag-Erling Smørgravenvironment variables, respectively, as the address of a proxy server 1974ca1ab94SDag-Erling Smørgravto use for transferring files. 1984ca1ab94SDag-Erling Smørgrav.Sh SEE ALSO 1994ca1ab94SDag-Erling Smørgrav.Xr fetch 1 , 200db5f8cebSDag-Erling Smørgrav.Xr ftpio 3 2014ca1ab94SDag-Erling Smørgrav.Rs 2024ca1ab94SDag-Erling Smørgrav.%A T. Berners-Lee, L. Masinter & M. McCahill 2034ca1ab94SDag-Erling Smørgrav.%D December 1994 2044ca1ab94SDag-Erling Smørgrav.%T Uniform Resource Locators (URL) 2054ca1ab94SDag-Erling Smørgrav.%O RFC1738 2064ca1ab94SDag-Erling Smørgrav.Re 2074ca1ab94SDag-Erling Smørgrav.Rs 2084ca1ab94SDag-Erling Smørgrav.%A R. Fielding, J. Gettys, J. Mogul, H. Frystyk, T. Berners-Lee 2094ca1ab94SDag-Erling Smørgrav.%D Januray 1997 2104ca1ab94SDag-Erling Smørgrav.%B Hypertext Transfer Protocol -- HTTP/1.1 2114ca1ab94SDag-Erling Smørgrav.%O RFC2068 2124ca1ab94SDag-Erling Smørgrav.Re 2134ca1ab94SDag-Erling Smørgrav.Rs 2144ca1ab94SDag-Erling Smørgrav.%A J. Postel, J. K. Reynolds 2154ca1ab94SDag-Erling Smørgrav.%D October 1985 2164ca1ab94SDag-Erling Smørgrav.%B File Transfer Protocol 2174ca1ab94SDag-Erling Smørgrav.%O RFC959 2184ca1ab94SDag-Erling Smørgrav.Re 2194ca1ab94SDag-Erling Smørgrav.Sh DIAGNOSTICS 2204ca1ab94SDag-Erling SmørgravAdd later. 2214ca1ab94SDag-Erling Smørgrav.Sh NOTES 2224ca1ab94SDag-Erling SmørgravSome parts of the library are not yet implemented. The most notable 2234ca1ab94SDag-Erling Smørgravexamples of this are 2244ca1ab94SDag-Erling Smørgrav.Fn fetchPutHTTP 2254ca1ab94SDag-Erling Smørgravand proxy support for the FTP access method. 2264ca1ab94SDag-Erling Smørgrav.Sh HISTORY 2274ca1ab94SDag-Erling SmørgravThe 2284ca1ab94SDag-Erling Smørgrav.Nm fetch 2294ca1ab94SDag-Erling Smørgravlibrary first appeared in 2304ca1ab94SDag-Erling Smørgrav.Fx 3.0 . 2314ca1ab94SDag-Erling Smørgrav.Sh AUTHORS 2324ca1ab94SDag-Erling SmørgravThe 2334ca1ab94SDag-Erling Smørgrav.Nm fetch 2344ca1ab94SDag-Erling Smørgravlibrary was mostly written by 2354ca1ab94SDag-Erling Smørgrav.An Dag-Erling Co�dan Sm�rgrav Aq des@FreeBSD.org 2364ca1ab94SDag-Erling Smørgravwith numerous suggestions from 2374ca1ab94SDag-Erling Smørgrav.An Jordan K. Hubbard Aq jkh@FreeBSD.org 2384ca1ab94SDag-Erling Smørgravand other FreeBSD developers. 2394ca1ab94SDag-Erling SmørgravIt incorporates the older 2404ca1ab94SDag-Erling Smørgrav.Nm ftpio 2414ca1ab94SDag-Erling Smørgravlibrary, which was originally written by 2424ca1ab94SDag-Erling Smørgrav.Nm Poul-Henning Kamp Aq pkh@FreeBSD.org 2434ca1ab94SDag-Erling Smørgravand later turned inside out by 2444ca1ab94SDag-Erling Smørgrav.An Jordan K. Hubbard Aq jkh@FreeBSD.org . 2454ca1ab94SDag-Erling Smørgrav.Pp 2464ca1ab94SDag-Erling SmørgravThis manual page was written by 2474ca1ab94SDag-Erling Smørgrav.An Dag-Erling Co�dan Sm�rgrav Aq des@FreeBSD.org 2484ca1ab94SDag-Erling Smørgrav.Sh BUGS 249db5f8cebSDag-Erling SmørgravThere's no way to select a proxy at run-time other than setting the 250db5f8cebSDag-Erling Smørgrav.Ev HTTP_PROXY 251db5f8cebSDag-Erling Smørgravor 252db5f8cebSDag-Erling Smørgrav.Ev FTP_PROXY 253db5f8cebSDag-Erling Smørgravenvironment variables as appropriate. There is also no way to stop the 254db5f8cebSDag-Erling SmørgravFTP and HTTP functions from trying to use a proxy if these variables 255db5f8cebSDag-Erling Smørgravare set. 256db5f8cebSDag-Erling Smørgrav.Pp 257db5f8cebSDag-Erling SmørgravHTTP authentication doesn't work. I'm not sure that's a bug in my 258db5f8cebSDag-Erling Smørgravcode; as far as I can determine, 259db5f8cebSDag-Erling Smørgrav.Nm libfetch 260db5f8cebSDag-Erling Smørgravhandles HTTP/1.1 basic authentication correctly as outlined in 261db5f8cebSDag-Erling SmørgravRFC2068, but I haven't been able to find an HTTP server that honors 262842a95ccSDag-Erling Smørgravthe Authentication: header field. Also, 263842a95ccSDag-Erling Smørgrav.Nm libfetch 264842a95ccSDag-Erling Smørgravdoes not attempt to interpret and respond to authentication requests 265842a95ccSDag-Erling Smørgravfrom the HTTP server. 266842a95ccSDag-Erling Smørgrav.Pp 267842a95ccSDag-Erling SmørgravNo attempt is made to encode spaces etc. within URLs. Spaces in the 268842a95ccSDag-Erling Smørgravdocument part of an URLshould be replaced with "%20" in HTTP URLs and 269842a95ccSDag-Erling Smørgrav"\\ " in FTP URLs. 270842a95ccSDag-Erling Smørgrav.Pp 271842a95ccSDag-Erling SmørgravError numbers are unique only within a certain context; the error 272842a95ccSDag-Erling Smørgravcodes used for FTP and HTTP overlap, as do those used for resolver and 273842a95ccSDag-Erling Smørgravsystem errors. For instance, error code 202 means "Command not 274842a95ccSDag-Erling Smørgravimplemented, superfluous at this site" in an FTP context and 275842a95ccSDag-Erling Smørgrav"Accepted" in an HTTP context. 276842a95ccSDag-Erling Smørgrav.Pp 277842a95ccSDag-Erling SmørgravThe man page is poorly written and produces badly formatted text. 278db5f8cebSDag-Erling Smørgrav.Pp 279db5f8cebSDag-Erling SmørgravTons of other stuff. 280