Reindent, and add parentheses to return statements. Some functions in
ftp.c and http.c now have exceedingly long lines due to deep nesting; this will be corrected by reorganizing the code in a later revision.
This commit is contained in:
parent
076172c5bc
commit
e19e6098b3
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=90267
@ -2,7 +2,7 @@
|
||||
|
||||
MAINTAINER= des@freebsd.org
|
||||
LIB= fetch
|
||||
WARNS?= 2
|
||||
WARNS?= 4
|
||||
CFLAGS+= -I.
|
||||
CFLAGS+= -DINET6
|
||||
SRCS= fetch.c common.c ftp.c http.c file.c \
|
||||
|
@ -53,11 +53,11 @@ __FBSDID("$FreeBSD$");
|
||||
* Error messages for resolver errors
|
||||
*/
|
||||
static struct fetcherr _netdb_errlist[] = {
|
||||
{ EAI_NODATA, FETCH_RESOLV, "Host not found" },
|
||||
{ EAI_AGAIN, FETCH_TEMP, "Transient resolver failure" },
|
||||
{ EAI_FAIL, FETCH_RESOLV, "Non-recoverable resolver failure" },
|
||||
{ EAI_NONAME, FETCH_RESOLV, "No address record" },
|
||||
{ -1, FETCH_UNKNOWN, "Unknown resolver error" }
|
||||
{ EAI_NODATA, FETCH_RESOLV, "Host not found" },
|
||||
{ EAI_AGAIN, FETCH_TEMP, "Transient resolver failure" },
|
||||
{ EAI_FAIL, FETCH_RESOLV, "Non-recoverable resolver failure" },
|
||||
{ EAI_NONAME, FETCH_RESOLV, "No address record" },
|
||||
{ -1, FETCH_UNKNOWN, "Unknown resolver error" }
|
||||
};
|
||||
|
||||
/* End-of-Line */
|
||||
@ -72,9 +72,9 @@ static const char ENDL[2] = "\r\n";
|
||||
static struct fetcherr *
|
||||
_fetch_finderr(struct fetcherr *p, int e)
|
||||
{
|
||||
while (p->num != -1 && p->num != e)
|
||||
p++;
|
||||
return p;
|
||||
while (p->num != -1 && p->num != e)
|
||||
p++;
|
||||
return (p);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -83,9 +83,9 @@ _fetch_finderr(struct fetcherr *p, int e)
|
||||
void
|
||||
_fetch_seterr(struct fetcherr *p, int e)
|
||||
{
|
||||
p = _fetch_finderr(p, e);
|
||||
fetchLastErrCode = p->cat;
|
||||
snprintf(fetchLastErrString, MAXERRSTRING, "%s", p->string);
|
||||
p = _fetch_finderr(p, e);
|
||||
fetchLastErrCode = p->cat;
|
||||
snprintf(fetchLastErrString, MAXERRSTRING, "%s", p->string);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -94,60 +94,57 @@ _fetch_seterr(struct fetcherr *p, int e)
|
||||
void
|
||||
_fetch_syserr(void)
|
||||
{
|
||||
int e;
|
||||
e = errno;
|
||||
|
||||
switch (errno) {
|
||||
case 0:
|
||||
fetchLastErrCode = FETCH_OK;
|
||||
break;
|
||||
case EPERM:
|
||||
case EACCES:
|
||||
case EROFS:
|
||||
case EAUTH:
|
||||
case ENEEDAUTH:
|
||||
fetchLastErrCode = FETCH_AUTH;
|
||||
break;
|
||||
case ENOENT:
|
||||
case EISDIR: /* XXX */
|
||||
fetchLastErrCode = FETCH_UNAVAIL;
|
||||
break;
|
||||
case ENOMEM:
|
||||
fetchLastErrCode = FETCH_MEMORY;
|
||||
break;
|
||||
case EBUSY:
|
||||
case EAGAIN:
|
||||
fetchLastErrCode = FETCH_TEMP;
|
||||
break;
|
||||
case EEXIST:
|
||||
fetchLastErrCode = FETCH_EXISTS;
|
||||
break;
|
||||
case ENOSPC:
|
||||
fetchLastErrCode = FETCH_FULL;
|
||||
break;
|
||||
case EADDRINUSE:
|
||||
case EADDRNOTAVAIL:
|
||||
case ENETDOWN:
|
||||
case ENETUNREACH:
|
||||
case ENETRESET:
|
||||
case EHOSTUNREACH:
|
||||
fetchLastErrCode = FETCH_NETWORK;
|
||||
break;
|
||||
case ECONNABORTED:
|
||||
case ECONNRESET:
|
||||
fetchLastErrCode = FETCH_ABORT;
|
||||
break;
|
||||
case ETIMEDOUT:
|
||||
fetchLastErrCode = FETCH_TIMEOUT;
|
||||
break;
|
||||
case ECONNREFUSED:
|
||||
case EHOSTDOWN:
|
||||
fetchLastErrCode = FETCH_DOWN;
|
||||
break;
|
||||
default:
|
||||
fetchLastErrCode = FETCH_UNKNOWN;
|
||||
}
|
||||
snprintf(fetchLastErrString, MAXERRSTRING, "%s", strerror(e));
|
||||
switch (errno) {
|
||||
case 0:
|
||||
fetchLastErrCode = FETCH_OK;
|
||||
break;
|
||||
case EPERM:
|
||||
case EACCES:
|
||||
case EROFS:
|
||||
case EAUTH:
|
||||
case ENEEDAUTH:
|
||||
fetchLastErrCode = FETCH_AUTH;
|
||||
break;
|
||||
case ENOENT:
|
||||
case EISDIR: /* XXX */
|
||||
fetchLastErrCode = FETCH_UNAVAIL;
|
||||
break;
|
||||
case ENOMEM:
|
||||
fetchLastErrCode = FETCH_MEMORY;
|
||||
break;
|
||||
case EBUSY:
|
||||
case EAGAIN:
|
||||
fetchLastErrCode = FETCH_TEMP;
|
||||
break;
|
||||
case EEXIST:
|
||||
fetchLastErrCode = FETCH_EXISTS;
|
||||
break;
|
||||
case ENOSPC:
|
||||
fetchLastErrCode = FETCH_FULL;
|
||||
break;
|
||||
case EADDRINUSE:
|
||||
case EADDRNOTAVAIL:
|
||||
case ENETDOWN:
|
||||
case ENETUNREACH:
|
||||
case ENETRESET:
|
||||
case EHOSTUNREACH:
|
||||
fetchLastErrCode = FETCH_NETWORK;
|
||||
break;
|
||||
case ECONNABORTED:
|
||||
case ECONNRESET:
|
||||
fetchLastErrCode = FETCH_ABORT;
|
||||
break;
|
||||
case ETIMEDOUT:
|
||||
fetchLastErrCode = FETCH_TIMEOUT;
|
||||
break;
|
||||
case ECONNREFUSED:
|
||||
case EHOSTDOWN:
|
||||
fetchLastErrCode = FETCH_DOWN;
|
||||
break;
|
||||
default:
|
||||
fetchLastErrCode = FETCH_UNKNOWN;
|
||||
}
|
||||
snprintf(fetchLastErrString, MAXERRSTRING, "%s", strerror(errno));
|
||||
}
|
||||
|
||||
|
||||
@ -157,12 +154,12 @@ _fetch_syserr(void)
|
||||
void
|
||||
_fetch_info(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
vfprintf(stderr, fmt, ap);
|
||||
va_end(ap);
|
||||
fputc('\n', stderr);
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
vfprintf(stderr, fmt, ap);
|
||||
va_end(ap);
|
||||
fputc('\n', stderr);
|
||||
}
|
||||
|
||||
|
||||
@ -174,15 +171,15 @@ _fetch_info(const char *fmt, ...)
|
||||
int
|
||||
_fetch_default_port(const char *scheme)
|
||||
{
|
||||
struct servent *se;
|
||||
struct servent *se;
|
||||
|
||||
if ((se = getservbyname(scheme, "tcp")) != NULL)
|
||||
return ntohs(se->s_port);
|
||||
if (strcasecmp(scheme, SCHEME_FTP) == 0)
|
||||
return FTP_DEFAULT_PORT;
|
||||
if (strcasecmp(scheme, SCHEME_HTTP) == 0)
|
||||
return HTTP_DEFAULT_PORT;
|
||||
return 0;
|
||||
if ((se = getservbyname(scheme, "tcp")) != NULL)
|
||||
return (ntohs(se->s_port));
|
||||
if (strcasecmp(scheme, SCHEME_FTP) == 0)
|
||||
return (FTP_DEFAULT_PORT);
|
||||
if (strcasecmp(scheme, SCHEME_HTTP) == 0)
|
||||
return (HTTP_DEFAULT_PORT);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -191,11 +188,11 @@ _fetch_default_port(const char *scheme)
|
||||
int
|
||||
_fetch_default_proxy_port(const char *scheme)
|
||||
{
|
||||
if (strcasecmp(scheme, SCHEME_FTP) == 0)
|
||||
return FTP_DEFAULT_PROXY_PORT;
|
||||
if (strcasecmp(scheme, SCHEME_HTTP) == 0)
|
||||
return HTTP_DEFAULT_PROXY_PORT;
|
||||
return 0;
|
||||
if (strcasecmp(scheme, SCHEME_FTP) == 0)
|
||||
return (FTP_DEFAULT_PROXY_PORT);
|
||||
if (strcasecmp(scheme, SCHEME_HTTP) == 0)
|
||||
return (HTTP_DEFAULT_PROXY_PORT);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -204,46 +201,46 @@ _fetch_default_proxy_port(const char *scheme)
|
||||
int
|
||||
_fetch_connect(const char *host, int port, int af, int verbose)
|
||||
{
|
||||
char pbuf[10];
|
||||
struct addrinfo hints, *res, *res0;
|
||||
int sd, err;
|
||||
char pbuf[10];
|
||||
struct addrinfo hints, *res, *res0;
|
||||
int sd, err;
|
||||
|
||||
DEBUG(fprintf(stderr, "---> %s:%d\n", host, port));
|
||||
DEBUG(fprintf(stderr, "---> %s:%d\n", host, port));
|
||||
|
||||
if (verbose)
|
||||
_fetch_info("looking up %s", host);
|
||||
|
||||
/* look up host name and set up socket address structure */
|
||||
snprintf(pbuf, sizeof(pbuf), "%d", port);
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_family = af;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
hints.ai_protocol = 0;
|
||||
if ((err = getaddrinfo(host, pbuf, &hints, &res0)) != 0) {
|
||||
_netdb_seterr(err);
|
||||
return -1;
|
||||
}
|
||||
if (verbose)
|
||||
_fetch_info("looking up %s", host);
|
||||
|
||||
if (verbose)
|
||||
_fetch_info("connecting to %s:%d", host, port);
|
||||
|
||||
/* try to connect */
|
||||
for (sd = -1, res = res0; res; res = res->ai_next) {
|
||||
if ((sd = socket(res->ai_family, res->ai_socktype,
|
||||
/* look up host name and set up socket address structure */
|
||||
snprintf(pbuf, sizeof(pbuf), "%d", port);
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_family = af;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
hints.ai_protocol = 0;
|
||||
if ((err = getaddrinfo(host, pbuf, &hints, &res0)) != 0) {
|
||||
_netdb_seterr(err);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (verbose)
|
||||
_fetch_info("connecting to %s:%d", host, port);
|
||||
|
||||
/* try to connect */
|
||||
for (sd = -1, res = res0; res; res = res->ai_next) {
|
||||
if ((sd = socket(res->ai_family, res->ai_socktype,
|
||||
res->ai_protocol)) == -1)
|
||||
continue;
|
||||
if (connect(sd, res->ai_addr, res->ai_addrlen) != -1)
|
||||
break;
|
||||
close(sd);
|
||||
sd = -1;
|
||||
}
|
||||
freeaddrinfo(res0);
|
||||
if (sd == -1) {
|
||||
_fetch_syserr();
|
||||
return -1;
|
||||
}
|
||||
continue;
|
||||
if (connect(sd, res->ai_addr, res->ai_addrlen) != -1)
|
||||
break;
|
||||
close(sd);
|
||||
sd = -1;
|
||||
}
|
||||
freeaddrinfo(res0);
|
||||
if (sd == -1) {
|
||||
_fetch_syserr();
|
||||
return (-1);
|
||||
}
|
||||
|
||||
return sd;
|
||||
return (sd);
|
||||
}
|
||||
|
||||
|
||||
@ -255,77 +252,77 @@ _fetch_connect(const char *host, int port, int af, int verbose)
|
||||
int
|
||||
_fetch_getln(int fd, char **buf, size_t *size, size_t *len)
|
||||
{
|
||||
struct timeval now, timeout, wait;
|
||||
fd_set readfds;
|
||||
int r;
|
||||
char c;
|
||||
|
||||
if (*buf == NULL) {
|
||||
if ((*buf = malloc(MIN_BUF_SIZE)) == NULL) {
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
struct timeval now, timeout, wait;
|
||||
fd_set readfds;
|
||||
int r;
|
||||
char c;
|
||||
|
||||
if (*buf == NULL) {
|
||||
if ((*buf = malloc(MIN_BUF_SIZE)) == NULL) {
|
||||
errno = ENOMEM;
|
||||
return (-1);
|
||||
}
|
||||
*size = MIN_BUF_SIZE;
|
||||
}
|
||||
*size = MIN_BUF_SIZE;
|
||||
}
|
||||
|
||||
**buf = '\0';
|
||||
*len = 0;
|
||||
**buf = '\0';
|
||||
*len = 0;
|
||||
|
||||
if (fetchTimeout) {
|
||||
gettimeofday(&timeout, NULL);
|
||||
timeout.tv_sec += fetchTimeout;
|
||||
FD_ZERO(&readfds);
|
||||
}
|
||||
|
||||
do {
|
||||
if (fetchTimeout) {
|
||||
FD_SET(fd, &readfds);
|
||||
gettimeofday(&now, NULL);
|
||||
wait.tv_sec = timeout.tv_sec - now.tv_sec;
|
||||
wait.tv_usec = timeout.tv_usec - now.tv_usec;
|
||||
if (wait.tv_usec < 0) {
|
||||
wait.tv_usec += 1000000;
|
||||
wait.tv_sec--;
|
||||
}
|
||||
if (wait.tv_sec < 0) {
|
||||
errno = ETIMEDOUT;
|
||||
return -1;
|
||||
}
|
||||
r = select(fd+1, &readfds, NULL, NULL, &wait);
|
||||
if (r == -1) {
|
||||
if (errno == EINTR && fetchRestartCalls)
|
||||
continue;
|
||||
/* EBADF or EINVAL: shouldn't happen */
|
||||
return -1;
|
||||
}
|
||||
if (!FD_ISSET(fd, &readfds))
|
||||
continue;
|
||||
gettimeofday(&timeout, NULL);
|
||||
timeout.tv_sec += fetchTimeout;
|
||||
FD_ZERO(&readfds);
|
||||
}
|
||||
r = read(fd, &c, 1);
|
||||
if (r == 0)
|
||||
break;
|
||||
if (r == -1) {
|
||||
if (errno == EINTR && fetchRestartCalls)
|
||||
continue;
|
||||
/* any other error is bad news */
|
||||
return -1;
|
||||
}
|
||||
(*buf)[*len] = c;
|
||||
*len += 1;
|
||||
if (*len == *size) {
|
||||
char *tmp;
|
||||
|
||||
if ((tmp = realloc(*buf, *size * 2 + 1)) == NULL) {
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
*buf = tmp;
|
||||
*size = *size * 2 + 1;
|
||||
}
|
||||
} while (c != '\n');
|
||||
|
||||
DEBUG(fprintf(stderr, "<<< %.*s", (int)*len, *buf));
|
||||
return 0;
|
||||
|
||||
do {
|
||||
if (fetchTimeout) {
|
||||
FD_SET(fd, &readfds);
|
||||
gettimeofday(&now, NULL);
|
||||
wait.tv_sec = timeout.tv_sec - now.tv_sec;
|
||||
wait.tv_usec = timeout.tv_usec - now.tv_usec;
|
||||
if (wait.tv_usec < 0) {
|
||||
wait.tv_usec += 1000000;
|
||||
wait.tv_sec--;
|
||||
}
|
||||
if (wait.tv_sec < 0) {
|
||||
errno = ETIMEDOUT;
|
||||
return (-1);
|
||||
}
|
||||
r = select(fd+1, &readfds, NULL, NULL, &wait);
|
||||
if (r == -1) {
|
||||
if (errno == EINTR && fetchRestartCalls)
|
||||
continue;
|
||||
/* EBADF or EINVAL: shouldn't happen */
|
||||
return (-1);
|
||||
}
|
||||
if (!FD_ISSET(fd, &readfds))
|
||||
continue;
|
||||
}
|
||||
r = read(fd, &c, 1);
|
||||
if (r == 0)
|
||||
break;
|
||||
if (r == -1) {
|
||||
if (errno == EINTR && fetchRestartCalls)
|
||||
continue;
|
||||
/* any other error is bad news */
|
||||
return (-1);
|
||||
}
|
||||
(*buf)[*len] = c;
|
||||
*len += 1;
|
||||
if (*len == *size) {
|
||||
char *tmp;
|
||||
|
||||
if ((tmp = realloc(*buf, *size * 2 + 1)) == NULL) {
|
||||
errno = ENOMEM;
|
||||
return (-1);
|
||||
}
|
||||
*buf = tmp;
|
||||
*size = *size * 2 + 1;
|
||||
}
|
||||
} while (c != '\n');
|
||||
|
||||
DEBUG(fprintf(stderr, "<<< %.*s", (int)*len, *buf));
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
@ -336,20 +333,20 @@ _fetch_getln(int fd, char **buf, size_t *size, size_t *len)
|
||||
int
|
||||
_fetch_putln(int fd, const char *str, size_t len)
|
||||
{
|
||||
struct iovec iov[2];
|
||||
ssize_t wlen;
|
||||
struct iovec iov[2];
|
||||
ssize_t wlen;
|
||||
|
||||
/* XXX should enforce timeout */
|
||||
iov[0].iov_base = (char *)str;
|
||||
iov[0].iov_len = len;
|
||||
iov[1].iov_base = (char *)ENDL;
|
||||
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, ">>> %s\n", str));
|
||||
return 0;
|
||||
/* XXX should enforce timeout */
|
||||
iov[0].iov_base = (char *)str;
|
||||
iov[0].iov_len = len;
|
||||
iov[1].iov_base = (char *)ENDL;
|
||||
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, ">>> %s\n", str));
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
@ -357,39 +354,39 @@ _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 *us)
|
||||
const char *name, struct url_stat *us)
|
||||
{
|
||||
struct url_ent *tmp;
|
||||
struct url_ent *tmp;
|
||||
|
||||
if (*p == NULL) {
|
||||
if (*p == NULL) {
|
||||
#define INITIAL_SIZE 8
|
||||
if ((*p = malloc(INITIAL_SIZE * sizeof **p)) == NULL) {
|
||||
errno = ENOMEM;
|
||||
_fetch_syserr();
|
||||
return -1;
|
||||
}
|
||||
*size = INITIAL_SIZE;
|
||||
*len = 0;
|
||||
if ((*p = malloc(INITIAL_SIZE * sizeof **p)) == NULL) {
|
||||
errno = ENOMEM;
|
||||
_fetch_syserr();
|
||||
return (-1);
|
||||
}
|
||||
*size = INITIAL_SIZE;
|
||||
*len = 0;
|
||||
#undef INITIAL_SIZE
|
||||
}
|
||||
|
||||
if (*len >= *size - 1) {
|
||||
tmp = realloc(*p, *size * 2 * sizeof **p);
|
||||
if (tmp == NULL) {
|
||||
errno = ENOMEM;
|
||||
_fetch_syserr();
|
||||
return -1;
|
||||
}
|
||||
*size *= 2;
|
||||
*p = tmp;
|
||||
}
|
||||
|
||||
tmp = *p + *len;
|
||||
snprintf(tmp->name, PATH_MAX, "%s", name);
|
||||
bcopy(us, &tmp->stat, sizeof *us);
|
||||
if (*len >= *size - 1) {
|
||||
tmp = realloc(*p, *size * 2 * sizeof **p);
|
||||
if (tmp == NULL) {
|
||||
errno = ENOMEM;
|
||||
_fetch_syserr();
|
||||
return (-1);
|
||||
}
|
||||
*size *= 2;
|
||||
*p = tmp;
|
||||
}
|
||||
|
||||
(*len)++;
|
||||
(++tmp)->name[0] = 0;
|
||||
tmp = *p + *len;
|
||||
snprintf(tmp->name, PATH_MAX, "%s", name);
|
||||
bcopy(us, &tmp->stat, sizeof *us);
|
||||
|
||||
return 0;
|
||||
(*len)++;
|
||||
(++tmp)->name[0] = 0;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
@ -38,8 +38,9 @@
|
||||
|
||||
/* Structure used for error message lists */
|
||||
struct fetcherr {
|
||||
const int num, cat;
|
||||
const char *string;
|
||||
const int num;
|
||||
const int cat;
|
||||
const char *string;
|
||||
};
|
||||
|
||||
void _fetch_seterr(struct fetcherr *, int);
|
||||
@ -51,7 +52,7 @@ 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 *);
|
||||
const char *, struct url_stat *);
|
||||
|
||||
#define _ftp_seterr(n) _fetch_seterr(_ftp_errlist, n)
|
||||
#define _http_seterr(n) _fetch_seterr(_http_errlist, n)
|
||||
@ -74,11 +75,9 @@ int _fetch_add_entry(struct url_ent **, int *, int *,
|
||||
* whole lot of trouble.
|
||||
*/
|
||||
FILE *_http_request(struct url *, const char *,
|
||||
struct url_stat *, struct url *,
|
||||
const char *);
|
||||
struct url_stat *, struct url *, const char *);
|
||||
FILE *_ftp_request(struct url *, const char *,
|
||||
struct url_stat *, struct url *,
|
||||
const char *);
|
||||
struct url_stat *, struct url *, const char *);
|
||||
|
||||
/*
|
||||
* Check whether a particular flag is set
|
||||
|
@ -57,10 +57,10 @@ int fetchDebug;
|
||||
#define URL_BAD_SCHEME 2
|
||||
#define URL_BAD_PORT 3
|
||||
static struct fetcherr _url_errlist[] = {
|
||||
{ URL_MALFORMED, FETCH_URL, "Malformed URL" },
|
||||
{ URL_BAD_SCHEME, FETCH_URL, "Invalid URL scheme" },
|
||||
{ URL_BAD_PORT, FETCH_URL, "Invalid server port" },
|
||||
{ -1, FETCH_UNKNOWN, "Unknown parser error" }
|
||||
{ URL_MALFORMED, FETCH_URL, "Malformed URL" },
|
||||
{ URL_BAD_SCHEME, FETCH_URL, "Invalid URL scheme" },
|
||||
{ URL_BAD_PORT, FETCH_URL, "Invalid server port" },
|
||||
{ -1, FETCH_UNKNOWN, "Unknown parser error" }
|
||||
};
|
||||
|
||||
|
||||
@ -74,19 +74,19 @@ static struct fetcherr _url_errlist[] = {
|
||||
FILE *
|
||||
fetchXGet(struct url *URL, struct url_stat *us, const char *flags)
|
||||
{
|
||||
int direct;
|
||||
int direct;
|
||||
|
||||
direct = CHECK_FLAG('d');
|
||||
if (strcasecmp(URL->scheme, SCHEME_FILE) == 0)
|
||||
return fetchXGetFile(URL, us, flags);
|
||||
else if (strcasecmp(URL->scheme, SCHEME_HTTP) == 0)
|
||||
return fetchXGetHTTP(URL, us, flags);
|
||||
else if (strcasecmp(URL->scheme, SCHEME_FTP) == 0) {
|
||||
return fetchXGetFTP(URL, us, flags);
|
||||
} else {
|
||||
_url_seterr(URL_BAD_SCHEME);
|
||||
return NULL;
|
||||
}
|
||||
direct = CHECK_FLAG('d');
|
||||
if (strcasecmp(URL->scheme, SCHEME_FILE) == 0)
|
||||
return (fetchXGetFile(URL, us, flags));
|
||||
else if (strcasecmp(URL->scheme, SCHEME_HTTP) == 0)
|
||||
return (fetchXGetHTTP(URL, us, flags));
|
||||
else if (strcasecmp(URL->scheme, SCHEME_FTP) == 0) {
|
||||
return (fetchXGetFTP(URL, us, flags));
|
||||
} else {
|
||||
_url_seterr(URL_BAD_SCHEME);
|
||||
return (NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@ -96,7 +96,7 @@ fetchXGet(struct url *URL, struct url_stat *us, const char *flags)
|
||||
FILE *
|
||||
fetchGet(struct url *URL, const char *flags)
|
||||
{
|
||||
return fetchXGet(URL, NULL, flags);
|
||||
return (fetchXGet(URL, NULL, flags));
|
||||
}
|
||||
|
||||
/*
|
||||
@ -106,19 +106,19 @@ fetchGet(struct url *URL, const char *flags)
|
||||
FILE *
|
||||
fetchPut(struct url *URL, const char *flags)
|
||||
{
|
||||
int direct;
|
||||
int direct;
|
||||
|
||||
direct = CHECK_FLAG('d');
|
||||
if (strcasecmp(URL->scheme, SCHEME_FILE) == 0)
|
||||
return fetchPutFile(URL, flags);
|
||||
else if (strcasecmp(URL->scheme, SCHEME_HTTP) == 0)
|
||||
return fetchPutHTTP(URL, flags);
|
||||
else if (strcasecmp(URL->scheme, SCHEME_FTP) == 0) {
|
||||
return fetchPutFTP(URL, flags);
|
||||
} else {
|
||||
_url_seterr(URL_BAD_SCHEME);
|
||||
return NULL;
|
||||
}
|
||||
direct = CHECK_FLAG('d');
|
||||
if (strcasecmp(URL->scheme, SCHEME_FILE) == 0)
|
||||
return (fetchPutFile(URL, flags));
|
||||
else if (strcasecmp(URL->scheme, SCHEME_HTTP) == 0)
|
||||
return (fetchPutHTTP(URL, flags));
|
||||
else if (strcasecmp(URL->scheme, SCHEME_FTP) == 0) {
|
||||
return (fetchPutFTP(URL, flags));
|
||||
} else {
|
||||
_url_seterr(URL_BAD_SCHEME);
|
||||
return (NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@ -128,19 +128,17 @@ fetchPut(struct url *URL, const char *flags)
|
||||
int
|
||||
fetchStat(struct url *URL, struct url_stat *us, const char *flags)
|
||||
{
|
||||
int direct;
|
||||
int direct;
|
||||
|
||||
direct = CHECK_FLAG('d');
|
||||
if (strcasecmp(URL->scheme, SCHEME_FILE) == 0)
|
||||
return fetchStatFile(URL, us, flags);
|
||||
else if (strcasecmp(URL->scheme, SCHEME_HTTP) == 0)
|
||||
return fetchStatHTTP(URL, us, flags);
|
||||
else if (strcasecmp(URL->scheme, SCHEME_FTP) == 0) {
|
||||
return fetchStatFTP(URL, us, flags);
|
||||
} else {
|
||||
direct = CHECK_FLAG('d');
|
||||
if (strcasecmp(URL->scheme, SCHEME_FILE) == 0)
|
||||
return (fetchStatFile(URL, us, flags));
|
||||
else if (strcasecmp(URL->scheme, SCHEME_HTTP) == 0)
|
||||
return (fetchStatHTTP(URL, us, flags));
|
||||
else if (strcasecmp(URL->scheme, SCHEME_FTP) == 0)
|
||||
return (fetchStatFTP(URL, us, flags));
|
||||
_url_seterr(URL_BAD_SCHEME);
|
||||
return -1;
|
||||
}
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -150,19 +148,17 @@ fetchStat(struct url *URL, struct url_stat *us, const char *flags)
|
||||
struct url_ent *
|
||||
fetchList(struct url *URL, const char *flags)
|
||||
{
|
||||
int direct;
|
||||
int direct;
|
||||
|
||||
direct = CHECK_FLAG('d');
|
||||
if (strcasecmp(URL->scheme, SCHEME_FILE) == 0)
|
||||
return fetchListFile(URL, flags);
|
||||
else if (strcasecmp(URL->scheme, SCHEME_HTTP) == 0)
|
||||
return fetchListHTTP(URL, flags);
|
||||
else if (strcasecmp(URL->scheme, SCHEME_FTP) == 0) {
|
||||
return fetchListFTP(URL, flags);
|
||||
} else {
|
||||
direct = CHECK_FLAG('d');
|
||||
if (strcasecmp(URL->scheme, SCHEME_FILE) == 0)
|
||||
return (fetchListFile(URL, flags));
|
||||
else if (strcasecmp(URL->scheme, SCHEME_HTTP) == 0)
|
||||
return (fetchListHTTP(URL, flags));
|
||||
else if (strcasecmp(URL->scheme, SCHEME_FTP) == 0)
|
||||
return (fetchListFTP(URL, flags));
|
||||
_url_seterr(URL_BAD_SCHEME);
|
||||
return NULL;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -171,16 +167,16 @@ fetchList(struct url *URL, const char *flags)
|
||||
FILE *
|
||||
fetchXGetURL(const char *URL, struct url_stat *us, const char *flags)
|
||||
{
|
||||
struct url *u;
|
||||
FILE *f;
|
||||
struct url *u;
|
||||
FILE *f;
|
||||
|
||||
if ((u = fetchParseURL(URL)) == NULL)
|
||||
return NULL;
|
||||
|
||||
f = fetchXGet(u, us, flags);
|
||||
|
||||
fetchFreeURL(u);
|
||||
return f;
|
||||
if ((u = fetchParseURL(URL)) == NULL)
|
||||
return (NULL);
|
||||
|
||||
f = fetchXGet(u, us, flags);
|
||||
|
||||
fetchFreeURL(u);
|
||||
return (f);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -189,7 +185,7 @@ fetchXGetURL(const char *URL, struct url_stat *us, const char *flags)
|
||||
FILE *
|
||||
fetchGetURL(const char *URL, const char *flags)
|
||||
{
|
||||
return fetchXGetURL(URL, NULL, flags);
|
||||
return (fetchXGetURL(URL, NULL, flags));
|
||||
}
|
||||
|
||||
/*
|
||||
@ -198,16 +194,16 @@ fetchGetURL(const char *URL, const char *flags)
|
||||
FILE *
|
||||
fetchPutURL(const char *URL, const char *flags)
|
||||
{
|
||||
struct url *u;
|
||||
FILE *f;
|
||||
|
||||
if ((u = fetchParseURL(URL)) == NULL)
|
||||
return NULL;
|
||||
|
||||
f = fetchPut(u, flags);
|
||||
|
||||
fetchFreeURL(u);
|
||||
return f;
|
||||
struct url *u;
|
||||
FILE *f;
|
||||
|
||||
if ((u = fetchParseURL(URL)) == NULL)
|
||||
return (NULL);
|
||||
|
||||
f = fetchPut(u, flags);
|
||||
|
||||
fetchFreeURL(u);
|
||||
return (f);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -216,16 +212,16 @@ fetchPutURL(const char *URL, const char *flags)
|
||||
int
|
||||
fetchStatURL(const char *URL, struct url_stat *us, const char *flags)
|
||||
{
|
||||
struct url *u;
|
||||
int s;
|
||||
struct url *u;
|
||||
int s;
|
||||
|
||||
if ((u = fetchParseURL(URL)) == NULL)
|
||||
return -1;
|
||||
if ((u = fetchParseURL(URL)) == NULL)
|
||||
return (-1);
|
||||
|
||||
s = fetchStat(u, us, flags);
|
||||
s = fetchStat(u, us, flags);
|
||||
|
||||
fetchFreeURL(u);
|
||||
return s;
|
||||
fetchFreeURL(u);
|
||||
return (s);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -234,16 +230,16 @@ fetchStatURL(const char *URL, struct url_stat *us, const char *flags)
|
||||
struct url_ent *
|
||||
fetchListURL(const char *URL, const char *flags)
|
||||
{
|
||||
struct url *u;
|
||||
struct url_ent *ue;
|
||||
struct url *u;
|
||||
struct url_ent *ue;
|
||||
|
||||
if ((u = fetchParseURL(URL)) == NULL)
|
||||
return NULL;
|
||||
if ((u = fetchParseURL(URL)) == NULL)
|
||||
return (NULL);
|
||||
|
||||
ue = fetchList(u, flags);
|
||||
ue = fetchList(u, flags);
|
||||
|
||||
fetchFreeURL(u);
|
||||
return ue;
|
||||
fetchFreeURL(u);
|
||||
return (ue);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -253,39 +249,39 @@ struct url *
|
||||
fetchMakeURL(const char *scheme, const char *host, int port, const char *doc,
|
||||
const char *user, const char *pwd)
|
||||
{
|
||||
struct url *u;
|
||||
struct url *u;
|
||||
|
||||
if (!scheme || (!host && !doc)) {
|
||||
_url_seterr(URL_MALFORMED);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (port < 0 || port > 65535) {
|
||||
_url_seterr(URL_BAD_PORT);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* allocate struct url */
|
||||
if ((u = calloc(1, sizeof *u)) == NULL) {
|
||||
_fetch_syserr();
|
||||
return NULL;
|
||||
}
|
||||
if (!scheme || (!host && !doc)) {
|
||||
_url_seterr(URL_MALFORMED);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
if (port < 0 || port > 65535) {
|
||||
_url_seterr(URL_BAD_PORT);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/* allocate struct url */
|
||||
if ((u = calloc(1, sizeof *u)) == NULL) {
|
||||
_fetch_syserr();
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
if ((u->doc = strdup(doc ? doc : "/")) == NULL) {
|
||||
_fetch_syserr();
|
||||
free(u);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
if ((u->doc = strdup(doc ? doc : "/")) == NULL) {
|
||||
_fetch_syserr();
|
||||
free(u);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#define seturl(x) snprintf(u->x, sizeof u->x, "%s", x)
|
||||
seturl(scheme);
|
||||
seturl(host);
|
||||
seturl(user);
|
||||
seturl(pwd);
|
||||
seturl(scheme);
|
||||
seturl(host);
|
||||
seturl(user);
|
||||
seturl(pwd);
|
||||
#undef seturl
|
||||
u->port = port;
|
||||
u->port = port;
|
||||
|
||||
return u;
|
||||
return (u);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -296,112 +292,113 @@ fetchMakeURL(const char *scheme, const char *host, int port, const char *doc,
|
||||
struct url *
|
||||
fetchParseURL(const char *URL)
|
||||
{
|
||||
char *doc;
|
||||
const char *p, *q;
|
||||
struct url *u;
|
||||
int i;
|
||||
char *doc;
|
||||
const char *p, *q;
|
||||
struct url *u;
|
||||
int i;
|
||||
|
||||
/* allocate struct url */
|
||||
if ((u = calloc(1, sizeof *u)) == NULL) {
|
||||
_fetch_syserr();
|
||||
return NULL;
|
||||
}
|
||||
/* allocate struct url */
|
||||
if ((u = calloc(1, sizeof *u)) == NULL) {
|
||||
_fetch_syserr();
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/* scheme name */
|
||||
if ((p = strstr(URL, ":/"))) {
|
||||
snprintf(u->scheme, URL_SCHEMELEN+1, "%.*s", (int)(p - URL), URL);
|
||||
URL = ++p;
|
||||
/*
|
||||
* Only one slash: no host, leave slash as part of document
|
||||
* Two slashes: host follows, strip slashes
|
||||
*/
|
||||
if (URL[1] == '/')
|
||||
URL = (p += 2);
|
||||
} else {
|
||||
p = URL;
|
||||
}
|
||||
if (!*URL || *URL == '/' || *URL == '.' ||
|
||||
(u->scheme[0] == '\0' &&
|
||||
strchr(URL, '/') == NULL && strchr(URL, ':') == NULL))
|
||||
goto nohost;
|
||||
/* scheme name */
|
||||
if ((p = strstr(URL, ":/"))) {
|
||||
snprintf(u->scheme, URL_SCHEMELEN+1,
|
||||
"%.*s", (int)(p - URL), URL);
|
||||
URL = ++p;
|
||||
/*
|
||||
* Only one slash: no host, leave slash as part of document
|
||||
* Two slashes: host follows, strip slashes
|
||||
*/
|
||||
if (URL[1] == '/')
|
||||
URL = (p += 2);
|
||||
} else {
|
||||
p = URL;
|
||||
}
|
||||
if (!*URL || *URL == '/' || *URL == '.' ||
|
||||
(u->scheme[0] == '\0' &&
|
||||
strchr(URL, '/') == NULL && strchr(URL, ':') == NULL))
|
||||
goto nohost;
|
||||
|
||||
p = strpbrk(URL, "/@");
|
||||
if (p && *p == '@') {
|
||||
/* username */
|
||||
for (q = URL, i = 0; (*q != ':') && (*q != '@'); q++)
|
||||
if (i < URL_USERLEN)
|
||||
u->user[i++] = *q;
|
||||
|
||||
/* password */
|
||||
if (*q == ':')
|
||||
for (q++, i = 0; (*q != ':') && (*q != '@'); q++)
|
||||
if (i < URL_PWDLEN)
|
||||
u->pwd[i++] = *q;
|
||||
|
||||
p++;
|
||||
} else {
|
||||
p = URL;
|
||||
}
|
||||
p = strpbrk(URL, "/@");
|
||||
if (p && *p == '@') {
|
||||
/* username */
|
||||
for (q = URL, i = 0; (*q != ':') && (*q != '@'); q++)
|
||||
if (i < URL_USERLEN)
|
||||
u->user[i++] = *q;
|
||||
|
||||
/* hostname */
|
||||
/* password */
|
||||
if (*q == ':')
|
||||
for (q++, i = 0; (*q != ':') && (*q != '@'); q++)
|
||||
if (i < URL_PWDLEN)
|
||||
u->pwd[i++] = *q;
|
||||
|
||||
p++;
|
||||
} else {
|
||||
p = URL;
|
||||
}
|
||||
|
||||
/* hostname */
|
||||
#ifdef INET6
|
||||
if (*p == '[' && (q = strchr(p + 1, ']')) != NULL &&
|
||||
(*++q == '\0' || *q == '/' || *q == ':')) {
|
||||
if ((i = q - p - 2) > MAXHOSTNAMELEN)
|
||||
i = MAXHOSTNAMELEN;
|
||||
strncpy(u->host, ++p, i);
|
||||
p = q;
|
||||
} else
|
||||
if (*p == '[' && (q = strchr(p + 1, ']')) != NULL &&
|
||||
(*++q == '\0' || *q == '/' || *q == ':')) {
|
||||
if ((i = q - p - 2) > MAXHOSTNAMELEN)
|
||||
i = MAXHOSTNAMELEN;
|
||||
strncpy(u->host, ++p, i);
|
||||
p = q;
|
||||
} else
|
||||
#endif
|
||||
for (i = 0; *p && (*p != '/') && (*p != ':'); p++)
|
||||
if (i < MAXHOSTNAMELEN)
|
||||
u->host[i++] = *p;
|
||||
for (i = 0; *p && (*p != '/') && (*p != ':'); p++)
|
||||
if (i < MAXHOSTNAMELEN)
|
||||
u->host[i++] = *p;
|
||||
|
||||
/* port */
|
||||
if (*p == ':') {
|
||||
for (q = ++p; *q && (*q != '/'); q++)
|
||||
if (isdigit(*q))
|
||||
u->port = u->port * 10 + (*q - '0');
|
||||
else {
|
||||
/* invalid port */
|
||||
_url_seterr(URL_BAD_PORT);
|
||||
goto ouch;
|
||||
}
|
||||
p = q;
|
||||
}
|
||||
/* port */
|
||||
if (*p == ':') {
|
||||
for (q = ++p; *q && (*q != '/'); q++)
|
||||
if (isdigit(*q))
|
||||
u->port = u->port * 10 + (*q - '0');
|
||||
else {
|
||||
/* invalid port */
|
||||
_url_seterr(URL_BAD_PORT);
|
||||
goto ouch;
|
||||
}
|
||||
p = q;
|
||||
}
|
||||
|
||||
nohost:
|
||||
/* document */
|
||||
if (!*p)
|
||||
p = "/";
|
||||
|
||||
if (strcasecmp(u->scheme, SCHEME_HTTP) == 0 ||
|
||||
strcasecmp(u->scheme, SCHEME_HTTPS) == 0) {
|
||||
const char hexnums[] = "0123456789abcdef";
|
||||
/* document */
|
||||
if (!*p)
|
||||
p = "/";
|
||||
|
||||
/* percent-escape whitespace. */
|
||||
if ((doc = malloc(strlen(p) * 3 + 1)) == NULL) {
|
||||
_fetch_syserr();
|
||||
goto ouch;
|
||||
if (strcasecmp(u->scheme, SCHEME_HTTP) == 0 ||
|
||||
strcasecmp(u->scheme, SCHEME_HTTPS) == 0) {
|
||||
const char hexnums[] = "0123456789abcdef";
|
||||
|
||||
/* percent-escape whitespace. */
|
||||
if ((doc = malloc(strlen(p) * 3 + 1)) == NULL) {
|
||||
_fetch_syserr();
|
||||
goto ouch;
|
||||
}
|
||||
u->doc = doc;
|
||||
while (*p != '\0') {
|
||||
if (!isspace(*p)) {
|
||||
*doc++ = *p++;
|
||||
} else {
|
||||
*doc++ = '%';
|
||||
*doc++ = hexnums[((unsigned int)*p) >> 4];
|
||||
*doc++ = hexnums[((unsigned int)*p) & 0xf];
|
||||
p++;
|
||||
}
|
||||
}
|
||||
*doc = '\0';
|
||||
} else if ((u->doc = strdup(p)) == NULL) {
|
||||
_fetch_syserr();
|
||||
goto ouch;
|
||||
}
|
||||
u->doc = doc;
|
||||
while (*p != '\0') {
|
||||
if (!isspace(*p)) {
|
||||
*doc++ = *p++;
|
||||
} else {
|
||||
*doc++ = '%';
|
||||
*doc++ = hexnums[((unsigned int)*p) >> 4];
|
||||
*doc++ = hexnums[((unsigned int)*p) & 0xf];
|
||||
p++;
|
||||
}
|
||||
}
|
||||
*doc = '\0';
|
||||
} else if ((u->doc = strdup(p)) == NULL) {
|
||||
_fetch_syserr();
|
||||
goto ouch;
|
||||
}
|
||||
|
||||
DEBUG(fprintf(stderr,
|
||||
|
||||
DEBUG(fprintf(stderr,
|
||||
"scheme: [%s]\n"
|
||||
"user: [%s]\n"
|
||||
"password: [%s]\n"
|
||||
@ -410,12 +407,12 @@ fetchParseURL(const char *URL)
|
||||
"document: [%s]\n",
|
||||
u->scheme, u->user, u->pwd,
|
||||
u->host, u->port, u->doc));
|
||||
|
||||
return u;
|
||||
|
||||
return (u);
|
||||
|
||||
ouch:
|
||||
free(u);
|
||||
return NULL;
|
||||
free(u);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -424,6 +421,6 @@ fetchParseURL(const char *URL)
|
||||
void
|
||||
fetchFreeURL(struct url *u)
|
||||
{
|
||||
free(u->doc);
|
||||
free(u);
|
||||
free(u->doc);
|
||||
free(u);
|
||||
}
|
||||
|
@ -38,25 +38,25 @@
|
||||
#define URL_PWDLEN 256
|
||||
|
||||
struct url {
|
||||
char scheme[URL_SCHEMELEN+1];
|
||||
char user[URL_USERLEN+1];
|
||||
char pwd[URL_PWDLEN+1];
|
||||
char host[MAXHOSTNAMELEN+1];
|
||||
int port;
|
||||
char *doc;
|
||||
off_t offset;
|
||||
size_t length;
|
||||
char scheme[URL_SCHEMELEN+1];
|
||||
char user[URL_USERLEN+1];
|
||||
char pwd[URL_PWDLEN+1];
|
||||
char host[MAXHOSTNAMELEN+1];
|
||||
int port;
|
||||
char *doc;
|
||||
off_t offset;
|
||||
size_t length;
|
||||
};
|
||||
|
||||
struct url_stat {
|
||||
off_t size;
|
||||
time_t atime;
|
||||
time_t mtime;
|
||||
off_t size;
|
||||
time_t atime;
|
||||
time_t mtime;
|
||||
};
|
||||
|
||||
struct url_ent {
|
||||
char name[PATH_MAX];
|
||||
struct url_stat stat;
|
||||
char name[PATH_MAX];
|
||||
struct url_stat stat;
|
||||
};
|
||||
|
||||
/* Recognized schemes */
|
||||
@ -121,22 +121,26 @@ struct url_ent *fetchList(struct url *, const char *);
|
||||
|
||||
/* URL parsing */
|
||||
struct url *fetchMakeURL(const char *, const char *, int,
|
||||
const char *, const char *, const char *);
|
||||
const char *, const char *, const char *);
|
||||
struct url *fetchParseURL(const char *);
|
||||
void fetchFreeURL(struct url *);
|
||||
|
||||
/* Authentication */
|
||||
typedef int (*auth_t)(struct url *);
|
||||
extern auth_t fetchAuthMethod;
|
||||
extern auth_t fetchAuthMethod;
|
||||
|
||||
/* Last error code */
|
||||
extern int fetchLastErrCode;
|
||||
extern int fetchLastErrCode;
|
||||
#define MAXERRSTRING 256
|
||||
extern char fetchLastErrString[MAXERRSTRING];
|
||||
extern int fetchTimeout;
|
||||
extern int fetchRestartCalls;
|
||||
extern char fetchLastErrString[MAXERRSTRING];
|
||||
|
||||
/* I/O timeout */
|
||||
extern int fetchTimeout;
|
||||
|
||||
/* Restart interrupted syscalls */
|
||||
extern int fetchRestartCalls;
|
||||
|
||||
/* Extra verbosity */
|
||||
extern int fetchDebug;
|
||||
extern int fetchDebug;
|
||||
|
||||
#endif
|
||||
|
@ -42,105 +42,105 @@ __FBSDID("$FreeBSD$");
|
||||
FILE *
|
||||
fetchXGetFile(struct url *u, struct url_stat *us, const char *flags)
|
||||
{
|
||||
FILE *f;
|
||||
|
||||
if (us && fetchStatFile(u, us, flags) == -1)
|
||||
return NULL;
|
||||
|
||||
f = fopen(u->doc, "r");
|
||||
|
||||
if (f == NULL)
|
||||
_fetch_syserr();
|
||||
FILE *f;
|
||||
|
||||
if (u->offset && fseeko(f, u->offset, SEEK_SET) == -1) {
|
||||
fclose(f);
|
||||
_fetch_syserr();
|
||||
}
|
||||
|
||||
return f;
|
||||
if (us && fetchStatFile(u, us, flags) == -1)
|
||||
return (NULL);
|
||||
|
||||
f = fopen(u->doc, "r");
|
||||
|
||||
if (f == NULL)
|
||||
_fetch_syserr();
|
||||
|
||||
if (u->offset && fseeko(f, u->offset, SEEK_SET) == -1) {
|
||||
fclose(f);
|
||||
_fetch_syserr();
|
||||
}
|
||||
|
||||
return (f);
|
||||
}
|
||||
|
||||
FILE *
|
||||
fetchGetFile(struct url *u, const char *flags)
|
||||
{
|
||||
return fetchXGetFile(u, NULL, flags);
|
||||
return (fetchXGetFile(u, NULL, flags));
|
||||
}
|
||||
|
||||
FILE *
|
||||
fetchPutFile(struct url *u, const char *flags)
|
||||
{
|
||||
FILE *f;
|
||||
|
||||
if (CHECK_FLAG('a'))
|
||||
f = fopen(u->doc, "a");
|
||||
else
|
||||
f = fopen(u->doc, "w+");
|
||||
|
||||
if (f == NULL)
|
||||
_fetch_syserr();
|
||||
|
||||
if (u->offset && fseeko(f, u->offset, SEEK_SET) == -1) {
|
||||
fclose(f);
|
||||
_fetch_syserr();
|
||||
}
|
||||
|
||||
return f;
|
||||
FILE *f;
|
||||
|
||||
if (CHECK_FLAG('a'))
|
||||
f = fopen(u->doc, "a");
|
||||
else
|
||||
f = fopen(u->doc, "w+");
|
||||
|
||||
if (f == NULL)
|
||||
_fetch_syserr();
|
||||
|
||||
if (u->offset && fseeko(f, u->offset, SEEK_SET) == -1) {
|
||||
fclose(f);
|
||||
_fetch_syserr();
|
||||
}
|
||||
|
||||
return (f);
|
||||
}
|
||||
|
||||
static int
|
||||
_fetch_stat_file(const char *fn, struct url_stat *us)
|
||||
{
|
||||
struct stat sb;
|
||||
struct stat sb;
|
||||
|
||||
us->size = -1;
|
||||
us->atime = us->mtime = 0;
|
||||
if (stat(fn, &sb) == -1) {
|
||||
_fetch_syserr();
|
||||
return -1;
|
||||
}
|
||||
us->size = sb.st_size;
|
||||
us->atime = sb.st_atime;
|
||||
us->mtime = sb.st_mtime;
|
||||
return 0;
|
||||
us->size = -1;
|
||||
us->atime = us->mtime = 0;
|
||||
if (stat(fn, &sb) == -1) {
|
||||
_fetch_syserr();
|
||||
return (-1);
|
||||
}
|
||||
us->size = sb.st_size;
|
||||
us->atime = sb.st_atime;
|
||||
us->mtime = sb.st_mtime;
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
fetchStatFile(struct url *u, struct url_stat *us, const char *flags __unused)
|
||||
{
|
||||
return _fetch_stat_file(u->doc, us);
|
||||
return (_fetch_stat_file(u->doc, us));
|
||||
}
|
||||
|
||||
struct url_ent *
|
||||
fetchListFile(struct url *u, const char *flags __unused)
|
||||
{
|
||||
DIR *dir;
|
||||
struct dirent *de;
|
||||
struct url_stat us;
|
||||
struct url_ent *ue;
|
||||
int size, len;
|
||||
char fn[PATH_MAX], *p;
|
||||
int l;
|
||||
struct dirent *de;
|
||||
struct url_stat us;
|
||||
struct url_ent *ue;
|
||||
int size, len;
|
||||
char fn[PATH_MAX], *p;
|
||||
DIR *dir;
|
||||
int l;
|
||||
|
||||
if ((dir = opendir(u->doc)) == NULL) {
|
||||
_fetch_syserr();
|
||||
return NULL;
|
||||
}
|
||||
if ((dir = opendir(u->doc)) == NULL) {
|
||||
_fetch_syserr();
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
ue = NULL;
|
||||
strncpy(fn, u->doc, sizeof fn - 2);
|
||||
fn[sizeof fn - 2] = 0;
|
||||
strcat(fn, "/");
|
||||
p = strchr(fn, 0);
|
||||
l = sizeof fn - strlen(fn) - 1;
|
||||
|
||||
while ((de = readdir(dir)) != NULL) {
|
||||
strncpy(p, de->d_name, l - 1);
|
||||
p[l - 1] = 0;
|
||||
if (_fetch_stat_file(fn, &us) == -1)
|
||||
/* should I return a partial result, or abort? */
|
||||
break;
|
||||
_fetch_add_entry(&ue, &size, &len, de->d_name, &us);
|
||||
}
|
||||
|
||||
return ue;
|
||||
ue = NULL;
|
||||
strncpy(fn, u->doc, sizeof fn - 2);
|
||||
fn[sizeof fn - 2] = 0;
|
||||
strcat(fn, "/");
|
||||
p = strchr(fn, 0);
|
||||
l = sizeof fn - strlen(fn) - 1;
|
||||
|
||||
while ((de = readdir(dir)) != NULL) {
|
||||
strncpy(p, de->d_name, l - 1);
|
||||
p[l - 1] = 0;
|
||||
if (_fetch_stat_file(fn, &us) == -1)
|
||||
/* should I return a partial result, or abort? */
|
||||
break;
|
||||
_fetch_add_entry(&ue, &size, &len, de->d_name, &us);
|
||||
}
|
||||
|
||||
return (ue);
|
||||
}
|
||||
|
1337
lib/libfetch/ftp.c
1337
lib/libfetch/ftp.c
File diff suppressed because it is too large
Load Diff
1444
lib/libfetch/http.c
1444
lib/libfetch/http.c
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user