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.\" 257f3dea24SPeter Wemm.\" $FreeBSD$ 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 319a964d6aSDag-Erling Smørgrav.Nm fetchMakeURL , 3260245e42SDag-Erling Smørgrav.Nm fetchParseURL , 3360245e42SDag-Erling Smørgrav.Nm fetchFreeURL , 341a5faa10SDag-Erling Smørgrav.Nm fetchXGetURL , 354ca1ab94SDag-Erling Smørgrav.Nm fetchGetURL , 364ca1ab94SDag-Erling Smørgrav.Nm fetchPutURL , 37d8acd8dcSDag-Erling Smørgrav.Nm fetchStatURL , 38ce71b736SDag-Erling Smørgrav.Nm fetchListURL , 391a5faa10SDag-Erling Smørgrav.Nm fetchXGet , 40db5f8cebSDag-Erling Smørgrav.Nm fetchGet , 41db5f8cebSDag-Erling Smørgrav.Nm fetchPut , 42d8acd8dcSDag-Erling Smørgrav.Nm fetchStat , 43ce71b736SDag-Erling Smørgrav.Nm fetchList , 441a5faa10SDag-Erling Smørgrav.Nm fetchXGetFile , 454ca1ab94SDag-Erling Smørgrav.Nm fetchGetFile , 464ca1ab94SDag-Erling Smørgrav.Nm fetchPutFile , 47d8acd8dcSDag-Erling Smørgrav.Nm fetchStatFile , 48ce71b736SDag-Erling Smørgrav.Nm fetchListFile , 491a5faa10SDag-Erling Smørgrav.Nm fetchXGetHTTP , 504ca1ab94SDag-Erling Smørgrav.Nm fetchGetHTTP , 514ca1ab94SDag-Erling Smørgrav.Nm fetchPutHTTP , 52d8acd8dcSDag-Erling Smørgrav.Nm fetchStatHTTP , 53ce71b736SDag-Erling Smørgrav.Nm fetchListHTTP , 541a5faa10SDag-Erling Smørgrav.Nm fetchXGetFTP , 554ca1ab94SDag-Erling Smørgrav.Nm fetchGetFTP , 5615efcd39SAlexey Zelkin.Nm fetchPutFTP , 5715efcd39SAlexey Zelkin.Nm fetchStatFTP , 5815efcd39SAlexey Zelkin.Nm fetchListFTP 5915efcd39SAlexey Zelkin.Nd file transfer functions 6015efcd39SAlexey Zelkin.Sh LIBRARY 6115efcd39SAlexey Zelkin.Lb libfetch 624ca1ab94SDag-Erling Smørgrav.Sh SYNOPSIS 630fba3a00SDag-Erling Smørgrav.Fd #include <sys/param.h> 640fba3a00SDag-Erling Smørgrav.Fd #include <stdio.h> 654ca1ab94SDag-Erling Smørgrav.Fd #include <fetch.h> 6660245e42SDag-Erling Smørgrav.Ft struct url * 679a964d6aSDag-Erling Smørgrav.Fn fetchMakeURL "char *scheme" "char *host" "int port" "char *doc" "char *user" "char *pwd" 689a964d6aSDag-Erling Smørgrav.Ft struct url * 6960245e42SDag-Erling Smørgrav.Fn fetchParseURL "char *URL" 7060245e42SDag-Erling Smørgrav.Ft void 7160245e42SDag-Erling Smørgrav.Fn fetchFreeURL "struct url *URL" 72db5f8cebSDag-Erling Smørgrav.Ft FILE * 731a5faa10SDag-Erling Smørgrav.Fn fetchXGetURL "char *URL" "struct url_stat *us" "char *flags" 741a5faa10SDag-Erling Smørgrav.Ft FILE * 75db5f8cebSDag-Erling Smørgrav.Fn fetchGetURL "char *URL" "char *flags" 76db5f8cebSDag-Erling Smørgrav.Ft FILE * 77db5f8cebSDag-Erling Smørgrav.Fn fetchPutURL "char *URL" "char *flags" 78d8acd8dcSDag-Erling Smørgrav.Ft int 79d8acd8dcSDag-Erling Smørgrav.Fn fetchStatURL "char *URL" "struct url_stat *us" "char *flags" 80ce71b736SDag-Erling Smørgrav.Ft struct url_ent * 81ce71b736SDag-Erling Smørgrav.Fn fetchListURL "char *URL" "char *flags" 824ca1ab94SDag-Erling Smørgrav.Ft FILE * 831a5faa10SDag-Erling Smørgrav.Fn fetchXGet "struct url *URL" "struct url_stat *us" "char *flags" 841a5faa10SDag-Erling Smørgrav.Ft FILE * 85d8acd8dcSDag-Erling Smørgrav.Fn fetchGet "struct url *URL" "char *flags" 86db5f8cebSDag-Erling Smørgrav.Ft FILE * 87d8acd8dcSDag-Erling Smørgrav.Fn fetchPut "struct url *URL" "char *flags" 88d8acd8dcSDag-Erling Smørgrav.Ft int 89d8acd8dcSDag-Erling Smørgrav.Fn fetchStat "struct url *URL" "struct url_stat *us" "char *flags" 90ce71b736SDag-Erling Smørgrav.Ft struct url_ent * 91ce71b736SDag-Erling Smørgrav.Fn fetchList "struct url *" "char *flags" 92db5f8cebSDag-Erling Smørgrav.Ft FILE * 931a5faa10SDag-Erling Smørgrav.Fn fetchXGetFile "struct url *u" "struct url_stat *us" "char *flags" 941a5faa10SDag-Erling Smørgrav.Ft FILE * 95d8acd8dcSDag-Erling Smørgrav.Fn fetchGetFile "struct url *u" "char *flags" 964ca1ab94SDag-Erling Smørgrav.Ft FILE * 97d8acd8dcSDag-Erling Smørgrav.Fn fetchPutFile "struct url *u" "char *flags" 98d8acd8dcSDag-Erling Smørgrav.Ft int 99d8acd8dcSDag-Erling Smørgrav.Fn fetchStatFile "struct url *URL" "struct url_stat *us" "char *flags" 100ce71b736SDag-Erling Smørgrav.Ft struct url_ent * 101ce71b736SDag-Erling Smørgrav.Fn fetchListFile "struct url *" "char *flags" 1024ca1ab94SDag-Erling Smørgrav.Ft FILE * 1031a5faa10SDag-Erling Smørgrav.Fn fetchXGetHTTP "struct url *u" "struct url_stat *us" "char *flags" 1041a5faa10SDag-Erling Smørgrav.Ft FILE * 105d8acd8dcSDag-Erling Smørgrav.Fn fetchGetHTTP "struct url *u" "char *flags" 1064ca1ab94SDag-Erling Smørgrav.Ft FILE * 107d8acd8dcSDag-Erling Smørgrav.Fn fetchPutHTTP "struct url *u" "char *flags" 108d8acd8dcSDag-Erling Smørgrav.Ft int 109d8acd8dcSDag-Erling Smørgrav.Fn fetchStatHTTP "struct url *URL" "struct url_stat *us" "char *flags" 110ce71b736SDag-Erling Smørgrav.Ft struct url_ent * 111ce71b736SDag-Erling Smørgrav.Fn fetchListHTTP "struct url *" "char *flags" 1124ca1ab94SDag-Erling Smørgrav.Ft FILE * 1131a5faa10SDag-Erling Smørgrav.Fn fetchXGetFTP "struct url *u" "struct url_stat *us" "char *flags" 1141a5faa10SDag-Erling Smørgrav.Ft FILE * 115d8acd8dcSDag-Erling Smørgrav.Fn fetchGetFTP "struct url *u" "char *flags" 1164ca1ab94SDag-Erling Smørgrav.Ft FILE * 117d8acd8dcSDag-Erling Smørgrav.Fn fetchPutFTP "struct url *u" "char *flags" 118d8acd8dcSDag-Erling Smørgrav.Ft int 119d8acd8dcSDag-Erling Smørgrav.Fn fetchStatFTP "struct url *URL" "struct url_stat *us" "char *flags" 120ce71b736SDag-Erling Smørgrav.Ft struct url_ent * 121ce71b736SDag-Erling Smørgrav.Fn fetchListFTP "struct url *" "char *flags" 1224ca1ab94SDag-Erling Smørgrav.Sh DESCRIPTION 123d8acd8dcSDag-Erling Smørgrav.Pp 1244ca1ab94SDag-Erling SmørgravThese functions implement a high-level library for retrieving and 1254ca1ab94SDag-Erling Smørgravuploading files using Uniform Resource Locators (URLs). 1264ca1ab94SDag-Erling Smørgrav.Pp 12760245e42SDag-Erling Smørgrav.Fn fetchParseURL 12860245e42SDag-Erling Smørgravtakes a URL in the form of a null-terminated string and splits it into 12960245e42SDag-Erling Smørgravits components function according to the Common Internet Scheme Syntax 1309364c532SDag-Erling Smørgravdetailed in RFC1738. 1319364c532SDag-Erling SmørgravA regular expression which produces this syntax is: 13260245e42SDag-Erling Smørgrav.Bd -literal 13360245e42SDag-Erling Smørgrav <scheme>:(//(<user>(:<pwd>)?@)?<host>(:<port>)?)?/(<document>)? 13460245e42SDag-Erling Smørgrav.Ed 13560245e42SDag-Erling Smørgrav.Pp 13660245e42SDag-Erling SmørgravNote that some components of the URL are not necessarily relevant to 13760245e42SDag-Erling Smørgravall URL schemes. 13860245e42SDag-Erling SmørgravFor instance, the file scheme only needs the <scheme> 13960245e42SDag-Erling Smørgravand <document> components. 14060245e42SDag-Erling Smørgrav.Pp 1419a964d6aSDag-Erling Smørgrav.Fn fetchMakeURL 1429a964d6aSDag-Erling Smørgravand 14340ac2845SDag-Erling Smørgrav.Fn fetchParseURL 1449a964d6aSDag-Erling Smørgravreturn a pointer to a 14540ac2845SDag-Erling Smørgrav.Fa url 14640ac2845SDag-Erling Smørgravstructure, which is defined as follows in 14740ac2845SDag-Erling Smørgrav.Aq Pa fetch.h : 14840ac2845SDag-Erling Smørgrav.Bd -literal 14940ac2845SDag-Erling Smørgrav#define URL_SCHEMELEN 16 15040ac2845SDag-Erling Smørgrav#define URL_USERLEN 256 15140ac2845SDag-Erling Smørgrav#define URL_PWDLEN 256 15240ac2845SDag-Erling Smørgrav 15340ac2845SDag-Erling Smørgravstruct url { 15440ac2845SDag-Erling Smørgrav char scheme[URL_SCHEMELEN+1]; 15540ac2845SDag-Erling Smørgrav char user[URL_USERLEN+1]; 15640ac2845SDag-Erling Smørgrav char pwd[URL_PWDLEN+1]; 15740ac2845SDag-Erling Smørgrav char host[MAXHOSTNAMELEN+1]; 15840ac2845SDag-Erling Smørgrav int port; 15940ac2845SDag-Erling Smørgrav char *doc; 16040ac2845SDag-Erling Smørgrav off_t offset; 16140ac2845SDag-Erling Smørgrav size_t length; 16240ac2845SDag-Erling Smørgrav}; 16340ac2845SDag-Erling Smørgrav.Ed 16440ac2845SDag-Erling Smørgrav.Pp 16560245e42SDag-Erling SmørgravThe pointer returned by 1669a964d6aSDag-Erling Smørgrav.Fn fetchMakeURL 1679a964d6aSDag-Erling Smørgravor 16860245e42SDag-Erling Smørgrav.Fn fetchParseURL 16960245e42SDag-Erling Smørgravshould be freed using 17060245e42SDag-Erling Smørgrav.Fn fetchFreeURL . 17160245e42SDag-Erling Smørgrav.Pp 1721a5faa10SDag-Erling Smørgrav.Fn fetchXGetURL , 1731a5faa10SDag-Erling Smørgrav.Fn fetchGetURL , 174db5f8cebSDag-Erling Smørgravand 175db5f8cebSDag-Erling Smørgrav.Fn fetchPutURL 176db5f8cebSDag-Erling Smørgravconstitute the recommended interface to the 177db5f8cebSDag-Erling Smørgrav.Nm fetch 178c6ff3a1bSSheldon Hearnlibrary. 179c6ff3a1bSSheldon HearnThey examine the URL passed to them to determine the transfer 180db5f8cebSDag-Erling Smørgravmethod, and call the appropriate lower-level functions to perform the 181c6ff3a1bSSheldon Hearnactual transfer. 1821a5faa10SDag-Erling Smørgrav.Fn fetchXGetURL 1831a5faa10SDag-Erling Smørgravalso returns the remote document's metadata in the 1841a5faa10SDag-Erling Smørgrav.Fa url_stat 1851a5faa10SDag-Erling Smørgravstructure pointed to by the 1861a5faa10SDag-Erling Smørgrav.Fa us 1871a5faa10SDag-Erling Smørgravargument. 1881a5faa10SDag-Erling Smørgrav.Pp 189c6ff3a1bSSheldon HearnThe 190db5f8cebSDag-Erling Smørgrav.Fa flags 191c6ff3a1bSSheldon Hearnargument is a string of characters which specify transfer options. 192c6ff3a1bSSheldon HearnThe 193db5f8cebSDag-Erling Smørgravmeaning of the individual flags is scheme-dependent, and is detailed 194db5f8cebSDag-Erling Smørgravin the appropriate section below. 195db5f8cebSDag-Erling Smørgrav.Pp 196d8acd8dcSDag-Erling Smørgrav.Fn fetchStatURL 197d8acd8dcSDag-Erling Smørgravattempts to obtain the requested document's metadata and fill in the 198c6ff3a1bSSheldon Hearnstructure pointed to by it's second argument. 199c6ff3a1bSSheldon HearnThe 200d8acd8dcSDag-Erling Smørgrav.Fa url_stat 201d8acd8dcSDag-Erling Smørgravstructure is defined as follows in 202d8acd8dcSDag-Erling Smørgrav.Aq Pa fetch.h : 203d8acd8dcSDag-Erling Smørgrav.Bd -literal 204d8acd8dcSDag-Erling Smørgravstruct url_stat { 205d8acd8dcSDag-Erling Smørgrav off_t size; 2065aea254fSDag-Erling Smørgrav time_t atime; 2075aea254fSDag-Erling Smørgrav time_t mtime; 208d8acd8dcSDag-Erling Smørgrav}; 209d8acd8dcSDag-Erling Smørgrav.Ed 210d8acd8dcSDag-Erling Smørgrav.Pp 21140ac2845SDag-Erling SmørgravIf the size could not be obtained from the server, the 21240ac2845SDag-Erling Smørgrav.Fa size 21340ac2845SDag-Erling Smørgravfield is set to -1. 21440ac2845SDag-Erling SmørgravIf the modification time could not be obtained from the server, the 21540ac2845SDag-Erling Smørgrav.Fa mtime 21640ac2845SDag-Erling Smørgravfield is set to the epoch. 21740ac2845SDag-Erling SmørgravIf the access time could not be obtained from the server, the 21840ac2845SDag-Erling Smørgrav.Fa atime 21940ac2845SDag-Erling Smørgravfield is set to the modification time. 22040ac2845SDag-Erling Smørgrav.Pp 221ce71b736SDag-Erling Smørgrav.Fn fetchListURL 222ce71b736SDag-Erling Smørgravattempts to list the contents of the directory pointed to by the URL 223c6ff3a1bSSheldon Hearnprovided. 224c6ff3a1bSSheldon HearnIf successful, it returns a malloced array of 225ce71b736SDag-Erling Smørgrav.Fa url_ent 226c6ff3a1bSSheldon Hearnstructures. 227c6ff3a1bSSheldon HearnThe 228ce71b736SDag-Erling Smørgrav.Fa url_ent 229ce71b736SDag-Erling Smørgravstructure is defined as follows in 230ce71b736SDag-Erling Smørgrav.Aq Pa fetch.h : 231ce71b736SDag-Erling Smørgrav.Bd -literal 232ce71b736SDag-Erling Smørgravstruct url_ent { 233ce71b736SDag-Erling Smørgrav char name[MAXPATHLEN]; 234ce71b736SDag-Erling Smørgrav struct url_stat stat; 235ce71b736SDag-Erling Smørgrav}; 236ce71b736SDag-Erling Smørgrav.Ed 237ce71b736SDag-Erling Smørgrav.Pp 238ce71b736SDag-Erling SmørgravThe list is terminated by an entry with an empty name. 239ce71b736SDag-Erling Smørgrav.Pp 240ce71b736SDag-Erling SmørgravThe pointer returned by 241ce71b736SDag-Erling Smørgrav.Fn fetchListURL 242ce71b736SDag-Erling Smørgravshould be freed using 243ce71b736SDag-Erling Smørgrav.Fn free . 244ce71b736SDag-Erling Smørgrav.Pp 2451a5faa10SDag-Erling Smørgrav.Fn fetchXGet , 246d8acd8dcSDag-Erling Smørgrav.Fn fetchGet , 247db5f8cebSDag-Erling Smørgrav.Fn fetchPut 2484ca1ab94SDag-Erling Smørgravand 249d8acd8dcSDag-Erling Smørgrav.Fn fetchStat 250d8acd8dcSDag-Erling Smørgravare similar to 2511a5faa10SDag-Erling Smørgrav.Fn fetchXGetURL , 252d8acd8dcSDag-Erling Smørgrav.Fn fetchGetURL , 253d8acd8dcSDag-Erling Smørgrav.Fn fetchPutURL 254d8acd8dcSDag-Erling Smørgravand 255d8acd8dcSDag-Erling Smørgrav.Fn fetchStatURL , 256db5f8cebSDag-Erling Smørgravexcept that they expect a pre-parsed URL in the form of a pointer to 257d8acd8dcSDag-Erling Smørgrava 258d8acd8dcSDag-Erling Smørgrav.Fa struct url 259d8acd8dcSDag-Erling Smørgravrather than a string. 2604ca1ab94SDag-Erling Smørgrav.Pp 2614ca1ab94SDag-Erling SmørgravAll of the 2621a5faa10SDag-Erling Smørgrav.Fn fetchXGetXXX , 2634ca1ab94SDag-Erling Smørgrav.Fn fetchGetXXX 2644ca1ab94SDag-Erling Smørgravand 2654ca1ab94SDag-Erling Smørgrav.Fn fetchPutXXX 2664ca1ab94SDag-Erling Smørgravfunctions return a pointer to a stream which can be used to read or 267c6ff3a1bSSheldon Hearnwrite data from or to the requested document, respectively. 268c6ff3a1bSSheldon HearnNote that 2694ca1ab94SDag-Erling Smørgravalthough the implementation details of the individual access methods 2704ca1ab94SDag-Erling Smørgravvary, it can generally be assumed that a stream returned by one of the 2711a5faa10SDag-Erling Smørgrav.Fn fetchXGetXXX 2721a5faa10SDag-Erling Smørgravor 2734ca1ab94SDag-Erling Smørgrav.Fn fetchGetXXX 2744ca1ab94SDag-Erling Smørgravfunctions is read-only, and that a stream returned by one of the 2754ca1ab94SDag-Erling Smørgrav.Fn fetchPutXXX 2764ca1ab94SDag-Erling Smørgravfunctions is write-only. 2774ca1ab94SDag-Erling Smørgrav.Sh FILE SCHEME 2781a5faa10SDag-Erling Smørgrav.Fn fetchXGetFile , 2794ca1ab94SDag-Erling Smørgrav.Fn fetchGetFile 2804ca1ab94SDag-Erling Smørgravand 2814ca1ab94SDag-Erling Smørgrav.Fn fetchPutFile 2824ca1ab94SDag-Erling Smørgravprovide access to documents which are files in a locally mounted file 283c6ff3a1bSSheldon Hearnsystem. 284c6ff3a1bSSheldon HearnOnly the <document> component of the URL is used. 2854ca1ab94SDag-Erling Smørgrav.Pp 2861a5faa10SDag-Erling Smørgrav.Fn fetchXGetFile 2871a5faa10SDag-Erling Smørgravand 2884ca1ab94SDag-Erling Smørgrav.Fn fetchGetFile 2891a5faa10SDag-Erling Smørgravdo not accept any flags. 2904ca1ab94SDag-Erling Smørgrav.Pp 2914ca1ab94SDag-Erling Smørgrav.Fn fetchPutFile 2924ca1ab94SDag-Erling Smørgravaccepts the 2934ca1ab94SDag-Erling Smørgrav.Fa a 294c6ff3a1bSSheldon Hearn(append to file) flag. 295c6ff3a1bSSheldon HearnIf that flag is specified, the data written to 2964ca1ab94SDag-Erling Smørgravthe stream returned by 2974ca1ab94SDag-Erling Smørgrav.Fn fetchPutFile 2984ca1ab94SDag-Erling Smørgravwill be appended to the previous contents of the file, instead of 2994ca1ab94SDag-Erling Smørgravreplacing them. 3004ca1ab94SDag-Erling Smørgrav.Sh FTP SCHEME 3011a5faa10SDag-Erling Smørgrav.Fn fetchXGetFTP , 3024ca1ab94SDag-Erling Smørgrav.Fn fetchGetFTP 3034ca1ab94SDag-Erling Smørgravand 3044ca1ab94SDag-Erling Smørgrav.Fn fetchPutFTP 3054ca1ab94SDag-Erling Smørgravimplement the FTP protocol as described in RFC959. 3064ca1ab94SDag-Erling Smørgrav.Pp 3074ca1ab94SDag-Erling SmørgravIf the 3084ca1ab94SDag-Erling Smørgrav.Fa p 3094ca1ab94SDag-Erling Smørgrav(passive) flag is specified, a passive (rather than active) connection 3104ca1ab94SDag-Erling Smørgravwill be attempted. 3114ca1ab94SDag-Erling Smørgrav.Pp 312f5f109a0SDag-Erling SmørgravIf the 313f5f109a0SDag-Erling Smørgrav.Fa h 314f5f109a0SDag-Erling Smørgrav(high) flag is specified, data sockets will be allocated in the high 315f5f109a0SDag-Erling Smørgravport range (see 316f5f109a0SDag-Erling Smørgrav.Xr ip 4 ). 317f5f109a0SDag-Erling Smørgrav.Pp 318f5f109a0SDag-Erling SmørgravIf the 319f5f109a0SDag-Erling Smørgrav.Fa d 320f5f109a0SDag-Erling Smørgrav(direct) flag is specified, 3211a5faa10SDag-Erling Smørgrav.Fn fetchXGetFTP , 322f5f109a0SDag-Erling Smørgrav.Fn fetchGetFTP 323f5f109a0SDag-Erling Smørgravand 324f5f109a0SDag-Erling Smørgrav.Fn fetchPutFTP 325f5f109a0SDag-Erling Smørgravwill use a direct connection even if a proxy server is defined. 326f5f109a0SDag-Erling Smørgrav.Pp 3274ca1ab94SDag-Erling SmørgravIf no user name or password is given, the 3284ca1ab94SDag-Erling Smørgrav.Nm fetch 3294ca1ab94SDag-Erling Smørgravlibrary will attempt an anonymous login, with user name "ftp" and 3304ca1ab94SDag-Erling Smørgravpassword "ftp". 3314ca1ab94SDag-Erling Smørgrav.Sh HTTP SCHEME 3324ca1ab94SDag-Erling SmørgravThe 3331a5faa10SDag-Erling Smørgrav.Fn fetchXGetHTTP , 3344ca1ab94SDag-Erling Smørgrav.Fn fetchGetHTTP 3354ca1ab94SDag-Erling Smørgravand 3364ca1ab94SDag-Erling Smørgrav.Fn fetchPutHTTP 337c6ff3a1bSSheldon Hearnfunctions implement the HTTP/1.1 protocol. 338c6ff3a1bSSheldon HearnWith a little luck, there's 3394ca1ab94SDag-Erling Smørgraveven a chance that they comply with RFC2068. 3404ca1ab94SDag-Erling Smørgrav.Pp 341f5f109a0SDag-Erling SmørgravIf the 342f5f109a0SDag-Erling Smørgrav.Fa d 343f5f109a0SDag-Erling Smørgrav(direct) flag is specified, 3441a5faa10SDag-Erling Smørgrav.Fn fetchXGetHTTP , 345f5f109a0SDag-Erling Smørgrav.Fn fetchGetHTTP 346f5f109a0SDag-Erling Smørgravand 347f5f109a0SDag-Erling Smørgrav.Fn fetchPutHTTP 348f5f109a0SDag-Erling Smørgravwill use a direct connection even if a proxy server is defined. 349f5f109a0SDag-Erling Smørgrav.Pp 3504ca1ab94SDag-Erling SmørgravSince there seems to be no good way of implementing the HTTP PUT 3514ca1ab94SDag-Erling Smørgravmethod in a manner consistent with the rest of the 3524ca1ab94SDag-Erling Smørgrav.Nm fetch 3534ca1ab94SDag-Erling Smørgravlibrary, 3544ca1ab94SDag-Erling Smørgrav.Fn fetchPutHTTP 3554ca1ab94SDag-Erling Smørgravis currently unimplemented. 3564ca1ab94SDag-Erling Smørgrav.Sh RETURN VALUES 3574ca1ab94SDag-Erling Smørgrav.Fn fetchParseURL 3584ca1ab94SDag-Erling Smørgravreturns a pointer to a 359d8acd8dcSDag-Erling Smørgrav.Fa struct url 360c6ff3a1bSSheldon Hearncontaining the individual components of the URL. 361c6ff3a1bSSheldon HearnIf it is 3624ca1ab94SDag-Erling Smørgravunable to allocate memory, or the URL is syntactically incorrect, 3634ca1ab94SDag-Erling Smørgrav.Fn fetchParseURL 3644ca1ab94SDag-Erling Smørgravreturns a NULL pointer. 3654ca1ab94SDag-Erling Smørgrav.Pp 366d8acd8dcSDag-Erling SmørgravThe 367d8acd8dcSDag-Erling Smørgrav.Fn fetchStat 368d8acd8dcSDag-Erling Smørgravfunctions return 0 on success and -1 on failure. 369d8acd8dcSDag-Erling Smørgrav.Pp 3704ca1ab94SDag-Erling SmørgravAll other functions return a stream pointer which may be used to 371d8acd8dcSDag-Erling Smørgravaccess the requested document, or NULL if an error occurred. 372d8acd8dcSDag-Erling Smørgrav.Pp 373ba101983SDag-Erling SmørgravThe following error codes are defined in 374ba101983SDag-Erling Smørgrav.Aq Pa fetch.h : 37515efcd39SAlexey Zelkin.Bl -tag -width 18n 376d8acd8dcSDag-Erling Smørgrav.It Bq Er FETCH_ABORT 377d8acd8dcSDag-Erling SmørgravOperation aborted 378d8acd8dcSDag-Erling Smørgrav.It Bq Er FETCH_AUTH 379d8acd8dcSDag-Erling SmørgravAuthentication failed 380d8acd8dcSDag-Erling Smørgrav.It Bq Er FETCH_DOWN 381d8acd8dcSDag-Erling SmørgravService unavailable 382d8acd8dcSDag-Erling Smørgrav.It Bq Er FETCH_EXISTS 383d8acd8dcSDag-Erling SmørgravFile exists 384d8acd8dcSDag-Erling Smørgrav.It Bq Er FETCH_FULL 385d8acd8dcSDag-Erling SmørgravFile system full 386d8acd8dcSDag-Erling Smørgrav.It Bq Er FETCH_INFO 387d8acd8dcSDag-Erling SmørgravInformational response 388d8acd8dcSDag-Erling Smørgrav.It Bq Er FETCH_MEMORY 389d8acd8dcSDag-Erling SmørgravInsufficient memory 390d8acd8dcSDag-Erling Smørgrav.It Bq Er FETCH_MOVED 391d8acd8dcSDag-Erling SmørgravFile has moved 392d8acd8dcSDag-Erling Smørgrav.It Bq Er FETCH_NETWORK 393d8acd8dcSDag-Erling SmørgravNetwork error 394d8acd8dcSDag-Erling Smørgrav.It Bq Er FETCH_OK 395d8acd8dcSDag-Erling SmørgravNo error 396d8acd8dcSDag-Erling Smørgrav.It Bq Er FETCH_PROTO 397d8acd8dcSDag-Erling SmørgravProtocol error 398d8acd8dcSDag-Erling Smørgrav.It Bq Er FETCH_RESOLV 399d8acd8dcSDag-Erling SmørgravResolver error 400d8acd8dcSDag-Erling Smørgrav.It Bq Er FETCH_SERVER 401d8acd8dcSDag-Erling SmørgravServer error 402d8acd8dcSDag-Erling Smørgrav.It Bq Er FETCH_TEMP 403d8acd8dcSDag-Erling SmørgravTemporary error 404d8acd8dcSDag-Erling Smørgrav.It Bq Er FETCH_TIMEOUT 405d8acd8dcSDag-Erling SmørgravOperation timed out 406d8acd8dcSDag-Erling Smørgrav.It Bq Er FETCH_UNAVAIL 407d8acd8dcSDag-Erling SmørgravFile is not available 408d8acd8dcSDag-Erling Smørgrav.It Bq Er FETCH_UNKNOWN 409d8acd8dcSDag-Erling SmørgravUnknown error 410d8acd8dcSDag-Erling Smørgrav.It Bq Er FETCH_URL 411d8acd8dcSDag-Erling SmørgravInvalid URL 412d8acd8dcSDag-Erling Smørgrav.El 413d8acd8dcSDag-Erling Smørgrav.Pp 414d8acd8dcSDag-Erling SmørgravThe accompanying error message includes a protocol-specific error code 415d8acd8dcSDag-Erling Smørgravand message, e.g. "File is not available (404 Not Found)" 4164ca1ab94SDag-Erling Smørgrav.Sh ENVIRONMENT 417bc2a5e68SDag-Erling Smørgrav.Bl -tag -width HTTP_PROXY_AUTH 418bc2a5e68SDag-Erling Smørgrav.It Ev FTP_PROXY 41989d755e1SDag-Erling SmørgravHost name of the FTP proxy to use, optionally followed by a port 420bc2a5e68SDag-Erling Smørgravnumber separated from the host name by a colon. 421e0a9ca38SDag-Erling Smørgrav.Nm libfetch 422e0a9ca38SDag-Erling Smørgravwill send 423e0a9ca38SDag-Erling Smørgrav.Ql user@host 424e0a9ca38SDag-Erling Smørgravas user name to the proxy, where 425e0a9ca38SDag-Erling Smørgrav.Ql user 426e0a9ca38SDag-Erling Smørgravis the real user name, and 427e0a9ca38SDag-Erling Smørgrav.Ql host 428e0a9ca38SDag-Erling Smørgravis the name of the FTP server. 42989d755e1SDag-Erling Smørgrav.Pp 4302e83f638SDag-Erling SmørgravIf this variable is set to an empty string, no proxy will be used for 4312e83f638SDag-Erling SmørgravFTP requests, even if the 4322e83f638SDag-Erling Smørgrav.Ev HTTP_PROXY 4332e83f638SDag-Erling Smørgravvariable is set. 43498f5573fSDag-Erling Smørgrav.It Ev HTTP_AUTH 43589d755e1SDag-Erling SmørgravSpecifies HTTP authorization parameters as a colon-separated list of 43689d755e1SDag-Erling Smørgravitems. 43798f5573fSDag-Erling SmørgravThe first and second item are the authorization scheme and realm 43898f5573fSDag-Erling Smørgravrespectively; further items are scheme-dependent. 43998f5573fSDag-Erling SmørgravCurrently, only basic authorization is supported. 44089d755e1SDag-Erling Smørgrav.Pp 44198f5573fSDag-Erling SmørgravBasic authorization requires two parameters: the user name and 44298f5573fSDag-Erling Smørgravpassword, in that order. 44389d755e1SDag-Erling Smørgrav.Pp 44489d755e1SDag-Erling SmørgravThis variable is only used if the server requires authorization and 44589d755e1SDag-Erling Smørgravno user name or password was specified in the URL. 446bc2a5e68SDag-Erling Smørgrav.It Ev HTTP_PROXY 447bc2a5e68SDag-Erling Smørgravhost name of the HTTP proxy to use, optionally followed by a port 448bc2a5e68SDag-Erling Smørgravnumber separated from the host name by a colon. 449bc2a5e68SDag-Erling SmørgravIf no port number is specified, the default is 3128. 45089d755e1SDag-Erling Smørgrav.Pp 451e0a9ca38SDag-Erling SmørgravNote that the HTTP proxy will also be used for FTP documents, unless 452e0a9ca38SDag-Erling Smørgravthe 453e0a9ca38SDag-Erling Smørgrav.Ev FTP_PROXY 454e0a9ca38SDag-Erling Smørgravvariable is set. 455bc2a5e68SDag-Erling Smørgrav.It Ev HTTP_PROXY_AUTH 45698f5573fSDag-Erling SmørgravSpecifies authorization parameters for the HTTP proxy in the same 457e0a9ca38SDag-Erling Smørgravformat as the 458e0a9ca38SDag-Erling Smørgrav.Ev HTTP_AUTH 459e0a9ca38SDag-Erling Smørgravvariable. 46089d755e1SDag-Erling Smørgrav.Pp 46198f5573fSDag-Erling SmørgravThe value of this variable is used if and only if connected to an HTTP 46298f5573fSDag-Erling Smørgravproxy. 463bc2a5e68SDag-Erling Smørgrav.El 4644ca1ab94SDag-Erling Smørgrav.Sh SEE ALSO 4654ca1ab94SDag-Erling Smørgrav.Xr fetch 1 , 466f5f109a0SDag-Erling Smørgrav.Xr ftpio 3 , 467f5f109a0SDag-Erling Smørgrav.Xr ip 4 . 4684ca1ab94SDag-Erling Smørgrav.Rs 4690f5fcaa3SSheldon Hearn.%A T. Berners-Lee 4700f5fcaa3SSheldon Hearn.%A L. Masinter 4710f5fcaa3SSheldon Hearn.%A M. McCahill 4724ca1ab94SDag-Erling Smørgrav.%D December 1994 4734ca1ab94SDag-Erling Smørgrav.%T Uniform Resource Locators (URL) 4744ca1ab94SDag-Erling Smørgrav.%O RFC1738 4754ca1ab94SDag-Erling Smørgrav.Re 4764ca1ab94SDag-Erling Smørgrav.Rs 4770f5fcaa3SSheldon Hearn.%A R. Fielding 4780f5fcaa3SSheldon Hearn.%A J. Gettys 4790f5fcaa3SSheldon Hearn.%A J. Mogul 4800f5fcaa3SSheldon Hearn.%A H. Frystyk 4810f5fcaa3SSheldon Hearn.%A T. Berners-Lee 4824ca1ab94SDag-Erling Smørgrav.%D Januray 1997 4834ca1ab94SDag-Erling Smørgrav.%B Hypertext Transfer Protocol -- HTTP/1.1 4844ca1ab94SDag-Erling Smørgrav.%O RFC2068 4854ca1ab94SDag-Erling Smørgrav.Re 4864ca1ab94SDag-Erling Smørgrav.Rs 4870f5fcaa3SSheldon Hearn.%A J. Postel 4880f5fcaa3SSheldon Hearn.%A J. K. Reynolds 4894ca1ab94SDag-Erling Smørgrav.%D October 1985 4904ca1ab94SDag-Erling Smørgrav.%B File Transfer Protocol 4914ca1ab94SDag-Erling Smørgrav.%O RFC959 4924ca1ab94SDag-Erling Smørgrav.Re 4934ca1ab94SDag-Erling Smørgrav.Sh HISTORY 4944ca1ab94SDag-Erling SmørgravThe 4954ca1ab94SDag-Erling Smørgrav.Nm fetch 4964ca1ab94SDag-Erling Smørgravlibrary first appeared in 4974ca1ab94SDag-Erling Smørgrav.Fx 3.0 . 4984ca1ab94SDag-Erling Smørgrav.Sh AUTHORS 4994ca1ab94SDag-Erling SmørgravThe 5004ca1ab94SDag-Erling Smørgrav.Nm fetch 5014ca1ab94SDag-Erling Smørgravlibrary was mostly written by 5024ca1ab94SDag-Erling Smørgrav.An Dag-Erling Co�dan Sm�rgrav Aq des@FreeBSD.org 5034ca1ab94SDag-Erling Smørgravwith numerous suggestions from 504d8acd8dcSDag-Erling Smørgrav.An Jordan K. Hubbard Aq jkh@FreeBSD.org , 505d8acd8dcSDag-Erling Smørgrav.An Eugene Skepner Aq eu@qub.com 5064ca1ab94SDag-Erling Smørgravand other FreeBSD developers. 507d8acd8dcSDag-Erling SmørgravIt replaces the older 5084ca1ab94SDag-Erling Smørgrav.Nm ftpio 509d8acd8dcSDag-Erling Smørgravlibrary written by 510d8acd8dcSDag-Erling Smørgrav.An Poul-Henning Kamp Aq pkh@FreeBSD.org 511d8acd8dcSDag-Erling Smørgravand 5124ca1ab94SDag-Erling Smørgrav.An Jordan K. Hubbard Aq jkh@FreeBSD.org . 5134ca1ab94SDag-Erling Smørgrav.Pp 5144ca1ab94SDag-Erling SmørgravThis manual page was written by 5154ca1ab94SDag-Erling Smørgrav.An Dag-Erling Co�dan Sm�rgrav Aq des@FreeBSD.org 5164ca1ab94SDag-Erling Smørgrav.Sh BUGS 517c6ff3a1bSSheldon HearnSome parts of the library are not yet implemented. 518c6ff3a1bSSheldon HearnThe most notable 519d8acd8dcSDag-Erling Smørgravexamples of this are 520d8acd8dcSDag-Erling Smørgrav.Fn fetchPutHTTP , 521ce71b736SDag-Erling Smørgrav.Fn fetchListHTTP , 52215efcd39SAlexey Zelkin.Fn fetchListFTP 523d8acd8dcSDag-Erling Smørgravand FTP proxy support. 524d8acd8dcSDag-Erling Smørgrav.Pp 525db5f8cebSDag-Erling SmørgravThere's no way to select a proxy at run-time other than setting the 526db5f8cebSDag-Erling Smørgrav.Ev HTTP_PROXY 527db5f8cebSDag-Erling Smørgravor 528db5f8cebSDag-Erling Smørgrav.Ev FTP_PROXY 529c6ff3a1bSSheldon Hearnenvironment variables as appropriate. 53098f5573fSDag-Erling Smørgrav.Pp 531842a95ccSDag-Erling Smørgrav.Nm libfetch 532842a95ccSDag-Erling Smørgravdoes not attempt to interpret and respond to authentication requests 533bc2a5e68SDag-Erling Smørgravfrom the HTTP server or proxy (code 401 and 407 respectively). 534842a95ccSDag-Erling Smørgrav.Pp 53598f5573fSDag-Erling Smørgrav.Nm libfetch 53698f5573fSDag-Erling Smørgravdoes not understand or obey 305 (Use Proxy) replies. 53798f5573fSDag-Erling Smørgrav.Pp 538c6ff3a1bSSheldon HearnNo attempt is made to encode spaces etc. within URLs. 539c6ff3a1bSSheldon HearnSpaces in the 540842a95ccSDag-Erling Smørgravdocument part of an URLshould be replaced with "%20" in HTTP URLs and 541842a95ccSDag-Erling Smørgrav"\\ " in FTP URLs. 542842a95ccSDag-Erling Smørgrav.Pp 543842a95ccSDag-Erling SmørgravError numbers are unique only within a certain context; the error 544842a95ccSDag-Erling Smørgravcodes used for FTP and HTTP overlap, as do those used for resolver and 545c6ff3a1bSSheldon Hearnsystem errors. 546c6ff3a1bSSheldon HearnFor instance, error code 202 means "Command not 547842a95ccSDag-Erling Smørgravimplemented, superfluous at this site" in an FTP context and 548842a95ccSDag-Erling Smørgrav"Accepted" in an HTTP context. 549842a95ccSDag-Erling Smørgrav.Pp 550f5f109a0SDag-Erling Smørgrav.Fn fetchStatFTP 551f5f109a0SDag-Erling Smørgravdoes not check that the result of an MDTM command is a valid date. 552f5f109a0SDag-Erling Smørgrav.Pp 553f5f109a0SDag-Erling SmørgravThe HTTP code needs a complete rewrite, or at least a serious cleanup. 554f5f109a0SDag-Erling Smørgrav.Pp 5551a5faa10SDag-Erling SmørgravThe man page is incomplete, poorly written and produces badly 5561a5faa10SDag-Erling Smørgravformatted text. 557db5f8cebSDag-Erling Smørgrav.Pp 558ba101983SDag-Erling SmørgravThe error reporting mechanism is unsatisfactory. 559ba101983SDag-Erling Smørgrav.Pp 560ba101983SDag-Erling SmørgravSome parts of the code are not fully reentrant. 561ba101983SDag-Erling Smørgrav.Pp 562db5f8cebSDag-Erling SmørgravTons of other stuff. 563