Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/external/bsd/fetch/dist/libfetch Import libfetch-2.25:
details: https://anonhg.NetBSD.org/src/rev/c3b800400c8a
branches: trunk
changeset: 746851:c3b800400c8a
user: joerg <joerg%NetBSD.org@localhost>
date: Fri Aug 21 15:12:24 2009 +0000
description:
Import libfetch-2.25:
- address a number of lint warnings
- fix strict-alignment issues for GCC 4.4
- fix a bug in the line reading optimisation
- do not reuse a FTP connection if there is an active transfer on it
diffstat:
external/bsd/fetch/dist/libfetch/common.c | 33 +++++++---
external/bsd/fetch/dist/libfetch/common.h | 3 +-
external/bsd/fetch/dist/libfetch/fetch.c | 10 +---
external/bsd/fetch/dist/libfetch/fetch.cat3 | 8 +-
external/bsd/fetch/dist/libfetch/ftp.c | 84 ++++++++++++++--------------
5 files changed, 72 insertions(+), 66 deletions(-)
diffs (truncated from 420 to 300 lines):
diff -r abbde2704cb9 -r c3b800400c8a external/bsd/fetch/dist/libfetch/common.c
--- a/external/bsd/fetch/dist/libfetch/common.c Fri Aug 21 14:41:22 2009 +0000
+++ b/external/bsd/fetch/dist/libfetch/common.c Fri Aug 21 15:12:24 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: common.c,v 1.1.1.5 2009/04/04 23:26:03 joerg Exp $ */
+/* $NetBSD: common.c,v 1.1.1.6 2009/08/21 15:12:24 joerg Exp $ */
/*-
* Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
* Copyright (c) 2008 Joerg Sonnenberger <joerg%NetBSD.org@localhost>
@@ -237,6 +237,7 @@
conn->next_buf = NULL;
conn->next_len = 0;
conn->sd = sd;
+ conn->is_active = 0;
++conn->ref;
return (conn);
}
@@ -261,17 +262,17 @@
fetch_bind(int sd, int af, const char *addr)
{
struct addrinfo hints, *res, *res0;
- int error;
memset(&hints, 0, sizeof(hints));
hints.ai_family = af;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = 0;
- if ((error = getaddrinfo(addr, NULL, &hints, &res0)) != 0)
+ if (getaddrinfo(addr, NULL, &hints, &res0))
return (-1);
- for (res = res0; res; res = res->ai_next)
+ for (res = res0; res; res = res->ai_next) {
if (bind(sd, res->ai_addr, res->ai_addrlen) == 0)
return (0);
+ }
return (-1);
}
@@ -475,18 +476,22 @@
ssize_t len;
if (conn->buf == NULL) {
- if ((conn->buf = malloc(MIN_BUF_SIZE + 1)) == NULL) {
+ if ((conn->buf = malloc(MIN_BUF_SIZE)) == NULL) {
errno = ENOMEM;
return (-1);
}
conn->bufsize = MIN_BUF_SIZE;
}
- conn->buf[0] = '\0';
conn->buflen = 0;
next = NULL;
do {
+ /*
+ * conn->bufsize != conn->buflen at this point,
+ * so the buffer can be NUL-terminated below for
+ * the case of len == 0.
+ */
len = fetch_read(conn, conn->buf + conn->buflen,
conn->bufsize - conn->buflen);
if (len == -1)
@@ -495,10 +500,13 @@
break;
next = memchr(conn->buf + conn->buflen, '\n', len);
conn->buflen += len;
- if (conn->buflen == conn->bufsize &&
- (next == NULL || next[1] == '\0')) {
+ if (conn->buflen == conn->bufsize && next == NULL) {
tmp = conn->buf;
- tmpsize = conn->bufsize * 2 + 1;
+ tmpsize = conn->bufsize * 2;
+ if (tmpsize < conn->bufsize) {
+ errno = ENOMEM;
+ return (-1);
+ }
if ((tmp = realloc(tmp, tmpsize)) == NULL) {
errno = ENOMEM;
return (-1);
@@ -509,11 +517,14 @@
} while (next == NULL);
if (next != NULL) {
+ *next = '\0';
conn->next_buf = next + 1;
conn->next_len = conn->buflen - (conn->next_buf - conn->buf);
conn->buflen = next - conn->buf;
+ } else {
+ conn->buf[conn->buflen] = '\0';
+ conn->next_len = 0;
}
- conn->buf[conn->buflen] = '\0';
return (0);
}
@@ -614,7 +625,7 @@
fetch_putln(conn_t *conn, const char *str, size_t len)
{
struct iovec iov[2];
- int ret;
+ ssize_t ret;
iov[0].iov_base = DECONST(char *, str);
iov[0].iov_len = len;
diff -r abbde2704cb9 -r c3b800400c8a external/bsd/fetch/dist/libfetch/common.h
--- a/external/bsd/fetch/dist/libfetch/common.h Fri Aug 21 14:41:22 2009 +0000
+++ b/external/bsd/fetch/dist/libfetch/common.h Fri Aug 21 15:12:24 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: common.h,v 1.1.1.4 2009/04/04 23:26:03 joerg Exp $ */
+/* $NetBSD: common.h,v 1.1.1.5 2009/08/21 15:12:24 joerg Exp $ */
/*-
* Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
* All rights reserved.
@@ -72,6 +72,7 @@
# endif
#endif
int ref; /* reference count */
+ int is_active;
};
/* Structure used for error message lists */
diff -r abbde2704cb9 -r c3b800400c8a external/bsd/fetch/dist/libfetch/fetch.c
--- a/external/bsd/fetch/dist/libfetch/fetch.c Fri Aug 21 14:41:22 2009 +0000
+++ b/external/bsd/fetch/dist/libfetch/fetch.c Fri Aug 21 15:12:24 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fetch.c,v 1.1.1.7 2009/04/04 23:26:04 joerg Exp $ */
+/* $NetBSD: fetch.c,v 1.1.1.8 2009/08/21 15:12:27 joerg Exp $ */
/*-
* Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
* Copyright (c) 2008 Joerg Sonnenberger <joerg%NetBSD.org@localhost>
@@ -80,9 +80,7 @@
fetchIO *
fetchXGet(struct url *URL, struct url_stat *us, const char *flags)
{
- int direct;
- direct = CHECK_FLAG('d');
if (us != NULL) {
us->size = -1;
us->atime = us->mtime = 0;
@@ -116,9 +114,7 @@
fetchIO *
fetchPut(struct url *URL, const char *flags)
{
- int direct;
- direct = CHECK_FLAG('d');
if (strcasecmp(URL->scheme, SCHEME_FILE) == 0)
return (fetchPutFile(URL, flags));
else if (strcasecmp(URL->scheme, SCHEME_FTP) == 0)
@@ -138,9 +134,7 @@
int
fetchStat(struct url *URL, struct url_stat *us, const char *flags)
{
- int direct;
- direct = CHECK_FLAG('d');
if (us != NULL) {
us->size = -1;
us->atime = us->mtime = 0;
@@ -165,9 +159,7 @@
fetchList(struct url_list *ue, struct url *URL, const char *pattern,
const char *flags)
{
- int direct;
- direct = CHECK_FLAG('d');
if (strcasecmp(URL->scheme, SCHEME_FILE) == 0)
return (fetchListFile(ue, URL, pattern, flags));
else if (strcasecmp(URL->scheme, SCHEME_FTP) == 0)
diff -r abbde2704cb9 -r c3b800400c8a external/bsd/fetch/dist/libfetch/fetch.cat3
--- a/external/bsd/fetch/dist/libfetch/fetch.cat3 Fri Aug 21 14:41:22 2009 +0000
+++ b/external/bsd/fetch/dist/libfetch/fetch.cat3 Fri Aug 21 15:12:24 2009 +0000
@@ -11,7 +11,7 @@
ffeettcchhSSttrriinnggiiffyyUURRLL, ffeettcchh -- file transfer functions
LLIIBBRRAARRYY
- library ``libfetch''
+ File Transfer Library for URLs (libfetch, -lfetch)
SSYYNNOOPPSSIISS
##iinncclluuddee <<ssttddiioo..hh>>
@@ -129,7 +129,7 @@
Scheme Syntax detailed in RFC 1738. A regular expression which produces
this syntax is:
- <scheme>:(//(<user>(:<pwd>)?@)?<host>(:<port>)?)?/(<document>)?
+ <scheme>:(//(<user>(:<pwd>)?@)?<host>(:<port>)?)?/(<document>)?
If the URL does not seem to begin with a scheme name, it is assumed to be
a local path. Only absolute path names are accepted.
@@ -470,13 +470,13 @@
The ffeettcchh library first appeared in FreeBSD 3.0.
AAUUTTHHOORRSS
- The ffeettcchh library was mostly written by Dag-Erling Sm/orgrav
+ The ffeettcchh library was mostly written by Dag-Erling Smørgrav
<des%FreeBSD.org@localhost> with numerous suggestions from Jordan K. Hubbard
<jkh%FreeBSD.org@localhost>, Eugene Skepner <eu%qub.com@localhost> and other FreeBSD develop-
ers. It replaces the older ffttppiioo library written by Poul-Henning Kamp
<phk%FreeBSD.org@localhost> and Jordan K. Hubbard <jkh%FreeBSD.org@localhost>.
- This manual page was written by Dag-Erling Sm/orgrav <des%FreeBSD.org@localhost>.
+ This manual page was written by Dag-Erling Smørgrav <des%FreeBSD.org@localhost>.
BBUUGGSS
Some parts of the library are not yet implemented. The most notable
diff -r abbde2704cb9 -r c3b800400c8a external/bsd/fetch/dist/libfetch/ftp.c
--- a/external/bsd/fetch/dist/libfetch/ftp.c Fri Aug 21 14:41:22 2009 +0000
+++ b/external/bsd/fetch/dist/libfetch/ftp.c Fri Aug 21 15:12:24 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ftp.c,v 1.1.1.6 2009/04/04 23:26:05 joerg Exp $ */
+/* $NetBSD: ftp.c,v 1.1.1.7 2009/08/21 15:12:52 joerg Exp $ */
/*-
* Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
* Copyright (c) 2008, 2009 Joerg Sonnenberger <joerg%NetBSD.org@localhost>
@@ -584,6 +584,7 @@
}
fetch_close(io->dconn);
io->dir = -1;
+ io->dconn->is_active = 0;
io->dconn = NULL;
r = ftp_chkerr(io->cconn);
if (io->cconn == cached_connection && io->cconn->ref == 1)
@@ -607,6 +608,7 @@
io->dconn = dconn;
io->dir = mode;
io->eof = io->err = 0;
+ io->cconn->is_active = 1;
f = fetchIO_unopen(io, ftp_readfn, ftp_writefn, ftp_closefn);
if (f == NULL)
free(io);
@@ -620,9 +622,12 @@
ftp_transfer(conn_t *conn, const char *oper, const char *file, const char *op_arg,
int mode, off_t offset, const char *flags)
{
- struct sockaddr_storage sa;
- struct sockaddr_in6 *sin6;
- struct sockaddr_in *sin4;
+ union anonymous {
+ struct sockaddr_storage ss;
+ struct sockaddr sa;
+ struct sockaddr_in6 sin6;
+ struct sockaddr_in sin4;
+ } u;
const char *bindaddr;
const char *filename;
int filenamelen, type;
@@ -650,16 +655,16 @@
goto ouch;
/* find our own address, bind, and listen */
- l = sizeof(sa);
- if (getsockname(conn->sd, (struct sockaddr *)&sa, &l) == -1)
+ l = sizeof(u.ss);
+ if (getsockname(conn->sd, &u.sa, &l) == -1)
goto sysouch;
- if (sa.ss_family == AF_INET6)
- unmappedaddr((struct sockaddr_in6 *)&sa, &l);
+ if (u.ss.ss_family == AF_INET6)
+ unmappedaddr(&u.sin6, &l);
retry_mode:
/* open data socket */
- if ((sd = socket(sa.ss_family, SOCK_STREAM, IPPROTO_TCP)) == -1) {
+ if ((sd = socket(u.ss.ss_family, SOCK_STREAM, IPPROTO_TCP)) == -1) {
fetch_syserr();
return (NULL);
}
@@ -673,7 +678,7 @@
/* send PASV command */
if (verbose)
fetch_info("setting passive mode");
- switch (sa.ss_family) {
+ switch (u.ss.ss_family) {
case AF_INET:
if ((e = ftp_cmd(conn, "PASV")) != FTP_PASSIVE_MODE)
goto ouch;
@@ -746,28 +751,26 @@
goto sysouch;
/* construct sockaddr for data socket */
- l = sizeof(sa);
- if (getpeername(conn->sd, (struct sockaddr *)&sa, &l) == -1)
+ l = sizeof(u.ss);
+ if (getpeername(conn->sd, &u.sa, &l) == -1)
goto sysouch;
- if (sa.ss_family == AF_INET6)
- unmappedaddr((struct sockaddr_in6 *)&sa, &l);
- switch (sa.ss_family) {
+ if (u.ss.ss_family == AF_INET6)
+ unmappedaddr(&u.sin6, &l);
+ switch (u.ss.ss_family) {
case AF_INET6:
- sin6 = (struct sockaddr_in6 *)&sa;
if (e == FTP_EPASSIVE_MODE)
- sin6->sin6_port = htons(port);
+ u.sin6.sin6_port = htons(port);
Home |
Main Index |
Thread Index |
Old Index