summaryrefslogtreecommitdiffstats
path: root/lib/libfetch/fetch.3
blob: 0ee591219a5b3552e8f6858bcfa16a1406b5cc38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
.\" Copyright (c) 1998 Dag-Erling Coïdan Smørgrav
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" $FreeBSD$
.\"
.Dd July 1, 1998
.Dt FETCH 3
.Os
.Sh NAME
.Nm fetchGetURL ,
.Nm fetchPutURL ,
.Nm fetchStatURL ,
.Nm fetchListURL ,
.Nm fetchParseURL ,
.Nm fetchGet ,
.Nm fetchPut ,
.Nm fetchStat ,
.Nm fetchList ,
.Nm fetchGetFile ,
.Nm fetchPutFile ,
.Nm fetchStatFile ,
.Nm fetchListFile ,
.Nm fetchGetHTTP ,
.Nm fetchPutHTTP ,
.Nm fetchStatHTTP ,
.Nm fetchListHTTP ,
.Nm fetchGetFTP ,
.Nm fetchPutFTP
.Nm fetchStatFTP
.Nm fetchListFTP ,
.Nd file transfer library
.Sh SYNOPSIS
.Fd #include <sys/param.h>
.Fd #include <stdio.h>
.Fd #include <fetch.h>
.Ft FILE *
.Fn fetchGetURL "char *URL" "char *flags"
.Ft FILE *
.Fn fetchPutURL "char *URL" "char *flags"
.Ft int
.Fn fetchStatURL "char *URL" "struct url_stat *us" "char *flags"
.Ft struct url_ent *
.Fn fetchListURL "char *URL" "char *flags"
.Ft struct url *
.Fn fetchParseURL "char *URL"
.Ft FILE *
.Fn fetchGet "struct url *URL" "char *flags"
.Ft FILE *
.Fn fetchPut "struct url *URL" "char *flags"
.Ft int
.Fn fetchStat "struct url *URL" "struct url_stat *us" "char *flags"
.Ft struct url_ent *
.Fn fetchList "struct url *" "char *flags"
.Ft FILE *
.Fn fetchGetFile "struct url *u" "char *flags"
.Ft FILE *
.Fn fetchPutFile "struct url *u" "char *flags"
.Ft int
.Fn fetchStatFile "struct url *URL" "struct url_stat *us" "char *flags"
.Ft struct url_ent *
.Fn fetchListFile "struct url *" "char *flags"
.Ft FILE *
.Fn fetchGetHTTP "struct url *u" "char *flags"
.Ft FILE *
.Fn fetchPutHTTP "struct url *u" "char *flags"
.Ft int
.Fn fetchStatHTTP "struct url *URL" "struct url_stat *us" "char *flags"
.Ft struct url_ent *
.Fn fetchListHTTP "struct url *" "char *flags"
.Ft FILE *
.Fn fetchGetFTP "struct url *u" "char *flags"
.Ft FILE *
.Fn fetchPutFTP "struct url *u" "char *flags"
.Ft int
.Fn fetchStatFTP "struct url *URL" "struct url_stat *us" "char *flags"
.Ft struct url_ent *
.Fn fetchListFTP "struct url *" "char *flags"
.Sh DESCRIPTION
.Pp
These functions implement a high-level library for retrieving and
uploading files using Uniform Resource Locators (URLs).
.Pp
.Fn fetchGetURL
and
.Fn fetchPutURL
constitute the recommended interface to the
.Nm fetch
library.
They examine the URL passed to them to determine the transfer
method, and call the appropriate lower-level functions to perform the
actual transfer.
The 
.Fa flags
argument is a string of characters which specify transfer options.
The
meaning of the individual flags is scheme-dependent, and is detailed
in the appropriate section below.
.Pp
.Fn fetchStatURL
attempts to obtain the requested document's metadata and fill in the
structure pointed to by it's second argument.
The
.Fa url_stat
structure is defined as follows in
.Aq Pa fetch.h :
.Bd -literal
struct url_stat {
    off_t	 size;
    time_t	 atime;
    time_t	 mtime;
};
.Ed
.Pp
.Fn fetchListURL
attempts to list the contents of the directory pointed to by the URL
provided.
If successful, it returns a malloced array of
.Fa url_ent
structures.
The
.Fa url_ent
structure is defined as follows in
.Aq Pa fetch.h :
.Bd -literal
struct url_ent {
    char         name[MAXPATHLEN];
    struct url_stat stat;
};
.Ed
.Pp
The list is terminated by an entry with an empty name.
.Pp
The pointer returned by
.Fn fetchListURL
should be freed using
.Fn free .
.Pp
.Fn fetchParseURL
takes a URL in the form of a null-terminated string and splits it into
its components function according to the Common Internet Scheme Syntax
detailed in RFC1738. A regular expression which produces this syntax
is:
.Bd -literal
    <scheme>:(//(<user>(:<pwd>)?@)?<host>(:<port>)?)?/(<document>)?
.Ed
.Pp
Note that some components of the URL are not necessarily relevant to
all URL schemes.
For instance, the file scheme only needs the <scheme>
and <document> components.
.Pp
The pointer returned by
.Fn fetchParseURL
should be freed using
.Fn free .
.Pp
.Fn fetchGet ,
.Fn fetchPut
and
.Fn fetchStat
are similar to
.Fn fetchGetURL ,
.Fn fetchPutURL
and
.Fn fetchStatURL ,
except that they expect a pre-parsed URL in the form of a pointer to
a
.Fa struct url
rather than a string.
.Pp
All of the
.Fn fetchGetXXX
and
.Fn fetchPutXXX
functions return a pointer to a stream which can be used to read or
write data from or to the requested document, respectively.
Note that
although the implementation details of the individual access methods
vary, it can generally be assumed that a stream returned by one of the
.Fn fetchGetXXX
functions is read-only, and that a stream returned by one of the
.Fn fetchPutXXX
functions is write-only.
.Sh FILE SCHEME
.Fn fetchGetFile
and
.Fn fetchPutFile
provide access to documents which are files in a locally mounted file
system.
Only the <document> component of the URL is used.
.Pp
.Fn fetchGetFile
does not accept any flags.
.Pp
.Fn fetchPutFile
accepts the
.Fa a
(append to file) flag.
If that flag is specified, the data written to
the stream returned by
.Fn fetchPutFile
will be appended to the previous contents of the file, instead of
replacing them.
.Sh FTP SCHEME
.Fn fetchGetFTP
and
.Fn fetchPutFTP
implement the FTP protocol as described in RFC959.
.Pp
If the
.Fa p
(passive) flag is specified, a passive (rather than active) connection
will be attempted.
.Pp
If the
.Fa h
(high) flag is specified, data sockets will be allocated in the high
port range (see
.Xr ip 4 ).
.Pp
If the
.Fa d
(direct) flag is specified,
.Fn fetchGetFTP
and
.Fn fetchPutFTP
will use a direct connection even if a proxy server is defined.
.Pp
If no user name or password is given, the
.Nm fetch
library will attempt an anonymous login, with user name "ftp" and
password "ftp".
.Sh HTTP SCHEME
The
.Fn fetchGetHTTP
and
.Fn fetchPutHTTP
functions implement the HTTP/1.1 protocol.
With a little luck, there's
even a chance that they comply with RFC2068.
.Pp
If the
.Fa d
(direct) flag is specified,
.Fn fetchGetHTTP
and
.Fn fetchPutHTTP
will use a direct connection even if a proxy server is defined.
.Pp
Since there seems to be no good way of implementing the HTTP PUT
method in a manner consistent with the rest of the
.Nm fetch
library,
.Fn fetchPutHTTP
is currently unimplemented.
.Sh RETURN VALUES
.Fn fetchParseURL
returns a pointer to a
.Fa struct url
containing the individual components of the URL.
If it is
unable to allocate memory, or the URL is syntactically incorrect,
.Fn fetchParseURL
returns a NULL pointer.
.Pp
The 
.Fn fetchStat
functions return 0 on success and -1 on failure.
.Pp
All other functions return a stream pointer which may be used to
access the requested document, or NULL if an error occurred.
.Pp
.Nm Libfetch
uses the Common Error Library
.Nm ( libcom_err )
to report errors.
The error code passed to
.Fn com_err
is one of:
.Bl -tag -width Er
.It Bq Er FETCH_ABORT
Operation aborted    
.It Bq Er FETCH_AUTH
Authentication failed    
.It Bq Er FETCH_DOWN
Service unavailable    
.It Bq Er FETCH_EXISTS
File exists    
.It Bq Er FETCH_FULL
File system full   
.It Bq Er FETCH_INFO
Informational response    
.It Bq Er FETCH_MEMORY
Insufficient memory    
.It Bq Er FETCH_MOVED
File has moved   
.It Bq Er FETCH_NETWORK
Network error    
.It Bq Er FETCH_OK
No error    
.It Bq Er FETCH_PROTO
Protocol error    
.It Bq Er FETCH_RESOLV
Resolver error    
.It Bq Er FETCH_SERVER
Server error    
.It Bq Er FETCH_TEMP
Temporary error    
.It Bq Er FETCH_TIMEOUT
Operation timed out   
.It Bq Er FETCH_UNAVAIL
File is not available  
.It Bq Er FETCH_UNKNOWN
Unknown error    
.It Bq Er FETCH_URL
Invalid URL
.El
.Pp
The accompanying error message includes a protocol-specific error code
and message, e.g. "File is not available (404 Not Found)"
.Sh ENVIRONMENT
The FTP and HTTP related functions use the
.Ev HTTP_PROXY
and
.Ev FTP_PROXY
environment variables, respectively, as the address of a proxy server
to use for transferring files.
.Sh SEE ALSO
.Xr com_err 3 ,
.Xr fetch 1 ,
.Xr ftpio 3 ,
.Xr ip 4 .
.Rs
.%A T. Berners-Lee, L. Masinter & M. McCahill
.%D December 1994
.%T Uniform Resource Locators (URL)
.%O RFC1738
.Re
.Rs
.%A R. Fielding, J. Gettys, J. Mogul, H. Frystyk, T. Berners-Lee
.%D Januray 1997
.%B Hypertext Transfer Protocol -- HTTP/1.1
.%O RFC2068
.Re
.Rs
.%A J. Postel, J. K. Reynolds
.%D October 1985
.%B File Transfer Protocol
.%O RFC959
.Re
.Sh NOTES
The
.Nm fetch
library uses the Common Error library, and applications which link
with
.Nm libfetch
must therefore also link with
.Nm libcom_err .
.Sh HISTORY
The
.Nm fetch
library first appeared in
.Fx 3.0 .
.Sh AUTHORS
The
.Nm fetch
library was mostly written by
.An Dag-Erling Coïdan Smørgrav Aq des@FreeBSD.org
with numerous suggestions from
.An Jordan K. Hubbard Aq jkh@FreeBSD.org ,
.An Eugene Skepner Aq eu@qub.com
and other FreeBSD developers.
It replaces the older
.Nm ftpio
library written by
.An Poul-Henning Kamp Aq pkh@FreeBSD.org
and
.An Jordan K. Hubbard Aq jkh@FreeBSD.org .
.Pp
This manual page was written by
.An Dag-Erling Coïdan Smørgrav Aq des@FreeBSD.org
.Sh BUGS
Some parts of the library are not yet implemented.
The most notable
examples of this are
.Fn fetchPutHTTP ,
.Fn fetchStatHTTP ,
.Fn fetchListHTTP ,
.Fn fetchListFTP ,
and FTP proxy support.
.Pp
There's no way to select a proxy at run-time other than setting the
.Ev HTTP_PROXY
or
.Ev FTP_PROXY
environment variables as appropriate.
There is also no way to stop the
FTP and HTTP functions from trying to use a proxy if these variables
are set.
.Pp
HTTP authentication doesn't work.
I'm not sure that's a bug in my
code; as far as I can determine,
.Nm libfetch
handles HTTP/1.1 basic authentication correctly as outlined in
RFC2068, but I haven't been able to find an HTTP server that honors
the Authentication: header field.
Also,
.Nm libfetch
does not attempt to interpret and respond to authentication requests
from the HTTP server.
.Pp
No attempt is made to encode spaces etc. within URLs.
Spaces in the
document part of an URLshould be replaced with "%20" in HTTP URLs and
"\\ " in FTP URLs.
.Pp
Error numbers are unique only within a certain context; the error
codes used for FTP and HTTP overlap, as do those used for resolver and
system errors.
For instance, error code 202 means "Command not
implemented, superfluous at this site" in an FTP context and
"Accepted" in an HTTP context.
.Pp
.Fn fetchStatFTP
does not check that the result of an MDTM command is a valid date.
.Pp
The HTTP code needs a complete rewrite, or at least a serious cleanup.
.Pp
The man page is poorly written and produces badly formatted text.
.Pp
Tons of other stuff.
OpenPOWER on IntegriCloud