summaryrefslogtreecommitdiff
path: root/net/libfetch/files
diff options
context:
space:
mode:
authorjoerg <joerg@pkgsrc.org>2008-10-06 12:58:29 +0000
committerjoerg <joerg@pkgsrc.org>2008-10-06 12:58:29 +0000
commita627d8f327ea78b48a96f6bc280df545f39a9084 (patch)
tree251e154f7a7fbf5e4dd7aa4a8388eeaa893d97ec /net/libfetch/files
parent6635d9bb1ca9574ed959e8e6d8a373fc0ea58208 (diff)
downloadpkgsrc-a627d8f327ea78b48a96f6bc280df545f39a9084.tar.gz
libfetch-2.16:
- only include openssl if the openssl option is present - include arpa/inet.h to get ntohl and friends on older platforms like Interix - use new netdb.h compat code from libnbcompat - include inttypes.h only when present - don't name local variables err, Interix has a symbol like that in default namespace - allow fetch_read to do short read and do more intelligent buffering for header processing; effectively don't do a system call for each byte read
Diffstat (limited to 'net/libfetch/files')
-rw-r--r--net/libfetch/files/common.c57
-rw-r--r--net/libfetch/files/common.h2
-rwxr-xr-xnet/libfetch/files/errlist.sh2
-rw-r--r--net/libfetch/files/fetch.32
-rw-r--r--net/libfetch/files/fetch.c9
-rw-r--r--net/libfetch/files/fetch.h2
-rw-r--r--net/libfetch/files/file.c9
-rw-r--r--net/libfetch/files/ftp.c11
-rw-r--r--net/libfetch/files/ftp.errors2
-rw-r--r--net/libfetch/files/http.c16
-rw-r--r--net/libfetch/files/http.errors2
11 files changed, 78 insertions, 36 deletions
diff --git a/net/libfetch/files/common.c b/net/libfetch/files/common.c
index 07dbb642b00..77060d5ca71 100644
--- a/net/libfetch/files/common.c
+++ b/net/libfetch/files/common.c
@@ -1,4 +1,4 @@
-/* $NetBSD: common.c,v 1.13 2008/05/09 00:39:06 joerg Exp $ */
+/* $NetBSD: common.c,v 1.14 2008/10/06 12:58:29 joerg Exp $ */
/*-
* Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
* Copyright (c) 2008 Joerg Sonnenberger <joerg@NetBSD.org>
@@ -30,17 +30,31 @@
* $FreeBSD: common.c,v 1.53 2007/12/19 00:26:36 des Exp $
*/
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+#ifndef NETBSD
+#include <nbcompat.h>
+#endif
+
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/uio.h>
+#include <arpa/inet.h>
#include <netinet/in.h>
#include <ctype.h>
#include <errno.h>
+#if defined(HAVE_INTTYPES_H) || defined(NETBSD)
#include <inttypes.h>
+#endif
+#ifndef NETBSD
+#include <nbcompat/netdb.h>
+#else
#include <netdb.h>
+#endif
#include <pwd.h>
#include <stdarg.h>
#include <stdlib.h>
@@ -245,13 +259,13 @@ int
fetch_bind(int sd, int af, const char *addr)
{
struct addrinfo hints, *res, *res0;
- int err;
+ int error;
memset(&hints, 0, sizeof(hints));
hints.ai_family = af;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = 0;
- if ((err = getaddrinfo(addr, NULL, &hints, &res0)) != 0)
+ if ((error = getaddrinfo(addr, NULL, &hints, &res0)) != 0)
return (-1);
for (res = res0; res; res = res->ai_next)
if (bind(sd, res->ai_addr, res->ai_addrlen) == 0)
@@ -270,7 +284,7 @@ fetch_connect(const char *host, int port, int af, int verbose)
char pbuf[10];
const char *bindaddr;
struct addrinfo hints, *res, *res0;
- int sd, err;
+ int sd, error;
if (verbose)
fetch_info("looking up %s", host);
@@ -281,8 +295,8 @@ fetch_connect(const char *host, int port, int af, int verbose)
hints.ai_family = af;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = 0;
- if ((err = getaddrinfo(host, pbuf, &hints, &res0)) != 0) {
- netdb_seterr(err);
+ if ((error = getaddrinfo(host, pbuf, &hints, &res0)) != 0) {
+ netdb_seterr(error);
return (NULL);
}
bindaddr = getenv("FETCH_BIND_ADDRESS");
@@ -385,17 +399,19 @@ fetch_read(conn_t *conn, char *buf, size_t len)
{
struct timeval now, timeout, waittv;
fd_set readfds;
- ssize_t rlen, total;
+ ssize_t rlen;
int r;
+ if (len == 0)
+ return 0;
+
if (fetchTimeout) {
FD_ZERO(&readfds);
gettimeofday(&timeout, NULL);
timeout.tv_sec += fetchTimeout;
}
- total = 0;
- while (len > 0) {
+ for (;;) {
while (fetchTimeout && !FD_ISSET(conn->sd, &readfds)) {
FD_SET(conn->sd, &readfds);
gettimeofday(&now, NULL);
@@ -425,18 +441,13 @@ fetch_read(conn_t *conn, char *buf, size_t len)
else
#endif
rlen = read(conn->sd, buf, len);
- if (rlen == 0)
+ if (rlen >= 0)
break;
- if (rlen < 0) {
- if (errno == EINTR && fetchRestartCalls)
- continue;
+
+ if (errno != EINTR || !fetchRestartCalls)
return (-1);
- }
- len -= rlen;
- buf += rlen;
- total += rlen;
}
- return (total);
+ return (rlen);
}
@@ -451,7 +462,7 @@ fetch_getln(conn_t *conn)
char *tmp;
size_t tmpsize;
ssize_t len;
- char c;
+ int done;
if (conn->buf == NULL) {
if ((conn->buf = malloc(MIN_BUF_SIZE)) == NULL) {
@@ -465,12 +476,14 @@ fetch_getln(conn_t *conn)
conn->buflen = 0;
do {
- len = fetch_read(conn, &c, 1);
+ len = fetch_read(conn, conn->buf + conn->buflen,
+ conn->bufsize - conn->buflen);
if (len == -1)
return (-1);
if (len == 0)
break;
- conn->buf[conn->buflen++] = c;
+ done = memchr(conn->buf + conn->buflen, '\n', len) != NULL;
+ conn->buflen += len;
if (conn->buflen == conn->bufsize) {
tmp = conn->buf;
tmpsize = conn->bufsize * 2 + 1;
@@ -481,7 +494,7 @@ fetch_getln(conn_t *conn)
conn->buf = tmp;
conn->bufsize = tmpsize;
}
- } while (c != '\n');
+ } while (!done);
conn->buf[conn->buflen] = '\0';
return (0);
diff --git a/net/libfetch/files/common.h b/net/libfetch/files/common.h
index 6aef138fdf4..97f0be49e7e 100644
--- a/net/libfetch/files/common.h
+++ b/net/libfetch/files/common.h
@@ -1,4 +1,4 @@
-/* $NetBSD: common.h,v 1.8 2008/07/27 13:51:27 joerg Exp $ */
+/* $NetBSD: common.h,v 1.9 2008/10/06 12:58:29 joerg Exp $ */
/*-
* Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
* All rights reserved.
diff --git a/net/libfetch/files/errlist.sh b/net/libfetch/files/errlist.sh
index 673103389e9..84779fe9970 100755
--- a/net/libfetch/files/errlist.sh
+++ b/net/libfetch/files/errlist.sh
@@ -1,5 +1,5 @@
#!/bin/sh
-# $NetBSD: errlist.sh,v 1.1 2008/08/21 15:22:45 joerg Exp $
+# $NetBSD: errlist.sh,v 1.2 2008/10/06 12:58:29 joerg Exp $
printf "static struct fetcherr $1[] = {\n"
while read code type msg; do
diff --git a/net/libfetch/files/fetch.3 b/net/libfetch/files/fetch.3
index 31e79361bb7..c22091b9b21 100644
--- a/net/libfetch/files/fetch.3
+++ b/net/libfetch/files/fetch.3
@@ -24,7 +24,7 @@
.\" SUCH DAMAGE.
.\"
.\" $FreeBSD: fetch.3,v 1.64 2007/12/18 11:03:26 des Exp $
-.\" $NetBSD: fetch.3,v 1.8 2008/04/30 11:43:59 wiz Exp $
+.\" $NetBSD: fetch.3,v 1.9 2008/10/06 12:58:29 joerg Exp $
.\"
.Dd April 25, 2008
.Dt FETCH 3
diff --git a/net/libfetch/files/fetch.c b/net/libfetch/files/fetch.c
index 393dc621243..7f5bf588c18 100644
--- a/net/libfetch/files/fetch.c
+++ b/net/libfetch/files/fetch.c
@@ -1,4 +1,4 @@
-/* $NetBSD: fetch.c,v 1.12 2008/04/26 22:42:49 tnn Exp $ */
+/* $NetBSD: fetch.c,v 1.13 2008/10/06 12:58:29 joerg Exp $ */
/*-
* Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
* Copyright (c) 2008 Joerg Sonnenberger <joerg@NetBSD.org>
@@ -30,6 +30,13 @@
* $FreeBSD: fetch.c,v 1.41 2007/12/19 00:26:36 des Exp $
*/
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+#ifndef NETBSD
+#include <nbcompat.h>
+#endif
+
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
diff --git a/net/libfetch/files/fetch.h b/net/libfetch/files/fetch.h
index 9a7b80cf262..9772306f9e4 100644
--- a/net/libfetch/files/fetch.h
+++ b/net/libfetch/files/fetch.h
@@ -1,4 +1,4 @@
-/* $NetBSD: fetch.h,v 1.11 2008/04/25 19:59:30 joerg Exp $ */
+/* $NetBSD: fetch.h,v 1.12 2008/10/06 12:58:29 joerg Exp $ */
/*-
* Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
* All rights reserved.
diff --git a/net/libfetch/files/file.c b/net/libfetch/files/file.c
index 19aa5493e66..d99e08b42f0 100644
--- a/net/libfetch/files/file.c
+++ b/net/libfetch/files/file.c
@@ -1,4 +1,4 @@
-/* $NetBSD: file.c,v 1.11 2008/04/25 16:25:25 joerg Exp $ */
+/* $NetBSD: file.c,v 1.12 2008/10/06 12:58:29 joerg Exp $ */
/*-
* Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
* Copyright (c) 2008 Joerg Sonnenberger <joerg@NetBSD.org>
@@ -30,6 +30,13 @@
* $FreeBSD: file.c,v 1.18 2007/12/14 10:26:58 des Exp $
*/
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+#ifndef NETBSD
+#include <nbcompat.h>
+#endif
+
#include <sys/stat.h>
#include <dirent.h>
diff --git a/net/libfetch/files/ftp.c b/net/libfetch/files/ftp.c
index 7e324dfc99a..e9fe2de2e5f 100644
--- a/net/libfetch/files/ftp.c
+++ b/net/libfetch/files/ftp.c
@@ -1,4 +1,4 @@
-/* $NetBSD: ftp.c,v 1.22 2008/04/25 16:25:25 joerg Exp $ */
+/* $NetBSD: ftp.c,v 1.23 2008/10/06 12:58:29 joerg Exp $ */
/*-
* Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
* Copyright (c) 2008 Joerg Sonnenberger <joerg@NetBSD.org>
@@ -60,21 +60,28 @@
#if HAVE_CONFIG_H
#include "config.h"
#endif
+#ifndef NETBSD
#include <nbcompat.h>
+#endif
#include <sys/types.h>
#include <sys/socket.h>
+
+#include <arpa/inet.h>
#include <netinet/in.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
+#if defined(HAVE_INTTYPES_H) || defined(NETBSD)
#include <inttypes.h>
-#include <netdb.h>
+#endif
#include <stdarg.h>
#ifndef NETBSD
+#include <nbcompat/netdb.h>
#include <nbcompat/stdio.h>
#else
+#include <netdb.h>
#include <stdio.h>
#endif
#include <stdlib.h>
diff --git a/net/libfetch/files/ftp.errors b/net/libfetch/files/ftp.errors
index 368a8e596ab..e9c4950d388 100644
--- a/net/libfetch/files/ftp.errors
+++ b/net/libfetch/files/ftp.errors
@@ -1,4 +1,4 @@
-# $NetBSD: ftp.errors,v 1.1.1.1 2008/02/07 01:48:22 joerg Exp $
+# $NetBSD: ftp.errors,v 1.2 2008/10/06 12:58:29 joerg Exp $
# $FreeBSD: ftp.errors,v 1.6 2002/10/30 06:06:16 des Exp $
#
# This list is taken from RFC 959.
diff --git a/net/libfetch/files/http.c b/net/libfetch/files/http.c
index e36116f4658..c1df4b8f1ea 100644
--- a/net/libfetch/files/http.c
+++ b/net/libfetch/files/http.c
@@ -1,4 +1,4 @@
-/* $NetBSD: http.c,v 1.19 2008/05/06 17:37:30 joerg Exp $ */
+/* $NetBSD: http.c,v 1.20 2008/10/06 12:58:29 joerg Exp $ */
/*-
* Copyright (c) 2000-2004 Dag-Erling Coïdan Smørgrav
* Copyright (c) 2003 Thomas Klausner <wiz@NetBSD.org>
@@ -71,7 +71,9 @@
#if HAVE_CONFIG_H
#include "config.h"
#endif
+#ifndef NETBSD
#include <nbcompat.h>
+#endif
#include <sys/types.h>
#include <sys/socket.h>
@@ -79,11 +81,12 @@
#include <ctype.h>
#include <errno.h>
#include <locale.h>
-#include <netdb.h>
#include <stdarg.h>
#ifndef NETBSD
+#include <nbcompat/netdb.h>
#include <nbcompat/stdio.h>
#else
+#include <netdb.h>
#include <stdio.h>
#endif
#include <stdlib.h>
@@ -91,6 +94,8 @@
#include <time.h>
#include <unistd.h>
+#include <arpa/inet.h>
+
#include <netinet/in.h>
#include <netinet/tcp.h>
@@ -232,9 +237,12 @@ http_fillbuf(struct httpio *io, size_t len)
if (io->chunksize == 0) {
char endl[2];
+ ssize_t len2;
- if (fetch_read(io->conn, endl, 2) != 2 ||
- endl[0] != '\r' || endl[1] != '\n')
+ len2 = fetch_read(io->conn, endl, 2);
+ if (len2 == 1 && fetch_read(io->conn, endl + 1, 1) != 1)
+ return (-1);
+ if (len2 == -1 || endl[0] != '\r' || endl[1] != '\n')
return (-1);
}
diff --git a/net/libfetch/files/http.errors b/net/libfetch/files/http.errors
index f5487774066..bdf51d0e335 100644
--- a/net/libfetch/files/http.errors
+++ b/net/libfetch/files/http.errors
@@ -1,5 +1,5 @@
# $FreeBSD: http.errors,v 1.5 2001/05/23 18:52:02 des Exp $
-# $NetBSD: http.errors,v 1.1.1.1 2008/02/07 01:48:23 joerg Exp $
+# $NetBSD: http.errors,v 1.2 2008/10/06 12:58:29 joerg Exp $
#
# This list is taken from RFC 2068.
#