Tons of type, style and warning fixes that have been rotting in my tree for

ages - some of which wouldn't be necessary if gcc wasn't broken or TPTB were
willing to do something (-fno-builtin) about it.
This commit is contained in:
des 2001-10-18 08:29:26 +00:00
parent 68b394464f
commit 33b095fe4a
5 changed files with 101 additions and 70 deletions

View File

@ -2,7 +2,8 @@
MAINTAINER= des@freebsd.org
LIB= fetch
CFLAGS+= -I. -Wall -pedantic
WARNS?= 2
CFLAGS+= -I.
CFLAGS+= -DINET6
.if !defined(DEBUG)
CFLAGS+= -DNDEBUG
@ -38,12 +39,33 @@ httperr.h: http.errors
@echo " { -1, FETCH_UNKNOWN, \"Unknown HTTP error\" }" >> ${.TARGET}
@echo "};" >> ${.TARGET}
.for MP in fetchFreeURL fetchGet fetchGetFTP fetchGetFile fetchGetHTTP \
fetchGetURL fetchList fetchListFTP fetchListFile fetchListHTTP fetchListURL \
fetchMakeURL fetchParseURL fetchPut fetchPutFTP fetchPutFile fetchPutHTTP \
fetchPutURL fetchStat fetchStatFTP fetchStatFile fetchStatHTTP fetchStatURL \
fetchXGet fetchXGetFTP fetchXGetFile fetchXGetHTTP fetchXGetURL
MLINKS+= fetch.3 ${MP}.3
.endfor
MLINKS+= fetch.3 fetchFreeURL.3
MLINKS+= fetch.3 fetchGet.3
MLINKS+= fetch.3 fetchGetFTP.3
MLINKS+= fetch.3 fetchGetFile.3
MLINKS+= fetch.3 fetchGetHTTP.3
MLINKS+= fetch.3 fetchGetURL.3
MLINKS+= fetch.3 fetchList.3
MLINKS+= fetch.3 fetchListFTP.3
MLINKS+= fetch.3 fetchListFile.3
MLINKS+= fetch.3 fetchListHTTP.3
MLINKS+= fetch.3 fetchListURL.3
MLINKS+= fetch.3 fetchMakeURL.3
MLINKS+= fetch.3 fetchParseURL.3
MLINKS+= fetch.3 fetchPut.3
MLINKS+= fetch.3 fetchPutFTP.3
MLINKS+= fetch.3 fetchPutFile.3
MLINKS+= fetch.3 fetchPutHTTP.3
MLINKS+= fetch.3 fetchPutURL.3
MLINKS+= fetch.3 fetchStat.3
MLINKS+= fetch.3 fetchStatFTP.3
MLINKS+= fetch.3 fetchStatFile.3
MLINKS+= fetch.3 fetchStatHTTP.3
MLINKS+= fetch.3 fetchStatURL.3
MLINKS+= fetch.3 fetchXGet.3
MLINKS+= fetch.3 fetchXGetFTP.3
MLINKS+= fetch.3 fetchXGetFile.3
MLINKS+= fetch.3 fetchXGetHTTP.3
MLINKS+= fetch.3 fetchXGetURL.3
.include <bsd.lib.mk>

View File

@ -340,13 +340,16 @@ _fetch_putln(int fd, const char *str, size_t len)
ssize_t wlen;
/* XXX should enforce timeout */
iov[0].iov_base = (char *)str;
(const char *)iov[0].iov_base = str; /* XXX */
iov[0].iov_len = len;
iov[1].iov_base = (char *)ENDL;
(const char *)iov[1].iov_base = ENDL; /* XXX */
iov[1].iov_len = sizeof ENDL;
len += sizeof ENDL;
wlen = writev(fd, iov, 2);
if (wlen < 0 || (size_t)wlen != len)
return -1;
DEBUG(fprintf(stderr, "\033[1m>>> %s\n\033[m", str));
return (wlen != len);
return 0;
}
@ -354,7 +357,7 @@ _fetch_putln(int fd, const char *str, size_t len)
int
_fetch_add_entry(struct url_ent **p, int *size, int *len,
const char *name, struct url_stat *stat)
const char *name, struct url_stat *us)
{
struct url_ent *tmp;
@ -383,7 +386,7 @@ _fetch_add_entry(struct url_ent **p, int *size, int *len,
tmp = *p + *len;
snprintf(tmp->name, PATH_MAX, "%s", name);
bcopy(stat, &tmp->stat, sizeof *stat);
bcopy(us, &tmp->stat, sizeof *us);
(*len)++;
(++tmp)->name[0] = 0;

View File

@ -42,16 +42,16 @@ struct fetcherr {
const char *string;
};
void _fetch_seterr(struct fetcherr *p, int e);
void _fetch_seterr(struct fetcherr *, int);
void _fetch_syserr(void);
void _fetch_info(const char *fmt, ...);
void _fetch_info(const char *, ...);
int _fetch_default_port(const char *);
int _fetch_default_proxy_port(const char *);
int _fetch_connect(const char *host, int port, int af, int verbose);
int _fetch_getln(int fd, char **buf, size_t *size, size_t *len);
int _fetch_putln(int fd, const char *str, size_t len);
int _fetch_add_entry(struct url_ent **p, int *size, int *len,
const char *name, struct url_stat *stat);
int _fetch_connect(const char *, int, int, int);
int _fetch_getln(int, char **, size_t *, size_t *);
int _fetch_putln(int, const char *, size_t);
int _fetch_add_entry(struct url_ent **, int *, int *,
const char *, struct url_stat *);
#define _ftp_seterr(n) _fetch_seterr(_ftp_errlist, n)
#define _http_seterr(n) _fetch_seterr(_http_errlist, n)
@ -72,9 +72,9 @@ int _fetch_add_entry(struct url_ent **p, int *size, int *len,
* Note that _http_request() frees purl, which is way ugly but saves us a
* whole lot of trouble.
*/
FILE *_http_request(struct url *URL, const char *op,
struct url_stat *us, struct url *purl,
const char *flags);
FILE *_http_request(struct url *, const char *,
struct url_stat *, struct url *,
const char *);
/*
* Check whether a particular flag is set

View File

@ -267,7 +267,7 @@ _ftp_stat(int cd, const char *file, struct url_stat *us)
}
if (us->size == 0)
us->size = -1;
DEBUG(fprintf(stderr, "size: [\033[1m%lld\033[m]\n", us->size));
DEBUG(fprintf(stderr, "size: [\033[1m%lld\033[m]\n", (long long)us->size));
if ((e = _ftp_cmd(cd, "MDTM %s", s)) != FTP_FILE_STATUS) {
_ftp_seterr(e);
@ -385,7 +385,7 @@ _ftp_writefn(void *v, const char *buf, int len)
}
static fpos_t
_ftp_seekfn(void *v, fpos_t pos, int whence)
_ftp_seekfn(void *v, fpos_t pos __unused, int whence __unused)
{
struct ftpio *io;
@ -450,7 +450,7 @@ static FILE *
_ftp_transfer(int cd, const char *oper, const char *file,
int mode, off_t offset, const char *flags)
{
struct sockaddr_storage sin;
struct sockaddr_storage sa;
struct sockaddr_in6 *sin6;
struct sockaddr_in *sin4;
int low, pasv, verbose;
@ -470,14 +470,14 @@ _ftp_transfer(int cd, const char *oper, const char *file,
strncasecmp(s, "no", 2) != 0);
/* find our own address, bind, and listen */
l = sizeof sin;
if (getsockname(cd, (struct sockaddr *)&sin, &l) == -1)
l = sizeof sa;
if (getsockname(cd, (struct sockaddr *)&sa, &l) == -1)
goto sysouch;
if (sin.ss_family == AF_INET6)
unmappedaddr((struct sockaddr_in6 *)&sin);
if (sa.ss_family == AF_INET6)
unmappedaddr((struct sockaddr_in6 *)&sa);
/* open data socket */
if ((sd = socket(sin.ss_family, SOCK_STREAM, IPPROTO_TCP)) == -1) {
if ((sd = socket(sa.ss_family, SOCK_STREAM, IPPROTO_TCP)) == -1) {
_fetch_syserr();
return NULL;
}
@ -485,13 +485,13 @@ _ftp_transfer(int cd, const char *oper, const char *file,
if (pasv) {
u_char addr[64];
char *ln, *p;
int i;
unsigned int i;
int port;
/* send PASV command */
if (verbose)
_fetch_info("setting passive mode");
switch (sin.ss_family) {
switch (sa.ss_family) {
case AF_INET:
if ((e = _ftp_cmd(cd, "PASV")) != FTP_PASSIVE_MODE)
goto ouch;
@ -555,14 +555,14 @@ _ftp_transfer(int cd, const char *oper, const char *file,
goto sysouch;
/* construct sockaddr for data socket */
l = sizeof sin;
if (getpeername(cd, (struct sockaddr *)&sin, &l) == -1)
l = sizeof sa;
if (getpeername(cd, (struct sockaddr *)&sa, &l) == -1)
goto sysouch;
if (sin.ss_family == AF_INET6)
unmappedaddr((struct sockaddr_in6 *)&sin);
switch (sin.ss_family) {
if (sa.ss_family == AF_INET6)
unmappedaddr((struct sockaddr_in6 *)&sa);
switch (sa.ss_family) {
case AF_INET6:
sin6 = (struct sockaddr_in6 *)&sin;
sin6 = (struct sockaddr_in6 *)&sa;
if (e == FTP_EPASSIVE_MODE)
sin6->sin6_port = htons(port);
else {
@ -571,7 +571,7 @@ _ftp_transfer(int cd, const char *oper, const char *file,
}
break;
case AF_INET:
sin4 = (struct sockaddr_in *)&sin;
sin4 = (struct sockaddr_in *)&sa;
if (e == FTP_EPASSIVE_MODE)
sin4->sin_port = htons(port);
else {
@ -587,7 +587,7 @@ _ftp_transfer(int cd, const char *oper, const char *file,
/* connect to data port */
if (verbose)
_fetch_info("opening data connection");
if (connect(sd, (struct sockaddr *)&sin, sin.ss_len) == -1)
if (connect(sd, (struct sockaddr *)&sa, sa.ss_len) == -1)
goto sysouch;
/* make the server initiate the transfer */
@ -604,9 +604,9 @@ _ftp_transfer(int cd, const char *oper, const char *file,
char *ap;
char hname[INET6_ADDRSTRLEN];
switch (sin.ss_family) {
switch (sa.ss_family) {
case AF_INET6:
((struct sockaddr_in6 *)&sin)->sin6_port = 0;
((struct sockaddr_in6 *)&sa)->sin6_port = 0;
#ifdef IPV6_PORTRANGE
arg = low ? IPV6_PORTRANGE_DEFAULT : IPV6_PORTRANGE_HIGH;
if (setsockopt(sd, IPPROTO_IPV6, IPV6_PORTRANGE,
@ -615,7 +615,7 @@ _ftp_transfer(int cd, const char *oper, const char *file,
#endif
break;
case AF_INET:
((struct sockaddr_in *)&sin)->sin_port = 0;
((struct sockaddr_in *)&sa)->sin_port = 0;
arg = low ? IP_PORTRANGE_DEFAULT : IP_PORTRANGE_HIGH;
if (setsockopt(sd, IPPROTO_IP, IP_PORTRANGE,
(char *)&arg, sizeof arg) == -1)
@ -624,17 +624,17 @@ _ftp_transfer(int cd, const char *oper, const char *file,
}
if (verbose)
_fetch_info("binding data socket");
if (bind(sd, (struct sockaddr *)&sin, sin.ss_len) == -1)
if (bind(sd, (struct sockaddr *)&sa, sa.ss_len) == -1)
goto sysouch;
if (listen(sd, 1) == -1)
goto sysouch;
/* find what port we're on and tell the server */
if (getsockname(sd, (struct sockaddr *)&sin, &l) == -1)
if (getsockname(sd, (struct sockaddr *)&sa, &l) == -1)
goto sysouch;
switch (sin.ss_family) {
switch (sa.ss_family) {
case AF_INET:
sin4 = (struct sockaddr_in *)&sin;
sin4 = (struct sockaddr_in *)&sa;
a = ntohl(sin4->sin_addr.s_addr);
p = ntohs(sin4->sin_port);
e = _ftp_cmd(cd, "PORT %d,%d,%d,%d,%d,%d",
@ -645,8 +645,8 @@ _ftp_transfer(int cd, const char *oper, const char *file,
case AF_INET6:
#define UC(b) (((int)b)&0xff)
e = -1;
sin6 = (struct sockaddr_in6 *)&sin;
if (getnameinfo((struct sockaddr *)&sin, sin.ss_len,
sin6 = (struct sockaddr_in6 *)&sa;
if (getnameinfo((struct sockaddr *)&sa, sa.ss_len,
hname, sizeof(hname),
NULL, 0, NI_NUMERICHOST) == 0) {
e = _ftp_cmd(cd, "EPRT |%d|%s|%d|", 2, hname,
@ -718,7 +718,7 @@ _ftp_transfer(int cd, const char *oper, const char *file,
static int
_ftp_authenticate(int cd, struct url *url, struct url *purl)
{
char *user, *pwd, *logname;
const char *user, *pwd, *logname;
char pbuf[MAXHOSTNAMELEN + MAXLOGNAME + 1];
int e, len;
@ -1028,7 +1028,7 @@ fetchStatFTP(struct url *url, struct url_stat *us, const char *flags)
* List a directory
*/
struct url_ent *
fetchListFTP(struct url *url, const char *flags)
fetchListFTP(struct url *url __unused, const char *flags __unused)
{
warnx("fetchListFTP(): not implemented");
return NULL;

View File

@ -110,13 +110,13 @@ struct cookie
int fd;
char *buf;
size_t b_size;
size_t b_len;
ssize_t b_len;
int b_pos;
int eof;
int error;
long chunksize;
size_t chunksize;
#ifndef NDEBUG
long total;
size_t total;
#endif
};
@ -149,7 +149,8 @@ _http_new_chunk(struct cookie *c)
"end of last chunk\033[m\n");
else
fprintf(stderr, "\033[1m_http_fillbuf(): "
"new chunk: %ld (%ld)\033[m\n", c->chunksize, c->total);
"new chunk: %lu (%lu)\033[m\n",
(unsigned long)c->chunksize, (unsigned long)c->total);
#endif
return c->chunksize;
@ -297,11 +298,11 @@ typedef enum {
hdr_location,
hdr_transfer_encoding,
hdr_www_authenticate
} hdr;
} hdr_t;
/* Names of interesting headers */
static struct {
hdr num;
hdr_t num;
const char *name;
} hdr_names[] = {
{ hdr_content_length, "Content-Length" },
@ -404,7 +405,7 @@ _http_match(const char *str, const char *hdr)
/*
* Get the next header and return the appropriate symbolic code.
*/
static hdr
static hdr_t
_http_next_header(int fd, const char **p)
{
int i;
@ -462,7 +463,10 @@ _http_parse_length(const char *p, off_t *length)
for (len = 0; *p && isdigit(*p); ++p)
len = len * 10 + (*p - '0');
DEBUG(fprintf(stderr, "content length: [\033[1m%lld\033[m]\n", len));
if (*p)
return -1;
DEBUG(fprintf(stderr, "content length: [\033[1m%lld\033[m]\n",
(long long)len));
*length = len;
return 0;
}
@ -473,7 +477,7 @@ _http_parse_length(const char *p, off_t *length)
static int
_http_parse_range(const char *p, off_t *offset, off_t *length, off_t *size)
{
int first, last, len;
off_t first, last, len;
if (strncasecmp(p, "bytes ", 6) != 0)
return -1;
@ -487,10 +491,10 @@ _http_parse_range(const char *p, off_t *offset, off_t *length, off_t *size)
return -1;
for (len = 0, ++p; *p && isdigit(*p); ++p)
len = len * 10 + *p - '0';
if (len < last - first + 1)
if (*p || len < last - first + 1)
return -1;
DEBUG(fprintf(stderr, "content range: [\033[1m%d-%d/%d\033[m]\n",
first, last, len));
DEBUG(fprintf(stderr, "content range: [\033[1m%lld-%lld/%lld\033[m]\n",
(long long)first, (long long)last, (long long)len));
*offset = first;
*length = last - first + 1;
*size = len;
@ -688,7 +692,7 @@ _http_request(struct url *URL, const char *op, struct url_stat *us,
time_t mtime;
const char *p;
FILE *f;
hdr h;
hdr_t h;
char *host;
#ifdef INET6
char hbuf[MAXHOSTNAMELEN + 1];
@ -783,7 +787,7 @@ _http_request(struct url *URL, const char *op, struct url_stat *us,
else
_http_cmd(fd, "User-Agent: %s " _LIBFETCH_VER, __progname);
if (url->offset)
_http_cmd(fd, "Range: bytes=%lld-", url->offset);
_http_cmd(fd, "Range: bytes=%lld-", (long long)url->offset);
_http_cmd(fd, "Connection: close");
_http_cmd(fd, "");
@ -921,8 +925,10 @@ _http_request(struct url *URL, const char *op, struct url_stat *us,
goto ouch;
}
DEBUG(fprintf(stderr, "offset %lld, length %lld, size %lld, clength %lld\n",
offset, length, size, clength));
DEBUG(fprintf(stderr, "offset %lld, length %lld,"
" size %lld, clength %lld\n",
(long long)offset, (long long)length,
(long long)size, (long long)clength));
/* check for inconsistencies */
if (clength != -1 && length != -1 && clength != length) {
@ -1006,7 +1012,7 @@ fetchGetHTTP(struct url *URL, const char *flags)
* Store a file by HTTP
*/
FILE *
fetchPutHTTP(struct url *URL, const char *flags)
fetchPutHTTP(struct url *URL __unused, const char *flags __unused)
{
warnx("fetchPutHTTP(): not implemented");
return NULL;
@ -1030,7 +1036,7 @@ fetchStatHTTP(struct url *URL, struct url_stat *us, const char *flags)
* List a directory
*/
struct url_ent *
fetchListHTTP(struct url *url, const char *flags)
fetchListHTTP(struct url *url __unused, const char *flags __unused)
{
warnx("fetchListHTTP(): not implemented");
return NULL;