Import libfetch-2.19 from pkgsrc:

- fix bug in URL quoting
- man page improvements
- remove passive mode flag, add flag to force active mode and fallback
from passive to active on syntax errors automatically
This commit is contained in:
joerg 2008-10-29 16:18:13 +00:00
parent 16d084a837
commit d45537460f
4 changed files with 52 additions and 36 deletions

View File

@ -24,7 +24,7 @@
.\" SUCH DAMAGE. .\" SUCH DAMAGE.
.\" .\"
.\" $FreeBSD: fetch.3,v 1.64 2007/12/18 11:03:26 des Exp $ .\" $FreeBSD: fetch.3,v 1.64 2007/12/18 11:03:26 des Exp $
.\" $NetBSD: fetch.3,v 1.1.1.2 2008/10/07 15:55:20 joerg Exp $ .\" $NetBSD: fetch.3,v 1.1.1.3 2008/10/29 16:18:13 joerg Exp $
.\" .\"
.Dd April 25, 2008 .Dd April 25, 2008
.Dt FETCH 3 .Dt FETCH 3
@ -358,10 +358,14 @@ and
.Fn fetchPutFTP .Fn fetchPutFTP
implement the FTP protocol as described in RFC 959. implement the FTP protocol as described in RFC 959.
.Pp .Pp
By default
.Nm libfetch
will attempt to use passive mode first and only fallback to active mode
if the server reports a syntax error.
If the If the
.Ql p .Ql a
(passive) flag is specified, a passive (rather than active) connection (active) flag is specified, a passive connection is not tried and active mode
will be attempted. is used directly.
.Pp .Pp
If the If the
.Ql l .Ql l

View File

@ -1,4 +1,4 @@
/* $NetBSD: fetch.c,v 1.1.1.2 2008/10/07 15:55:20 joerg Exp $ */ /* $NetBSD: fetch.c,v 1.1.1.3 2008/10/29 16:18:13 joerg Exp $ */
/*- /*-
* Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav * Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
* Copyright (c) 2008 Joerg Sonnenberger <joerg@NetBSD.org> * Copyright (c) 2008 Joerg Sonnenberger <joerg@NetBSD.org>
@ -510,7 +510,7 @@ quote_doc:
u->doc[i++] = '0' + ((unsigned char)*p) / 16; u->doc[i++] = '0' + ((unsigned char)*p) / 16;
else else
u->doc[i++] = 'a' - 10 + ((unsigned char)*p) / 16; u->doc[i++] = 'a' - 10 + ((unsigned char)*p) / 16;
if ((unsigned char)*p % 16 < 16) if ((unsigned char)*p % 16 < 10)
u->doc[i++] = '0' + ((unsigned char)*p) % 16; u->doc[i++] = '0' + ((unsigned char)*p) % 16;
else else
u->doc[i++] = 'a' - 10 + ((unsigned char)*p) % 16; u->doc[i++] = 'a' - 10 + ((unsigned char)*p) % 16;

View File

@ -126,7 +126,7 @@ DDEESSCCRRIIPPTTIIOONN
ffeettcchhPPaarrsseeUURRLL() takes a URL in the form of a null-terminated string and ffeettcchhPPaarrsseeUURRLL() takes a URL in the form of a null-terminated string and
splits it into its components function according to the Common Internet splits it into its components function according to the Common Internet
Scheme Syntax detailed in RFC1738. A regular expression which produces Scheme Syntax detailed in RFC 1738. A regular expression which produces
this syntax is: this syntax is:
<scheme>:(//(<user>(:<pwd>)?@)?<host>(:<port>)?)?/(<document>)? <scheme>:(//(<user>(:<pwd>)?@)?<host>(:<port>)?)?/(<document>)?
@ -140,7 +140,7 @@ DDEESSCCRRIIPPTTIIOONN
the URL automatically. This is not done by ffeettcchhMMaakkeeUURRLL(). the URL automatically. This is not done by ffeettcchhMMaakkeeUURRLL().
ffeettcchhCCooppyyUURRLL() copies an existing _u_r_l structure. ffeettcchhCCooppyyUURRLL() copies an existing _u_r_l structure.
ffeettcchhMMaakkeeUURRLL(), ffeettcchhPPaarrsseeUURRLL() and ffeettcchhCCooppyyUURRLL() return a pointer to a ffeettcchhMMaakkeeUURRLL(), ffeettcchhPPaarrsseeUURRLL(), and ffeettcchhCCooppyyUURRLL() return a pointer to a
_u_r_l structure, which is defined as follows in <_f_e_t_c_h_._h>: _u_r_l structure, which is defined as follows in <_f_e_t_c_h_._h>:
#define URL_SCHEMELEN 16 #define URL_SCHEMELEN 16
@ -159,7 +159,7 @@ DDEESSCCRRIIPPTTIIOONN
size_t length; size_t length;
}; };
The pointer returned by ffeettcchhMMaakkeeUURRLL(), ffeettcchhCCooppyyUURRLL() and The pointer returned by ffeettcchhMMaakkeeUURRLL(), ffeettcchhCCooppyyUURRLL(), and
ffeettcchhPPaarrsseeUURRLL() should be freed using ffeettcchhFFrreeeeUURRLL(). ffeettcchhPPaarrsseeUURRLL() should be freed using ffeettcchhFFrreeeeUURRLL().
ffeettcchhXXGGeettUURRLL(), ffeettcchhGGeettUURRLL(), and ffeettcchhPPuuttUURRLL() constitute the recom- ffeettcchhXXGGeettUURRLL(), ffeettcchhGGeettUURRLL(), and ffeettcchhPPuuttUURRLL() constitute the recom-
@ -201,23 +201,23 @@ DDEESSCCRRIIPPTTIIOONN
struct url *urls; struct url *urls;
}; };
The list should be initialised by calling ffeettcchhIInniittUURRLLLLiisstt() and the The list should be initialized by calling ffeettcchhIInniittUURRLLLLiisstt() and the
entries be freed by calling ffeettcchhFFrreeeeUURRLLLLiisstt(). entries be freed by calling ffeettcchhFFrreeeeUURRLLLLiisstt().
ffeettcchhSSttrriinnggiiffyyUURRLL() returns the URL as string. ffeettcchhUUnnqquuootteePPaatthh() ffeettcchhSSttrriinnggiiffyyUURRLL() returns the URL as string. ffeettcchhUUnnqquuootteePPaatthh()
returns the path name part of the URL with any quoting undone. Query returns the path name part of the URL with any quoting undone. Query
arguments and fragment identifiers are not included. arguments and fragment identifiers are not included.
ffeettcchhUUnnqquuootteeFFiilleennaammee() returns the last component of the path name as ffeettcchhUUnnqquuootteeFFiilleennaammee() returns the last component of the path name as
returned by ffeettcchhUUnnqquuootteePPaatthh(). ffeettcchhSSttrriinnggiiffyyUURRLL(), ffeettcchhUUnnqquuootteePPaatthh() returned by ffeettcchhUUnnqquuootteePPaatthh(). ffeettcchhSSttrriinnggiiffyyUURRLL(), ffeettcchhUUnnqquuootteePPaatthh(),
and ffeettcchhUUnnqquuootteeFFiilleennaammee() return a string that should be deallocated and ffeettcchhUUnnqquuootteeFFiilleennaammee() return a string that should be deallocated
with ffrreeee() after use. with ffrreeee() after use.
ffeettcchhXXGGeett(), ffeettcchhGGeett(), ffeettcchhPPuutt() and ffeettcchhSSttaatt() are similar to ffeettcchhXXGGeett(), ffeettcchhGGeett(), ffeettcchhPPuutt(), and ffeettcchhSSttaatt() are similar to
ffeettcchhXXGGeettUURRLL(), ffeettcchhGGeettUURRLL(), ffeettcchhPPuuttUURRLL() and ffeettcchhSSttaattUURRLL(), except ffeettcchhXXGGeettUURRLL(), ffeettcchhGGeettUURRLL(), ffeettcchhPPuuttUURRLL(), and ffeettcchhSSttaattUURRLL(), except
that they expect a pre-parsed URL in the form of a pointer to a _s_t_r_u_c_t that they expect a pre-parsed URL in the form of a pointer to a _s_t_r_u_c_t
_u_r_l rather than a string. _u_r_l rather than a string.
All of the ffeettcchhXXGGeettXXXXXX(), ffeettcchhGGeettXXXXXX() and ffeettcchhPPuuttXXXXXX() functions All of the ffeettcchhXXGGeettXXXXXX(), ffeettcchhGGeettXXXXXX(), and ffeettcchhPPuuttXXXXXX() functions
return a pointer to a stream which can be used to read or write data from 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 or to the requested document, respectively. Note that although the
implementation details of the individual access methods vary, it can gen- implementation details of the individual access methods vary, it can gen-
@ -226,9 +226,9 @@ DDEESSCCRRIIPPTTIIOONN
of the ffeettcchhPPuuttXXXXXX() functions is write-only. of the ffeettcchhPPuuttXXXXXX() functions is write-only.
FFIILLEE SSCCHHEEMMEE FFIILLEE SSCCHHEEMMEE
ffeettcchhXXGGeettFFiillee(), ffeettcchhGGeettFFiillee() and ffeettcchhPPuuttFFiillee() provide access to doc- ffeettcchhXXGGeettFFiillee(), ffeettcchhGGeettFFiillee(), and ffeettcchhPPuuttFFiillee() provide access to
uments which are files in a locally mounted file system. Only the <docu- documents which are files in a locally mounted file system. Only the
ment> component of the URL is used. <document> component of the URL is used.
ffeettcchhXXGGeettFFiillee() and ffeettcchhGGeettFFiillee() do not accept any flags. ffeettcchhXXGGeettFFiillee() and ffeettcchhGGeettFFiillee() do not accept any flags.
@ -238,16 +238,18 @@ FFIILLEE SSCCHHEEMMEE
them. them.
FFTTPP SSCCHHEEMMEE FFTTPP SSCCHHEEMMEE
ffeettcchhXXGGeettFFTTPP(), ffeettcchhGGeettFFTTPP() and ffeettcchhPPuuttFFTTPP() implement the FTP proto- ffeettcchhXXGGeettFFTTPP(), ffeettcchhGGeettFFTTPP(), and ffeettcchhPPuuttFFTTPP() implement the FTP proto-
col as described in RFC959. col as described in RFC 959.
If the `p' (passive) flag is specified, a passive (rather than active) By default lliibbffeettcchh will attempt to use passive mode first and only fall-
connection will be attempted. back to active mode if the server reports a syntax error. If the `a'
(active) flag is specified, a passive connection is not tried and active
mode is used directly.
If the `l' (low) flag is specified, data sockets will be allocated in the If the `l' (low) flag is specified, data sockets will be allocated in the
low (or default) port range instead of the high port range (see ip(4)). low (or default) port range instead of the high port range (see ip(4)).
If the `d' (direct) flag is specified, ffeettcchhXXGGeettFFTTPP(), ffeettcchhGGeettFFTTPP() and If the `d' (direct) flag is specified, ffeettcchhXXGGeettFFTTPP(), ffeettcchhGGeettFFTTPP(), and
ffeettcchhPPuuttFFTTPP() will use a direct connection even if a proxy server is ffeettcchhPPuuttFFTTPP() will use a direct connection even if a proxy server is
defined. defined.
@ -256,11 +258,11 @@ FFTTPP SSCCHHEEMMEE
mous@<hostname>". mous@<hostname>".
HHTTTTPP SSCCHHEEMMEE HHTTTTPP SSCCHHEEMMEE
The ffeettcchhXXGGeettHHTTTTPP(), ffeettcchhGGeettHHTTTTPP() and ffeettcchhPPuuttHHTTTTPP() functions imple- The ffeettcchhXXGGeettHHTTTTPP(), ffeettcchhGGeettHHTTTTPP(), and ffeettcchhPPuuttHHTTTTPP() functions imple-
ment the HTTP/1.1 protocol. With a little luck, there is even a chance ment the HTTP/1.1 protocol. With a little luck, there is even a chance
that they comply with RFC2616 and RFC2617. that they comply with RFC 2616 and RFC 2617.
If the `d' (direct) flag is specified, ffeettcchhXXGGeettHHTTTTPP(), ffeettcchhGGeettHHTTTTPP() If the `d' (direct) flag is specified, ffeettcchhXXGGeettHHTTTTPP(), ffeettcchhGGeettHHTTTTPP(),
and ffeettcchhPPuuttHHTTTTPP() will use a direct connection even if a proxy server is and ffeettcchhPPuuttHHTTTTPP() will use a direct connection even if a proxy server is
defined. defined.
@ -338,7 +340,7 @@ RREETTUURRNN VVAALLUUEESS
and message, e.g. "File is not available (404 Not Found)" and message, e.g. "File is not available (404 Not Found)"
EENNVVIIRROONNMMEENNTT EENNVVIIRROONNMMEENNTT
FETCH_BIND_ADDRESS Specifies a hostname or IP address to which sockets FETCH_BIND_ADDRESS Specifies a host name or IP address to which sockets
used for outgoing connections will be bound. used for outgoing connections will be bound.
FTP_LOGIN Default FTP login if none was provided in the URL. FTP_LOGIN Default FTP login if none was provided in the URL.
@ -437,24 +439,24 @@ EEXXAAMMPPLLEESS
NO_PROXY=localhost,127.0.0.1 NO_PROXY=localhost,127.0.0.1
SSEEEE AALLSSOO SSEEEE AALLSSOO
fetch(1), ftpio(3), ip(4) ftp(1), ip(4)
J. Postel and J. K. Reynolds, _F_i_l_e _T_r_a_n_s_f_e_r _P_r_o_t_o_c_o_l, October 1985, J. Postel and J. K. Reynolds, _F_i_l_e _T_r_a_n_s_f_e_r _P_r_o_t_o_c_o_l, October 1985, RFC
RFC959. 959.
P. Deutsch, A. Emtage, and A. Marine., _H_o_w _t_o _U_s_e _A_n_o_n_y_m_o_u_s _F_T_P, May P. Deutsch, A. Emtage, and A. Marine, _H_o_w _t_o _U_s_e _A_n_o_n_y_m_o_u_s _F_T_P, May 1994,
1994, RFC1635. RFC 1635.
T. Berners-Lee, L. Masinter, and M. McCahill, _U_n_i_f_o_r_m _R_e_s_o_u_r_c_e _L_o_c_a_t_o_r_s T. Berners-Lee, L. Masinter, and M. McCahill, _U_n_i_f_o_r_m _R_e_s_o_u_r_c_e _L_o_c_a_t_o_r_s
_(_U_R_L_), December 1994, RFC1738. _(_U_R_L_), December 1994, RFC 1738.
R. Fielding, J. Gettys, J. Mogul, H. Frystyk, L. Masinter, P. Leach, and R. Fielding, J. Gettys, J. Mogul, H. Frystyk, L. Masinter, P. Leach, and
T. Berners-Lee, _H_y_p_e_r_t_e_x_t _T_r_a_n_s_f_e_r _P_r_o_t_o_c_o_l _-_- _H_T_T_P_/_1_._1, January 1999, T. Berners-Lee, _H_y_p_e_r_t_e_x_t _T_r_a_n_s_f_e_r _P_r_o_t_o_c_o_l _-_- _H_T_T_P_/_1_._1, January 1999,
RFC2616. RFC 2616.
J. Franks, P. Hallam-Baker, J. Hostetler, S. Lawrence, P. Leach, A. J. Franks, P. Hallam-Baker, J. Hostetler, S. Lawrence, P. Leach, A.
Luotonen, and L. Stewart, _H_T_T_P _A_u_t_h_e_n_t_i_c_a_t_i_o_n_: _B_a_s_i_c _a_n_d _D_i_g_e_s_t _A_c_c_e_s_s Luotonen, and L. Stewart, _H_T_T_P _A_u_t_h_e_n_t_i_c_a_t_i_o_n_: _B_a_s_i_c _a_n_d _D_i_g_e_s_t _A_c_c_e_s_s
_A_u_t_h_e_n_t_i_c_a_t_i_o_n, June 1999, RFC2617. _A_u_t_h_e_n_t_i_c_a_t_i_o_n, June 1999, RFC 2617.
HHIISSTTOORRYY HHIISSTTOORRYY
The ffeettcchh library first appeared in FreeBSD 3.0. The ffeettcchh library first appeared in FreeBSD 3.0.

View File

@ -1,4 +1,4 @@
/* $NetBSD: ftp.c,v 1.1.1.2 2008/10/07 15:55:20 joerg Exp $ */ /* $NetBSD: ftp.c,v 1.1.1.3 2008/10/29 16:18:14 joerg Exp $ */
/*- /*-
* Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav * Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
* Copyright (c) 2008 Joerg Sonnenberger <joerg@NetBSD.org> * Copyright (c) 2008 Joerg Sonnenberger <joerg@NetBSD.org>
@ -629,7 +629,7 @@ ftp_transfer(conn_t *conn, const char *oper, const char *file, const char *op_ar
/* check flags */ /* check flags */
low = CHECK_FLAG('l'); low = CHECK_FLAG('l');
pasv = CHECK_FLAG('p'); pasv = !CHECK_FLAG('a');
verbose = CHECK_FLAG('v'); verbose = CHECK_FLAG('v');
/* passive mode */ /* passive mode */
@ -651,6 +651,8 @@ ftp_transfer(conn_t *conn, const char *oper, const char *file, const char *op_ar
if (sa.ss_family == AF_INET6) if (sa.ss_family == AF_INET6)
unmappedaddr((struct sockaddr_in6 *)&sa, &l); unmappedaddr((struct sockaddr_in6 *)&sa, &l);
retry_mode:
/* open data socket */ /* open data socket */
if ((sd = socket(sa.ss_family, SOCK_STREAM, IPPROTO_TCP)) == -1) { if ((sd = socket(sa.ss_family, SOCK_STREAM, IPPROTO_TCP)) == -1) {
fetch_syserr(); fetch_syserr();
@ -723,6 +725,14 @@ ftp_transfer(conn_t *conn, const char *oper, const char *file, const char *op_ar
goto ouch; goto ouch;
} }
break; break;
case FTP_SYNTAX_ERROR:
if (verbose)
fetch_info("passive mode failed");
/* Close socket and retry with passive mode. */
pasv = 0;
close(sd);
sd = -1;
goto retry_mode;
} }
/* seek to required offset */ /* seek to required offset */