diff options
Diffstat (limited to 'WWW/Library/Implementation/HTFTP.c')
-rw-r--r-- | WWW/Library/Implementation/HTFTP.c | 96 |
1 files changed, 32 insertions, 64 deletions
diff --git a/WWW/Library/Implementation/HTFTP.c b/WWW/Library/Implementation/HTFTP.c index 20cafe2e..a4418474 100644 --- a/WWW/Library/Implementation/HTFTP.c +++ b/WWW/Library/Implementation/HTFTP.c @@ -38,11 +38,6 @@ ** and code to parse dates and sizes on most hosts. ** 27 Mar 93 (FM) Added code for getting dates and sizes on VMS hosts. ** -** Options: -** LISTEN We listen, the other guy connects for data. -** Otherwise, other way round, but problem finding our -** internet address! -** ** Notes: ** Portions Copyright 1994 Trustees of Dartmouth College ** Code for recognizing different FTP servers and @@ -52,15 +47,6 @@ */ /* -** If LISTEN is not defined, PASV is used instead of PORT, and not -** all FTP servers support PASV, so define it unless there is no -** alternative for your system. -*/ -#ifndef NOPORT -#define LISTEN /* @@@@ Test LJM */ -#endif /* !NOPORT */ - -/* BUGS: @@@ Limit connection cache size! Error reporting to user. 400 & 500 errors are ack'ed by user with windows. @@ -81,9 +67,7 @@ BUGS: @@@ Limit connection cache size! #include <HTFTP.h> /* Implemented here */ #include <HTTCP.h> - -/* this define should be in HTFont.h :( */ -#define HT_NON_BREAK_SPACE ((char)1) /* For now */ +#include <HTFont.h> #define REPEAT_PORT /* Give the port number for each file */ #define REPEAT_LISTEN /* Close each listen socket and open a new one */ @@ -109,6 +93,7 @@ BUGS: @@@ Limit connection cache size! #endif /* !IPORT_FTP */ #include <LYUtils.h> +#include <LYGlobalDefs.h> #include <LYStrings.h> #include <LYLeaks.h> @@ -189,14 +174,11 @@ PRIVATE int interrupted_in_next_data_char = FALSE; PRIVATE unsigned short port_number = FIRST_TCP_PORT; #endif /* POLL_PORTS */ -#ifdef LISTEN PRIVATE int master_socket = -1; /* Listening socket = invalid */ PRIVATE char port_command[255]; /* Command for setting the port */ PRIVATE fd_set open_sockets; /* Mask of active channels */ PRIVATE int num_sockets; /* Number of sockets to scan */ -#else PRIVATE unsigned short passive_port; /* Port server specified for data */ -#endif /* LISTEN */ #define NEXT_CHAR HTGetCharacter() /* Use function in HTFormat.c */ @@ -1053,8 +1035,6 @@ PRIVATE int get_connection ARGS2( } -#ifdef LISTEN - /* Close Master (listening) socket ** ------------------------------- ** @@ -1211,7 +1191,7 @@ PRIVATE int get_listen_socket NOARGS #ifdef REPEAT_LISTEN if (master_socket >= 0) (void) close_master_socket(); -#endif /* REPEAD_LISTEN */ +#endif /* REPEAT_LISTEN */ master_socket = new_socket; @@ -1251,7 +1231,6 @@ PRIVATE int get_listen_socket NOARGS return master_socket; /* Good */ } /* get_listen_socket */ -#endif /* LISTEN */ PRIVATE char * months[12] = { "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec" @@ -2891,21 +2870,20 @@ PUBLIC int HTFTPLoad ARGS4( if (status < 0) return status; -#ifdef LISTEN - status = get_listen_socket(); - if (status < 0) { - NETCLOSE (control->socket); - control->socket = -1; - close_master_socket (); - /* HT_INTERRUPTED would fall through, if we could interrupt - somehow in the middle of it, which we currently can't. */ - return status; - } + if (!ftp_passive) { + status = get_listen_socket(); + if (status < 0) { + NETCLOSE (control->socket); + control->socket = -1; + close_master_socket (); + /* HT_INTERRUPTED would fall through, if we could interrupt + somehow in the middle of it, which we currently can't. */ + return status; + } #ifdef REPEAT_PORT -/* Inform the server of the port number we will listen on -*/ - { + /* Inform the server of the port number we will listen on + */ status = response(port_command); if (status == HT_INTERRUPTED) { CTRACE((tfp, "HTFTP: Interrupted in response (port_command)\n")); @@ -2921,16 +2899,12 @@ PUBLIC int HTFTPLoad ARGS4( return -status; /* bad reply */ } CTRACE((tfp, "HTFTP: Port defined.\n")); - } #endif /* REPEAT_PORT */ -#else /* Use PASV */ -/* Tell the server to be passive -*/ - { + } else { /* Tell the server to be passive */ char command[LINE_LENGTH+1]; char *p; - int reply, h0, h1, h2, h3, p0, p1; /* Parts of reply */ - int status; + int h0, h1, h2, h3, p0, p1; /* Parts of reply */ + data_soc = status; status = send_cmd_1("PASV"); @@ -2945,19 +2919,18 @@ PUBLIC int HTFTPLoad ARGS4( while (--p > response_text && '0' <= *p && *p <= '9') ; /* null body */ - status = sscanf(p+1, "%d,%d,%d,%d,%d,%d", - &h0, &h1, &h2, &h3, &p0, &p1); - if (status < 4) { - fprintf(tfp, "HTFTP: PASV reply has no inet address!\n"); - return -99; - } - passive_port = (p0<<8) + p1; - CTRACE((tfp, "HTFTP: Server is listening on port %d\n", - passive_port)); + status = sscanf(p+1, "%d,%d,%d,%d,%d,%d", + &h0, &h1, &h2, &h3, &p0, &p1); + if (status < 4) { + fprintf(tfp, "HTFTP: PASV reply has no inet address!\n"); + return -99; + } + passive_port = (p0<<8) + p1; + CTRACE((tfp, "HTFTP: Server is listening on port %d\n", + passive_port)); + /* Open connection for data: */ -/* Open connection for data: -*/ sprintf(command, "ftp://%d.%d.%d.%d:%d/",h0,h1,h2,h3,passive_port); status = HTDoConnect(name, "FTP", passive_port, &data_soc); @@ -2970,7 +2943,6 @@ PUBLIC int HTFTPLoad ARGS4( CTRACE((tfp, "FTP data connected, socket %d\n", data_soc)); } -#endif /* use PASV */ status = 0; break; /* No more retries */ @@ -3460,10 +3432,8 @@ PUBLIC int HTFTPLoad ARGS4( } listen: -#ifdef LISTEN -/* Wait for the connection -*/ - { + if(!ftp_passive) { + /* Wait for the connection */ struct sockaddr_in soc_address; int soc_addrlen=sizeof(soc_address); #ifdef SOCKS @@ -3482,10 +3452,8 @@ listen: } CTRACE((tfp, "TCP: Accepted new socket %d\n", status)); data_soc = status; - } -#else -/* @@ */ -#endif /* LISTEN */ + } /* !ftp_passive */ + if ((status = send_cmd_nowait("QUIT")) == 1) outstanding++; if (isDirectory) { |