summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>1998-12-16 11:44:31 +0000
committerdes <des@FreeBSD.org>1998-12-16 11:44:31 +0000
commitf13cf4998ebeac5def876891741a5d135fc7f867 (patch)
tree47e11589b8ea0c705b1f9551ca529bb1a4ac8e5d
parent37f6ae6efa76ffd76030b285155c142929e27e71 (diff)
downloadFreeBSD-src-f13cf4998ebeac5def876891741a5d135fc7f867.zip
FreeBSD-src-f13cf4998ebeac5def876891741a5d135fc7f867.tar.gz
Remove unused header files. Fix a few shadowing bugs. Improve error reporting.
-rw-r--r--lib/libfetch/ftp.c55
-rw-r--r--lib/libfetch/http.c32
2 files changed, 30 insertions, 57 deletions
diff --git a/lib/libfetch/ftp.c b/lib/libfetch/ftp.c
index 2e2e8a2..3fe7181 100644
--- a/lib/libfetch/ftp.c
+++ b/lib/libfetch/ftp.c
@@ -25,7 +25,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $Id: ftp.c,v 1.7 1998/11/06 22:14:08 des Exp $
+ * $Id: ftp.c,v 1.8 1998/12/16 10:24:55 des Exp $
*/
/*
@@ -58,11 +58,8 @@
#include <sys/param.h>
#include <sys/socket.h>
#include <netinet/in.h>
-#include <sys/errno.h>
#include <ctype.h>
-#include <errno.h>
-#include <netdb.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
@@ -73,13 +70,13 @@
#include "common.h"
#include "ftperr.h"
-#define FTP_DEFAULT_TO_ANONYMOUS
#define FTP_ANONYMOUS_USER "ftp"
#define FTP_ANONYMOUS_PASSWORD "ftp"
#define FTP_DEFAULT_PORT 21
#define FTP_OPEN_DATA_CONNECTION 150
#define FTP_OK 200
+#define FTP_SERVICE_READY 220
#define FTP_PASSIVE_MODE 227
#define FTP_LOGGED_IN 230
#define FTP_FILE_ACTION_OK 250
@@ -97,15 +94,11 @@ static char *_ftp_last_reply;
* Get server response, check that first digit is a '2'
*/
static int
-_ftp_chkerr(FILE *s, int *e)
+_ftp_chkerr(FILE *s)
{
char *line;
size_t len;
- int err;
- if (e)
- *e = 0;
-
do {
if (((line = fgetln(s, &len)) == NULL) || (len < 4)) {
_fetch_syserr();
@@ -123,17 +116,10 @@ _ftp_chkerr(FILE *s, int *e)
if (!isdigit(line[1]) || !isdigit(line[1])
|| !isdigit(line[2]) || (line[3] != ' ')) {
- _ftp_seterr(0);
return -1;
}
- err = (line[0] - '0') * 100 + (line[1] - '0') * 10 + (line[2] - '0');
- _ftp_seterr(err);
-
- if (e)
- *e = err;
-
- return (line[0] == '2') - 1;
+ return (line[0] - '0') * 100 + (line[1] - '0') * 10 + (line[2] - '0');
}
/*
@@ -143,7 +129,6 @@ static int
_ftp_cmd(FILE *f, char *fmt, ...)
{
va_list ap;
- int e;
va_start(ap, fmt);
vfprintf(f, fmt, ap);
@@ -154,8 +139,7 @@ _ftp_cmd(FILE *f, char *fmt, ...)
#endif
va_end(ap);
- _ftp_chkerr(f, &e);
- return e;
+ return _ftp_chkerr(f);
}
/*
@@ -310,8 +294,10 @@ _ftp_connect(char *host, int port, char *user, char *pwd, int verbose)
}
/* expect welcome message */
- if (_ftp_chkerr(f, NULL) == -1)
+ if ((e = _ftp_chkerr(f)) != FTP_SERVICE_READY) {
+ _ftp_seterr(e);
goto fouch;
+ }
/* send user name and password */
if (!user || !*user)
@@ -327,12 +313,16 @@ _ftp_connect(char *host, int port, char *user, char *pwd, int verbose)
}
/* did the server request an account? */
- if (e == FTP_NEED_ACCOUNT)
- /* help! */ ;
+ if (e == FTP_NEED_ACCOUNT) {
+ _ftp_seterr(e);
+ goto fouch;
+ }
/* we should be done by now */
- if (e != FTP_LOGGED_IN)
+ if (e != FTP_LOGGED_IN) {
+ _ftp_seterr(e);
goto fouch;
+ }
/* might as well select mode and type at once */
#ifdef FTP_FORCE_STREAM_MODE
@@ -359,7 +349,7 @@ fouch:
static void
_ftp_disconnect(FILE *f)
{
- _ftp_cmd(f, "QUIT" ENDL);
+ (void)_ftp_cmd(f, "QUIT" ENDL);
fclose(f);
}
@@ -383,18 +373,15 @@ static FILE *
fetchXxxFTP(struct url *url, char *oper, char *mode, char *flags)
{
FILE *cf = NULL;
- int e;
/* set default port */
if (!url->port)
url->port = FTP_DEFAULT_PORT;
- /* try to use previously cached connection; there should be a 226 waiting */
- if (_ftp_isconnected(url)) {
- _ftp_chkerr(cached_socket, &e);
- if (e > 0)
+ /* try to use previously cached connection */
+ if (_ftp_isconnected(url))
+ if (_ftp_cmd(cached_socket, "NOOP" ENDL) > 0)
cf = cached_socket;
- }
/* connect to server */
if (!cf) {
@@ -409,7 +396,8 @@ fetchXxxFTP(struct url *url, char *oper, char *mode, char *flags)
}
/* initiate the transfer */
- return _ftp_transfer(cf, oper, url->doc, mode, (flags && strchr(flags, 'p')));
+ return _ftp_transfer(cf, oper, url->doc, mode,
+ (flags && strchr(flags, 'p')));
}
/*
@@ -436,4 +424,3 @@ fetchStatFTP(struct url *url, struct url_stat *us, char *flags)
warnx("fetchStatFTP(): not implemented");
return -1;
}
-
diff --git a/lib/libfetch/http.c b/lib/libfetch/http.c
index 6f0388d..f5a065e 100644
--- a/lib/libfetch/http.c
+++ b/lib/libfetch/http.c
@@ -25,7 +25,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $Id: http.c,v 1.7 1998/11/06 22:14:08 des Exp $
+ * $Id: http.c,v 1.8 1998/12/16 10:24:55 des Exp $
*/
/*
@@ -61,15 +61,9 @@
* SUCH DAMAGE. */
#include <sys/param.h>
-#include <sys/errno.h>
-#include <sys/socket.h>
-#include <sys/types.h>
-
-#include <netinet/in.h>
#include <err.h>
#include <ctype.h>
-#include <netdb.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
@@ -80,12 +74,6 @@
#include "common.h"
#include "httperr.h"
-#ifndef NDEBUG
-#define DEBUG(x) do x; while (0)
-#else
-#define DEBUG(x) do { } while (0)
-#endif
-
extern char *__progname;
#define ENDL "\r\n"
@@ -305,9 +293,9 @@ _http_auth(char *usr, char *pwd)
FILE *
fetchGetHTTP(struct url *URL, char *flags)
{
- int sd = -1, err, i, enc = ENC_NONE, verbose;
+ int sd = -1, e, i, enc = ENC_NONE, verbose;
struct cookie *c;
- char *ln, *p, *q;
+ char *ln, *p, *px, *q;
FILE *f, *cf;
size_t len;
@@ -322,13 +310,11 @@ fetchGetHTTP(struct url *URL, char *flags)
URL->port = 80; /* default HTTP port */
/* attempt to connect to proxy server */
- if (getenv("HTTP_PROXY")) {
- char *px, host[MAXHOSTNAMELEN];
+ if ((px = getenv("HTTP_PROXY")) != NULL) {
+ char host[MAXHOSTNAMELEN];
int port = 3128; /* XXX I think 3128 is default... check? */
- size_t len;
/* measure length */
- px = getenv("HTTP_PROXY");
len = strcspn(px, ":");
/* get port (atoi is a little too tolerant perhaps?) */
@@ -389,12 +375,12 @@ fetchGetHTTP(struct url *URL, char *flags)
p++;
if (!isdigit(*p))
goto fouch;
- err = atoi(p);
- DEBUG(fprintf(stderr, "code: [\033[1m%d\033[m]\n", err));
+ e = atoi(p);
+ DEBUG(fprintf(stderr, "code: [\033[1m%d\033[m]\n", e));
/* add code to handle redirects later */
- if (err != 200) {
- _http_seterr(err);
+ if (e != 200) {
+ _http_seterr(e);
goto fouch;
}
OpenPOWER on IntegriCloud