diff options
| author | Dag-Erling Smørgrav <des@FreeBSD.org> | 2000-10-30 14:50:33 +0000 |
|---|---|---|
| committer | Dag-Erling Smørgrav <des@FreeBSD.org> | 2000-10-30 14:50:33 +0000 |
| commit | ab2b55916e57bfbeb27fcb827ebb1567deb131d8 (patch) | |
| tree | 7a3fa9e0f14b079fa5a3d439a2ce691edf9fcd65 /lib | |
| parent | 4cc01a5a9b96095be1eaab76a18ffdf868f4ee96 (diff) | |
Notes
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/libfetch/common.h | 5 | ||||
| -rw-r--r-- | lib/libfetch/fetch.c | 8 | ||||
| -rw-r--r-- | lib/libfetch/file.c | 2 | ||||
| -rw-r--r-- | lib/libfetch/ftp.c | 48 | ||||
| -rw-r--r-- | lib/libfetch/http.c | 12 |
5 files changed, 52 insertions, 23 deletions
diff --git a/lib/libfetch/common.h b/lib/libfetch/common.h index 393010b4b820..4470c5ba9d97 100644 --- a/lib/libfetch/common.h +++ b/lib/libfetch/common.h @@ -71,4 +71,9 @@ int _fetch_add_entry(struct url_ent **p, int *size, int *len, FILE *_http_request(struct url *URL, char *op, struct url_stat *us, struct url *purl, char *flags); +/* + * Check whether a particular flag is set + */ +#define CHECK_FLAG(x) (flags && strchr(flags, (x))) + #endif diff --git a/lib/libfetch/fetch.c b/lib/libfetch/fetch.c index b814336285b3..46da7ce15510 100644 --- a/lib/libfetch/fetch.c +++ b/lib/libfetch/fetch.c @@ -74,7 +74,7 @@ fetchXGet(struct url *URL, struct url_stat *us, char *flags) { int direct; - direct = (flags && strchr(flags, 'd')); + direct = CHECK_FLAG('d'); if (strcasecmp(URL->scheme, SCHEME_FILE) == 0) return fetchXGetFile(URL, us, flags); else if (strcasecmp(URL->scheme, SCHEME_HTTP) == 0) @@ -106,7 +106,7 @@ fetchPut(struct url *URL, char *flags) { int direct; - direct = (flags && strchr(flags, 'd')); + direct = CHECK_FLAG('d'); if (strcasecmp(URL->scheme, SCHEME_FILE) == 0) return fetchPutFile(URL, flags); else if (strcasecmp(URL->scheme, SCHEME_HTTP) == 0) @@ -128,7 +128,7 @@ fetchStat(struct url *URL, struct url_stat *us, char *flags) { int direct; - direct = (flags && strchr(flags, 'd')); + direct = CHECK_FLAG('d'); if (strcasecmp(URL->scheme, SCHEME_FILE) == 0) return fetchStatFile(URL, us, flags); else if (strcasecmp(URL->scheme, SCHEME_HTTP) == 0) @@ -150,7 +150,7 @@ fetchList(struct url *URL, char *flags) { int direct; - direct = (flags && strchr(flags, 'd')); + direct = CHECK_FLAG('d'); if (strcasecmp(URL->scheme, SCHEME_FILE) == 0) return fetchListFile(URL, flags); else if (strcasecmp(URL->scheme, SCHEME_HTTP) == 0) diff --git a/lib/libfetch/file.c b/lib/libfetch/file.c index 7cf6efdb6d0e..5d591432547c 100644 --- a/lib/libfetch/file.c +++ b/lib/libfetch/file.c @@ -70,7 +70,7 @@ fetchPutFile(struct url *u, char *flags) { FILE *f; - if (flags && strchr(flags, 'a')) + if (CHECK_FLAG('a')) f = fopen(u->doc, "a"); else f = fopen(u->doc, "w+"); diff --git a/lib/libfetch/ftp.c b/lib/libfetch/ftp.c index 00b1cf5e1204..18da8b295f63 100644 --- a/lib/libfetch/ftp.c +++ b/lib/libfetch/ftp.c @@ -82,6 +82,7 @@ #define FTP_OK 200 #define FTP_FILE_STATUS 213 #define FTP_SERVICE_READY 220 +#define FTP_TRANSFER_COMPLETE 226 #define FTP_PASSIVE_MODE 227 #define FTP_LPASSIVE_MODE 228 #define FTP_EPASSIVE_MODE 229 @@ -327,6 +328,10 @@ _ftp_readfn(void *v, char *buf, int len) int r; io = (struct ftpio *)v; + if (io == NULL) { + errno = EBADF; + return -1; + } if (io->csd == -1 || io->dsd == -1 || io->dir == O_WRONLY) { errno = EBADF; return -1; @@ -355,6 +360,10 @@ _ftp_writefn(void *v, const char *buf, int len) int w; io = (struct ftpio *)v; + if (io == NULL) { + errno = EBADF; + return -1; + } if (io->csd == -1 || io->dsd == -1 || io->dir == O_RDONLY) { errno = EBADF; return -1; @@ -373,6 +382,13 @@ _ftp_writefn(void *v, const char *buf, int len) static fpos_t _ftp_seekfn(void *v, fpos_t pos, int whence) { + struct ftpio *io; + + io = (struct ftpio *)v; + if (io == NULL) { + errno = EBADF; + return -1; + } errno = ESPIPE; return -1; } @@ -381,8 +397,13 @@ static int _ftp_closefn(void *v) { struct ftpio *io; + int r; io = (struct ftpio *)v; + if (io == NULL) { + errno = EBADF; + return -1; + } if (io->dir == -1) return 0; if (io->csd == -1 || io->dsd == -1) { @@ -393,7 +414,10 @@ _ftp_closefn(void *v) io->dir = -1; io->dsd = -1; DEBUG(fprintf(stderr, "Waiting for final status\n")); - io->err = _ftp_chkerr(io->csd); + if ((r = _ftp_chkerr(io->csd)) != FTP_TRANSFER_COMPLETE) + io->err = r; + else + io->err = 0; close(io->csd); io->csd = -1; return io->err ? -1 : 0; @@ -434,9 +458,9 @@ _ftp_transfer(int cd, char *oper, char *file, FILE *df; /* check flags */ - pasv = (flags && strchr(flags, 'p')); - high = (flags && strchr(flags, 'h')); - verbose = (flags && strchr(flags, 'v')); + pasv = CHECK_FLAG('p'); + high = CHECK_FLAG('h'); + verbose = CHECK_FLAG('v'); /* passive mode */ if (!pasv) @@ -716,11 +740,11 @@ _ftp_connect(struct url *url, struct url *purl, char *flags) char localhost[MAXHOSTNAMELEN]; char pbuf[MAXHOSTNAMELEN + MAXLOGNAME + 1]; - direct = (flags && strchr(flags, 'd')); - verbose = (flags && strchr(flags, 'v')); - if ((flags && strchr(flags, '4'))) + direct = CHECK_FLAG('d'); + verbose = CHECK_FLAG('v'); + if (CHECK_FLAG('4')) af = AF_INET; - else if ((flags && strchr(flags, '6'))) + else if (CHECK_FLAG('6')) af = AF_INET6; if (direct) @@ -887,7 +911,7 @@ fetchXGetFTP(struct url *url, struct url_stat *us, char *flags) int cd; /* get the proxy URL, and check if we should use HTTP instead */ - if (!strchr(flags, 'd') && (purl = _ftp_get_proxy()) != NULL) { + if (!CHECK_FLAG('d') && (purl = _ftp_get_proxy()) != NULL) { if (strcasecmp(purl->scheme, SCHEME_HTTP) == 0) return _http_request(url, "GET", us, purl, flags); } else { @@ -934,7 +958,7 @@ fetchPutFTP(struct url *url, char *flags) int cd; /* get the proxy URL, and check if we should use HTTP instead */ - if (!strchr(flags, 'd') && (purl = _ftp_get_proxy()) != NULL) { + if (!CHECK_FLAG('d') && (purl = _ftp_get_proxy()) != NULL) { if (strcasecmp(purl->scheme, SCHEME_HTTP) == 0) /* XXX HTTP PUT is not implemented, so try without the proxy */ purl = NULL; @@ -954,7 +978,7 @@ fetchPutFTP(struct url *url, char *flags) return NULL; /* initiate the transfer */ - return _ftp_transfer(cd, (flags && strchr(flags, 'a')) ? "APPE" : "STOR", + return _ftp_transfer(cd, CHECK_FLAG('a') ? "APPE" : "STOR", url->doc, O_WRONLY, url->offset, flags); } @@ -968,7 +992,7 @@ fetchStatFTP(struct url *url, struct url_stat *us, char *flags) int cd; /* get the proxy URL, and check if we should use HTTP instead */ - if (!strchr(flags, 'd') && (purl = _ftp_get_proxy()) != NULL) { + if (!CHECK_FLAG('d') && (purl = _ftp_get_proxy()) != NULL) { if (strcasecmp(purl->scheme, SCHEME_HTTP) == 0) { FILE *f; diff --git a/lib/libfetch/http.c b/lib/libfetch/http.c index a386364f6a80..e8d193bf439c 100644 --- a/lib/libfetch/http.c +++ b/lib/libfetch/http.c @@ -640,11 +640,11 @@ _http_connect(struct url *URL, struct url *purl, char *flags) af = AF_INET; #endif - verbose = (flags && strchr(flags, 'v')); - if (flags && strchr(flags, '4')) + verbose = CHECK_FLAG('v'); + if (CHECK_FLAG('4')) af = AF_INET; #ifdef INET6 - else if (flags && strchr(flags, '6')) + else if (CHECK_FLAG('6')) af = AF_INET6; #endif @@ -705,9 +705,9 @@ _http_request(struct url *URL, char *op, struct url_stat *us, char hbuf[MAXHOSTNAMELEN + 1]; #endif - direct = (flags && strchr(flags, 'd')); - noredirect = (flags && strchr(flags, 'A')); - verbose = (flags && strchr(flags, 'v')); + direct = CHECK_FLAG('d'); + noredirect = CHECK_FLAG('A'); + verbose = CHECK_FLAG('v'); if (direct && purl) { fetchFreeURL(purl); |
