1 .\" Copyright (c) 1998 Dag-Erling Coïdan Smørgrav
2 .\" All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
13 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59 .Nd file transfer functions
63 .Fd #include <sys/param.h>
64 .Fd #include <stdio.h>
65 .Fd #include <fetch.h>
67 .Fn fetchMakeURL "char *scheme" "char *host" "int port" "char *doc" "char *user" "char *pwd"
69 .Fn fetchParseURL "char *URL"
71 .Fn fetchFreeURL "struct url *URL"
73 .Fn fetchXGetURL "char *URL" "struct url_stat *us" "char *flags"
75 .Fn fetchGetURL "char *URL" "char *flags"
77 .Fn fetchPutURL "char *URL" "char *flags"
79 .Fn fetchStatURL "char *URL" "struct url_stat *us" "char *flags"
81 .Fn fetchListURL "char *URL" "char *flags"
83 .Fn fetchXGet "struct url *URL" "struct url_stat *us" "char *flags"
85 .Fn fetchGet "struct url *URL" "char *flags"
87 .Fn fetchPut "struct url *URL" "char *flags"
89 .Fn fetchStat "struct url *URL" "struct url_stat *us" "char *flags"
91 .Fn fetchList "struct url *" "char *flags"
93 .Fn fetchXGetFile "struct url *u" "struct url_stat *us" "char *flags"
95 .Fn fetchGetFile "struct url *u" "char *flags"
97 .Fn fetchPutFile "struct url *u" "char *flags"
99 .Fn fetchStatFile "struct url *URL" "struct url_stat *us" "char *flags"
101 .Fn fetchListFile "struct url *" "char *flags"
103 .Fn fetchXGetHTTP "struct url *u" "struct url_stat *us" "char *flags"
105 .Fn fetchGetHTTP "struct url *u" "char *flags"
107 .Fn fetchPutHTTP "struct url *u" "char *flags"
109 .Fn fetchStatHTTP "struct url *URL" "struct url_stat *us" "char *flags"
111 .Fn fetchListHTTP "struct url *" "char *flags"
113 .Fn fetchXGetFTP "struct url *u" "struct url_stat *us" "char *flags"
115 .Fn fetchGetFTP "struct url *u" "char *flags"
117 .Fn fetchPutFTP "struct url *u" "char *flags"
119 .Fn fetchStatFTP "struct url *URL" "struct url_stat *us" "char *flags"
121 .Fn fetchListFTP "struct url *" "char *flags"
124 These functions implement a high-level library for retrieving and
125 uploading files using Uniform Resource Locators (URLs).
128 takes a URL in the form of a null-terminated string and splits it into
129 its components function according to the Common Internet Scheme Syntax
131 A regular expression which produces this syntax is:
133 <scheme>:(//(<user>(:<pwd>)?@)?<host>(:<port>)?)?/(<document>)?
136 If the URL does not seem to begin with a scheme name, the following
139 ((<user>(:<pwd>)?@)?<host>(:<port>)?)?/(<document>)?
142 Note that some components of the URL are not necessarily relevant to
144 For instance, the file scheme only needs the <scheme> and <document>
150 return a pointer to a
152 structure, which is defined as follows in
155 #define URL_SCHEMELEN 16
156 #define URL_USERLEN 256
157 #define URL_PWDLEN 256
160 char scheme[URL_SCHEMELEN+1];
161 char user[URL_USERLEN+1];
162 char pwd[URL_PWDLEN+1];
163 char host[MAXHOSTNAMELEN+1];
171 The pointer returned by
175 should be freed using
182 constitute the recommended interface to the
185 They examine the URL passed to them to determine the transfer
186 method, and call the appropriate lower-level functions to perform the
189 also returns the remote document's metadata in the
191 structure pointed to by the
197 argument is a string of characters which specify transfer options.
199 meaning of the individual flags is scheme-dependent, and is detailed
200 in the appropriate section below.
203 attempts to obtain the requested document's metadata and fill in the
204 structure pointed to by it's second argument.
207 structure is defined as follows in
217 If the size could not be obtained from the server, the
220 If the modification time could not be obtained from the server, the
222 field is set to the epoch.
223 If the access time could not be obtained from the server, the
225 field is set to the modification time.
228 attempts to list the contents of the directory pointed to by the URL
230 If successful, it returns a malloced array of
235 structure is defined as follows in
239 char name[MAXPATHLEN];
240 struct url_stat stat;
244 The list is terminated by an entry with an empty name.
246 The pointer returned by
248 should be freed using
262 except that they expect a pre-parsed URL in the form of a pointer to
265 rather than a string.
272 functions return a pointer to a stream which can be used to read or
273 write data from or to the requested document, respectively.
275 although the implementation details of the individual access methods
276 vary, it can generally be assumed that a stream returned by one of the
280 functions is read-only, and that a stream returned by one of the
282 functions is write-only.
288 provide access to documents which are files in a locally mounted file
290 Only the <document> component of the URL is used.
295 do not accept any flags.
300 (append to file) flag.
301 If that flag is specified, the data written to
302 the stream returned by
304 will be appended to the previous contents of the file, instead of
311 implement the FTP protocol as described in RFC959.
315 (passive) flag is specified, a passive (rather than active) connection
320 (high) flag is specified, data sockets will be allocated in the high
326 (direct) flag is specified,
331 will use a direct connection even if a proxy server is defined.
333 If no user name or password is given, the
335 library will attempt an anonymous login, with user name "ftp" and
343 functions implement the HTTP/1.1 protocol.
344 With a little luck, there's
345 even a chance that they comply with RFC2068.
349 (direct) flag is specified,
354 will use a direct connection even if a proxy server is defined.
356 Since there seems to be no good way of implementing the HTTP PUT
357 method in a manner consistent with the rest of the
361 is currently unimplemented.
364 returns a pointer to a
366 containing the individual components of the URL.
368 unable to allocate memory, or the URL is syntactically incorrect,
370 returns a NULL pointer.
374 functions return 0 on success and -1 on failure.
376 All other functions return a stream pointer which may be used to
377 access the requested document, or NULL if an error occurred.
379 The following error codes are defined in
382 .It Bq Er FETCH_ABORT
385 Authentication failed
388 .It Bq Er FETCH_EXISTS
393 Informational response
394 .It Bq Er FETCH_MEMORY
396 .It Bq Er FETCH_MOVED
398 .It Bq Er FETCH_NETWORK
402 .It Bq Er FETCH_PROTO
404 .It Bq Er FETCH_RESOLV
406 .It Bq Er FETCH_SERVER
410 .It Bq Er FETCH_TIMEOUT
412 .It Bq Er FETCH_UNAVAIL
413 File is not available
414 .It Bq Er FETCH_UNKNOWN
420 The accompanying error message includes a protocol-specific error code
421 and message, e.g. "File is not available (404 Not Found)"
423 .Bl -tag -width FTP_PASSIVE_MODE
424 .It Ev FTP_PASSIVE_MODE
425 The FTP code selects passive mode by default.
426 To force active mode FTP, set this variable to
429 Default FTP password if the remote server requests one and none was
432 URL of the proxy to use for FTP requests.
433 The document part is ignored.
434 FTP and HTTP proxies are supported; if no scheme is specified, FTP is
436 If the proxy is an FTP proxy,
440 as user name to the proxy, where
442 is the real user name, and
444 is the name of the FTP server.
446 If this variable is set to an empty string, no proxy will be used for
447 FTP requests, even if the
451 Specifies HTTP authorization parameters as a colon-separated list of
453 The first and second item are the authorization scheme and realm
454 respectively; further items are scheme-dependent.
455 Currently, only basic authorization is supported.
457 Basic authorization requires two parameters: the user name and
458 password, in that order.
460 This variable is only used if the server requires authorization and
461 no user name or password was specified in the URL.
463 URL of the proxy to use for HTTP requests.
464 The document part is ignored.
465 Only HTTP proxies are supported for HTTP requests.
466 If no port number is specified, the default is 3128.
468 Note that this proxy will also be used for FTP documents, unless the
471 .It Ev HTTP_PROXY_AUTH
472 Specifies authorization parameters for the HTTP proxy in the same
477 This variable is used if and only if connected to an HTTP proxy, and
478 is ignored if a user and/or a password were specified in the proxy
490 .%T Uniform Resource Locators (URL)
500 .%B Hypertext Transfer Protocol -- HTTP/1.1
507 .%B File Transfer Protocol
513 library first appeared in
519 library was mostly written by
520 .An Dag-Erling Co\(:idan Sm\(/orgrav Aq des@FreeBSD.org
521 with numerous suggestions from
522 .An Jordan K. Hubbard Aq jkh@FreeBSD.org ,
523 .An Eugene Skepner Aq eu@qub.com
527 It replaces the older
530 .An Poul-Henning Kamp Aq pkh@FreeBSD.org
532 .An Jordan K. Hubbard Aq jkh@FreeBSD.org .
534 This manual page was written by
535 .An Dag-Erling Co\(:idan Sm\(/orgrav Aq des@FreeBSD.org .
537 Some parts of the library are not yet implemented.
543 and FTP proxy support.
545 There's no way to select a proxy at run-time other than setting the
549 environment variables as appropriate.
552 does not understand or obey 305 (Use Proxy) replies.
554 Error numbers are unique only within a certain context; the error
555 codes used for FTP and HTTP overlap, as do those used for resolver and
557 For instance, error code 202 means "Command not
558 implemented, superfluous at this site" in an FTP context and
559 "Accepted" in an HTTP context.
562 does not check that the result of an MDTM command is a valid date.
564 The man page is incomplete, poorly written and produces badly
567 The error reporting mechanism is unsatisfactory.
569 Some parts of the code are not fully reentrant.