Deleted Added
full compact
ftp.c (67892) ftp.c (68551)
1/*-
2 * Copyright (c) 1998 Dag-Erling Co�dan Sm�rgrav
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
1/*-
2 * Copyright (c) 1998 Dag-Erling Co�dan Sm�rgrav
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * $FreeBSD: head/lib/libfetch/ftp.c 67892 2000-10-29 15:56:10Z des $
28 * $FreeBSD: head/lib/libfetch/ftp.c 68551 2000-11-10 08:43:40Z des $
29 */
30
31/*
32 * Portions of this code were taken from or based on ftpio.c:
33 *
34 * ----------------------------------------------------------------------------
35 * "THE BEER-WARE LICENSE" (Revision 42):
36 * <phk@login.dknet.dk> wrote this file. As long as you retain this notice you

--- 669 unchanged lines hidden (view full) ---

706 if (e != -1)
707 _ftp_seterr(e);
708 if (sd >= 0)
709 close(sd);
710 return NULL;
711}
712
713/*
29 */
30
31/*
32 * Portions of this code were taken from or based on ftpio.c:
33 *
34 * ----------------------------------------------------------------------------
35 * "THE BEER-WARE LICENSE" (Revision 42):
36 * <phk@login.dknet.dk> wrote this file. As long as you retain this notice you

--- 669 unchanged lines hidden (view full) ---

706 if (e != -1)
707 _ftp_seterr(e);
708 if (sd >= 0)
709 close(sd);
710 return NULL;
711}
712
713/*
714 * Return default port
715 */
716static int
717_ftp_default_port(void)
718{
719 struct servent *se;
720
721 if ((se = getservbyname(SCHEME_FTP, "tcp")) != NULL)
722 return ntohs(se->s_port);
723 return FTP_DEFAULT_PORT;
724}
725
726/*
727 * Log on to FTP server
728 */
729static int
730_ftp_connect(struct url *url, struct url *purl, char *flags)
731{
732 int cd, e, direct, verbose;
733#ifdef INET6
734 int af = AF_UNSPEC;

--- 36 unchanged lines hidden (view full) ---

771 goto fouch;
772
773 /* XXX FTP_AUTH, and maybe .netrc */
774
775 /* send user name and password */
776 user = url->user;
777 if (!user || !*user)
778 user = FTP_ANONYMOUS_USER;
714 * Log on to FTP server
715 */
716static int
717_ftp_connect(struct url *url, struct url *purl, char *flags)
718{
719 int cd, e, direct, verbose;
720#ifdef INET6
721 int af = AF_UNSPEC;

--- 36 unchanged lines hidden (view full) ---

758 goto fouch;
759
760 /* XXX FTP_AUTH, and maybe .netrc */
761
762 /* send user name and password */
763 user = url->user;
764 if (!user || !*user)
765 user = FTP_ANONYMOUS_USER;
779 if (purl && url->port == FTP_DEFAULT_PORT)
766 if (purl && url->port == _fetch_default_port(url->scheme))
780 e = _ftp_cmd(cd, "USER %s@%s", user, url->host);
781 else if (purl)
782 e = _ftp_cmd(cd, "USER %s@%s@%d", user, url->host, url->port);
783 else
784 e = _ftp_cmd(cd, "USER %s", user);
785
786 /* did the server request a password? */
787 if (e == FTP_NEED_PASSWORD) {

--- 66 unchanged lines hidden (view full) ---

854_ftp_cached_connect(struct url *url, struct url *purl, char *flags)
855{
856 int e, cd;
857
858 cd = -1;
859
860 /* set default port */
861 if (!url->port)
767 e = _ftp_cmd(cd, "USER %s@%s", user, url->host);
768 else if (purl)
769 e = _ftp_cmd(cd, "USER %s@%s@%d", user, url->host, url->port);
770 else
771 e = _ftp_cmd(cd, "USER %s", user);
772
773 /* did the server request a password? */
774 if (e == FTP_NEED_PASSWORD) {

--- 66 unchanged lines hidden (view full) ---

841_ftp_cached_connect(struct url *url, struct url *purl, char *flags)
842{
843 int e, cd;
844
845 cd = -1;
846
847 /* set default port */
848 if (!url->port)
862 url->port = _ftp_default_port();
849 url->port = _fetch_default_port(url->scheme);
863
864 /* try to use previously cached connection */
865 if (_ftp_isconnected(url)) {
866 e = _ftp_cmd(cached_socket, "NOOP");
867 if (e == FTP_OK || e == FTP_SYNTAX_ERROR)
868 return cached_socket;
869 }
870

--- 14 unchanged lines hidden (view full) ---

885_ftp_get_proxy(void)
886{
887 struct url *purl;
888 char *p;
889
890 if (((p = getenv("FTP_PROXY")) || (p = getenv("HTTP_PROXY"))) &&
891 *p && (purl = fetchParseURL(p)) != NULL) {
892 if (!*purl->scheme)
850
851 /* try to use previously cached connection */
852 if (_ftp_isconnected(url)) {
853 e = _ftp_cmd(cached_socket, "NOOP");
854 if (e == FTP_OK || e == FTP_SYNTAX_ERROR)
855 return cached_socket;
856 }
857

--- 14 unchanged lines hidden (view full) ---

872_ftp_get_proxy(void)
873{
874 struct url *purl;
875 char *p;
876
877 if (((p = getenv("FTP_PROXY")) || (p = getenv("HTTP_PROXY"))) &&
878 *p && (purl = fetchParseURL(p)) != NULL) {
879 if (!*purl->scheme)
893 strcpy(purl->scheme, SCHEME_FTP);
880 strcpy(purl->scheme, SCHEME_HTTP);
894 if (!purl->port)
881 if (!purl->port)
895 purl->port = _ftp_default_port();
882 purl->port = _fetch_default_proxy_port(purl->scheme);
896 if (strcasecmp(purl->scheme, SCHEME_FTP) == 0 ||
897 strcasecmp(purl->scheme, SCHEME_HTTP) == 0)
898 return purl;
899 fetchFreeURL(purl);
900 }
901 return NULL;
902}
903

--- 129 unchanged lines hidden ---
883 if (strcasecmp(purl->scheme, SCHEME_FTP) == 0 ||
884 strcasecmp(purl->scheme, SCHEME_HTTP) == 0)
885 return purl;
886 fetchFreeURL(purl);
887 }
888 return NULL;
889}
890

--- 129 unchanged lines hidden ---