]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libfetch/fetch.3
This commit was generated by cvs2svn to compensate for changes in r75107,
[FreeBSD/FreeBSD.git] / lib / libfetch / fetch.3
1 .\" Copyright (c) 1998 Dag-Erling Coïdan Smørgrav
2 .\" All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
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.
12 .\"
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
23 .\" SUCH DAMAGE.
24 .\"
25 .\" $FreeBSD$
26 .\"
27 .Dd July 1, 1998
28 .Dt FETCH 3
29 .Os
30 .Sh NAME
31 .Nm fetchMakeURL ,
32 .Nm fetchParseURL ,
33 .Nm fetchFreeURL ,
34 .Nm fetchXGetURL ,
35 .Nm fetchGetURL ,
36 .Nm fetchPutURL ,
37 .Nm fetchStatURL ,
38 .Nm fetchListURL ,
39 .Nm fetchXGet ,
40 .Nm fetchGet ,
41 .Nm fetchPut ,
42 .Nm fetchStat ,
43 .Nm fetchList ,
44 .Nm fetchXGetFile ,
45 .Nm fetchGetFile ,
46 .Nm fetchPutFile ,
47 .Nm fetchStatFile ,
48 .Nm fetchListFile ,
49 .Nm fetchXGetHTTP ,
50 .Nm fetchGetHTTP ,
51 .Nm fetchPutHTTP ,
52 .Nm fetchStatHTTP ,
53 .Nm fetchListHTTP ,
54 .Nm fetchXGetFTP ,
55 .Nm fetchGetFTP ,
56 .Nm fetchPutFTP ,
57 .Nm fetchStatFTP ,
58 .Nm fetchListFTP
59 .Nd file transfer functions
60 .Sh LIBRARY
61 .Lb libfetch
62 .Sh SYNOPSIS
63 .Fd #include <sys/param.h>
64 .Fd #include <stdio.h>
65 .Fd #include <fetch.h>
66 .Ft struct url *
67 .Fn fetchMakeURL "char *scheme" "char *host" "int port" "char *doc" "char *user" "char *pwd"
68 .Ft struct url *
69 .Fn fetchParseURL "char *URL"
70 .Ft void
71 .Fn fetchFreeURL "struct url *URL"
72 .Ft FILE *
73 .Fn fetchXGetURL "char *URL" "struct url_stat *us" "char *flags"
74 .Ft FILE *
75 .Fn fetchGetURL "char *URL" "char *flags"
76 .Ft FILE *
77 .Fn fetchPutURL "char *URL" "char *flags"
78 .Ft int
79 .Fn fetchStatURL "char *URL" "struct url_stat *us" "char *flags"
80 .Ft struct url_ent *
81 .Fn fetchListURL "char *URL" "char *flags"
82 .Ft FILE *
83 .Fn fetchXGet "struct url *URL" "struct url_stat *us" "char *flags"
84 .Ft FILE *
85 .Fn fetchGet "struct url *URL" "char *flags"
86 .Ft FILE *
87 .Fn fetchPut "struct url *URL" "char *flags"
88 .Ft int
89 .Fn fetchStat "struct url *URL" "struct url_stat *us" "char *flags"
90 .Ft struct url_ent *
91 .Fn fetchList "struct url *" "char *flags"
92 .Ft FILE *
93 .Fn fetchXGetFile "struct url *u" "struct url_stat *us" "char *flags"
94 .Ft FILE *
95 .Fn fetchGetFile "struct url *u" "char *flags"
96 .Ft FILE *
97 .Fn fetchPutFile "struct url *u" "char *flags"
98 .Ft int
99 .Fn fetchStatFile "struct url *URL" "struct url_stat *us" "char *flags"
100 .Ft struct url_ent *
101 .Fn fetchListFile "struct url *" "char *flags"
102 .Ft FILE *
103 .Fn fetchXGetHTTP "struct url *u" "struct url_stat *us" "char *flags"
104 .Ft FILE *
105 .Fn fetchGetHTTP "struct url *u" "char *flags"
106 .Ft FILE *
107 .Fn fetchPutHTTP "struct url *u" "char *flags"
108 .Ft int
109 .Fn fetchStatHTTP "struct url *URL" "struct url_stat *us" "char *flags"
110 .Ft struct url_ent *
111 .Fn fetchListHTTP "struct url *" "char *flags"
112 .Ft FILE *
113 .Fn fetchXGetFTP "struct url *u" "struct url_stat *us" "char *flags"
114 .Ft FILE *
115 .Fn fetchGetFTP "struct url *u" "char *flags"
116 .Ft FILE *
117 .Fn fetchPutFTP "struct url *u" "char *flags"
118 .Ft int
119 .Fn fetchStatFTP "struct url *URL" "struct url_stat *us" "char *flags"
120 .Ft struct url_ent *
121 .Fn fetchListFTP "struct url *" "char *flags"
122 .Sh DESCRIPTION
123 .Pp
124 These functions implement a high-level library for retrieving and
125 uploading files using Uniform Resource Locators (URLs).
126 .Pp
127 .Fn fetchParseURL
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
130 detailed in RFC1738.
131 A regular expression which produces this syntax is:
132 .Bd -literal
133     <scheme>:(//(<user>(:<pwd>)?@)?<host>(:<port>)?)?/(<document>)?
134 .Ed
135 .Pp
136 If the URL does not seem to begin with a scheme name, the following
137 syntax is assumed:
138 .Bd -literal
139     ((<user>(:<pwd>)?@)?<host>(:<port>)?)?/(<document>)?
140 .Ed
141 .Pp
142 Note that some components of the URL are not necessarily relevant to
143 all URL schemes.
144 For instance, the file scheme only needs the <scheme> and <document>
145 components.
146 .Pp
147 .Fn fetchMakeURL
148 and
149 .Fn fetchParseURL
150 return a pointer to a
151 .Fa url
152 structure, which is defined as follows in
153 .Aq Pa fetch.h :
154 .Bd -literal
155 #define URL_SCHEMELEN 16
156 #define URL_USERLEN 256
157 #define URL_PWDLEN 256
158
159 struct url {
160     char         scheme[URL_SCHEMELEN+1];
161     char         user[URL_USERLEN+1];
162     char         pwd[URL_PWDLEN+1];
163     char         host[MAXHOSTNAMELEN+1];
164     int          port;
165     char        *doc;
166     off_t        offset;
167     size_t       length;
168 };
169 .Ed
170 .Pp
171 The pointer returned by
172 .Fn fetchMakeURL
173 or
174 .Fn fetchParseURL
175 should be freed using
176 .Fn fetchFreeURL .
177 .Pp
178 .Fn fetchXGetURL ,
179 .Fn fetchGetURL ,
180 and
181 .Fn fetchPutURL
182 constitute the recommended interface to the
183 .Nm fetch
184 library.
185 They examine the URL passed to them to determine the transfer
186 method, and call the appropriate lower-level functions to perform the
187 actual transfer.
188 .Fn fetchXGetURL
189 also returns the remote document's metadata in the
190 .Fa url_stat
191 structure pointed to by the
192 .Fa us
193 argument.
194 .Pp
195 The 
196 .Fa flags
197 argument is a string of characters which specify transfer options.
198 The
199 meaning of the individual flags is scheme-dependent, and is detailed
200 in the appropriate section below.
201 .Pp
202 .Fn fetchStatURL
203 attempts to obtain the requested document's metadata and fill in the
204 structure pointed to by it's second argument.
205 The
206 .Fa url_stat
207 structure is defined as follows in
208 .Aq Pa fetch.h :
209 .Bd -literal
210 struct url_stat {
211     off_t        size;
212     time_t       atime;
213     time_t       mtime;
214 };
215 .Ed
216 .Pp
217 If the size could not be obtained from the server, the
218 .Fa size
219 field is set to -1.
220 If the modification time could not be obtained from the server, the
221 .Fa mtime
222 field is set to the epoch.
223 If the access time could not be obtained from the server, the
224 .Fa atime
225 field is set to the modification time.
226 .Pp
227 .Fn fetchListURL
228 attempts to list the contents of the directory pointed to by the URL
229 provided.
230 If successful, it returns a malloced array of
231 .Fa url_ent
232 structures.
233 The
234 .Fa url_ent
235 structure is defined as follows in
236 .Aq Pa fetch.h :
237 .Bd -literal
238 struct url_ent {
239     char         name[MAXPATHLEN];
240     struct url_stat stat;
241 };
242 .Ed
243 .Pp
244 The list is terminated by an entry with an empty name.
245 .Pp
246 The pointer returned by
247 .Fn fetchListURL
248 should be freed using
249 .Fn free .
250 .Pp
251 .Fn fetchXGet ,
252 .Fn fetchGet ,
253 .Fn fetchPut
254 and
255 .Fn fetchStat
256 are similar to
257 .Fn fetchXGetURL ,
258 .Fn fetchGetURL ,
259 .Fn fetchPutURL
260 and
261 .Fn fetchStatURL ,
262 except that they expect a pre-parsed URL in the form of a pointer to
263 a
264 .Fa struct url
265 rather than a string.
266 .Pp
267 All of the
268 .Fn fetchXGetXXX ,
269 .Fn fetchGetXXX
270 and
271 .Fn fetchPutXXX
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.
274 Note that
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
277 .Fn fetchXGetXXX
278 or
279 .Fn fetchGetXXX
280 functions is read-only, and that a stream returned by one of the
281 .Fn fetchPutXXX
282 functions is write-only.
283 .Sh FILE SCHEME
284 .Fn fetchXGetFile ,
285 .Fn fetchGetFile
286 and
287 .Fn fetchPutFile
288 provide access to documents which are files in a locally mounted file
289 system.
290 Only the <document> component of the URL is used.
291 .Pp
292 .Fn fetchXGetFile
293 and
294 .Fn fetchGetFile
295 do not accept any flags.
296 .Pp
297 .Fn fetchPutFile
298 accepts the
299 .Fa a
300 (append to file) flag.
301 If that flag is specified, the data written to
302 the stream returned by
303 .Fn fetchPutFile
304 will be appended to the previous contents of the file, instead of
305 replacing them.
306 .Sh FTP SCHEME
307 .Fn fetchXGetFTP ,
308 .Fn fetchGetFTP
309 and
310 .Fn fetchPutFTP
311 implement the FTP protocol as described in RFC959.
312 .Pp
313 If the
314 .Fa p
315 (passive) flag is specified, a passive (rather than active) connection
316 will be attempted.
317 .Pp
318 If the
319 .Fa l
320 (low) flag is specified, data sockets will be allocated in the low (or
321 default) port range instead of the hifh port range (see
322 .Xr ip 4 ) .
323 .Pp
324 If the
325 .Fa d
326 (direct) flag is specified,
327 .Fn fetchXGetFTP ,
328 .Fn fetchGetFTP
329 and
330 .Fn fetchPutFTP
331 will use a direct connection even if a proxy server is defined.
332 .Pp
333 If no user name or password is given, the
334 .Nm fetch
335 library will attempt an anonymous login, with user name "anonymous"
336 and password "anonymous@<hostname>".
337 .Sh HTTP SCHEME
338 The
339 .Fn fetchXGetHTTP ,
340 .Fn fetchGetHTTP
341 and
342 .Fn fetchPutHTTP
343 functions implement the HTTP/1.1 protocol.
344 With a little luck, there's
345 even a chance that they comply with RFC2068.
346 .Pp
347 If the
348 .Fa d
349 (direct) flag is specified,
350 .Fn fetchXGetHTTP ,
351 .Fn fetchGetHTTP
352 and
353 .Fn fetchPutHTTP
354 will use a direct connection even if a proxy server is defined.
355 .Pp
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
358 .Nm fetch
359 library,
360 .Fn fetchPutHTTP
361 is currently unimplemented.
362 .Sh RETURN VALUES
363 .Fn fetchParseURL
364 returns a pointer to a
365 .Fa struct url
366 containing the individual components of the URL.
367 If it is
368 unable to allocate memory, or the URL is syntactically incorrect,
369 .Fn fetchParseURL
370 returns a NULL pointer.
371 .Pp
372 The 
373 .Fn fetchStat
374 functions return 0 on success and -1 on failure.
375 .Pp
376 All other functions return a stream pointer which may be used to
377 access the requested document, or NULL if an error occurred.
378 .Pp
379 The following error codes are defined in
380 .Aq Pa fetch.h :
381 .Bl -tag -width 18n
382 .It Bq Er FETCH_ABORT
383 Operation aborted    
384 .It Bq Er FETCH_AUTH
385 Authentication failed    
386 .It Bq Er FETCH_DOWN
387 Service unavailable    
388 .It Bq Er FETCH_EXISTS
389 File exists    
390 .It Bq Er FETCH_FULL
391 File system full   
392 .It Bq Er FETCH_INFO
393 Informational response    
394 .It Bq Er FETCH_MEMORY
395 Insufficient memory    
396 .It Bq Er FETCH_MOVED
397 File has moved   
398 .It Bq Er FETCH_NETWORK
399 Network error    
400 .It Bq Er FETCH_OK
401 No error    
402 .It Bq Er FETCH_PROTO
403 Protocol error    
404 .It Bq Er FETCH_RESOLV
405 Resolver error    
406 .It Bq Er FETCH_SERVER
407 Server error    
408 .It Bq Er FETCH_TEMP
409 Temporary error    
410 .It Bq Er FETCH_TIMEOUT
411 Operation timed out   
412 .It Bq Er FETCH_UNAVAIL
413 File is not available  
414 .It Bq Er FETCH_UNKNOWN
415 Unknown error    
416 .It Bq Er FETCH_URL
417 Invalid URL
418 .El
419 .Pp
420 The accompanying error message includes a protocol-specific error code
421 and message, e.g. "File is not available (404 Not Found)"
422 .Sh ENVIRONMENT
423 .Bl -tag -width FTP_PASSIVE_MODE
424 .It Ev FTP_LOGIN
425 Default FTP login if none was provided in the URL.
426 .It Ev FTP_PASSIVE_MODE
427 If set to anything but
428 .Ql no ,
429 forces the FTP code to use passive mode.
430 .It Ev FTP_PASSWORD
431 Default FTP password if the remote server requests one and none was
432 provided in the URL.
433 .It Ev FTP_PROXY
434 URL of the proxy to use for FTP requests.
435 The document part is ignored.
436 FTP and HTTP proxies are supported; if no scheme is specified, FTP is
437 assumed.
438 If the proxy is an FTP proxy,
439 .Nm libfetch
440 will send
441 .Ql user@host
442 as user name to the proxy, where
443 .Ql user
444 is the real user name, and
445 .Ql host
446 is the name of the FTP server.
447 .Pp
448 If this variable is set to an empty string, no proxy will be used for
449 FTP requests, even if the
450 .Ev HTTP_PROXY
451 variable is set.
452 .It Ev ftp_proxy
453 Same as
454 .Ev FTP_PROXY ,
455 for compatibility.
456 .It Ev HTTP_AUTH
457 Specifies HTTP authorization parameters as a colon-separated list of
458 items.
459 The first and second item are the authorization scheme and realm
460 respectively; further items are scheme-dependent.
461 Currently, only basic authorization is supported.
462 .Pp
463 Basic authorization requires two parameters: the user name and
464 password, in that order.
465 .Pp
466 This variable is only used if the server requires authorization and
467 no user name or password was specified in the URL.
468 .It Ev HTTP_PROXY
469 URL of the proxy to use for HTTP requests.
470 The document part is ignored.
471 Only HTTP proxies are supported for HTTP requests.
472 If no port number is specified, the default is 3128.
473 .Pp
474 Note that this proxy will also be used for FTP documents, unless the
475 .Ev FTP_PROXY
476 variable is set.
477 .It Ev http_proxy
478 Same as
479 .Ev HTTP_PROXY ,
480 for compatibility.
481 .It Ev HTTP_PROXY_AUTH
482 Specifies authorization parameters for the HTTP proxy in the same
483 format as the
484 .Ev HTTP_AUTH
485 variable.
486 .Pp
487 This variable is used if and only if connected to an HTTP proxy, and
488 is ignored if a user and/or a password were specified in the proxy
489 URL.
490 .El
491 .Sh SEE ALSO
492 .Xr fetch 1 ,
493 .Xr ftpio 3 ,
494 .Xr ip 4
495 .Rs
496 .%A J. Postel
497 .%A J. K. Reynolds
498 .%D October 1985
499 .%B File Transfer Protocol
500 .%O RFC959
501 .Re
502 .Rs
503 .%A P. Deutsch
504 .%A A. Emtage
505 .%A A. Marine.
506 .%D May 1994
507 .%T How to Use Anonymous FTP
508 .%O RFC1635
509 .Re
510 .Rs
511 .%A T. Berners-Lee
512 .%A L. Masinter
513 .%A M. McCahill
514 .%D December 1994
515 .%T Uniform Resource Locators (URL)
516 .%O RFC1738
517 .Re
518 .Rs
519 .%A R. Fielding
520 .%A J. Gettys
521 .%A J. Mogul
522 .%A H. Frystyk
523 .%A T. Berners-Lee
524 .%D Januray 1997
525 .%B Hypertext Transfer Protocol -- HTTP/1.1
526 .%O RFC2068
527 .Re
528 .Sh HISTORY
529 The
530 .Nm fetch
531 library first appeared in
532 .Fx 3.0 .
533 .Sh AUTHORS
534 .An -nosplit
535 The
536 .Nm fetch
537 library was mostly written by
538 .An Dag-Erling Co\(:idan Sm\(/orgrav Aq des@FreeBSD.org
539 with numerous suggestions from
540 .An Jordan K. Hubbard Aq jkh@FreeBSD.org ,
541 .An Eugene Skepner Aq eu@qub.com
542 and other
543 .Fx
544 developers.
545 It replaces the older
546 .Nm ftpio
547 library written by
548 .An Poul-Henning Kamp Aq pkh@FreeBSD.org
549 and
550 .An Jordan K. Hubbard Aq jkh@FreeBSD.org .
551 .Pp
552 This manual page was written by
553 .An Dag-Erling Co\(:idan Sm\(/orgrav Aq des@FreeBSD.org .
554 .Sh BUGS
555 Some parts of the library are not yet implemented.
556 The most notable
557 examples of this are
558 .Fn fetchPutHTTP ,
559 .Fn fetchListHTTP ,
560 .Fn fetchListFTP
561 and FTP proxy support.
562 .Pp
563 There's no way to select a proxy at run-time other than setting the
564 .Ev HTTP_PROXY
565 or
566 .Ev FTP_PROXY
567 environment variables as appropriate.
568 .Pp
569 .Nm libfetch
570 does not understand or obey 305 (Use Proxy) replies.
571 .Pp
572 Error numbers are unique only within a certain context; the error
573 codes used for FTP and HTTP overlap, as do those used for resolver and
574 system errors.
575 For instance, error code 202 means "Command not
576 implemented, superfluous at this site" in an FTP context and
577 "Accepted" in an HTTP context.
578 .Pp
579 .Fn fetchStatFTP
580 does not check that the result of an MDTM command is a valid date.
581 .Pp
582 The man page is incomplete, poorly written and produces badly
583 formatted text.
584 .Pp
585 The error reporting mechanism is unsatisfactory.
586 .Pp
587 Some parts of the code are not fully reentrant.