pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/net/libfetch libfetch-2.29:



details:   https://anonhg.NetBSD.org/pkgsrc/rev/3efe637c3635
branches:  trunk
changeset: 570027:3efe637c3635
user:      joerg <joerg%pkgsrc.org@localhost>
date:      Sat Jan 23 14:25:26 2010 +0000

description:
libfetch-2.29:
Push \r\n up to the users of fetch_putln and remove it. Use send instead
of write(v) to avoid SIGPIPE.

diffstat:

 net/libfetch/Makefile       |   4 +-
 net/libfetch/files/common.c |  66 ++++----------------------------------------
 net/libfetch/files/common.h |   9 +----
 net/libfetch/files/ftp.c    |  58 +++++++++++++++++++-------------------
 net/libfetch/files/http.c   |  28 +++++++++---------
 5 files changed, 54 insertions(+), 111 deletions(-)

diffs (truncated from 476 to 300 lines):

diff -r 5d41de1a6cc6 -r 3efe637c3635 net/libfetch/Makefile
--- a/net/libfetch/Makefile     Sat Jan 23 13:39:42 2010 +0000
+++ b/net/libfetch/Makefile     Sat Jan 23 14:25:26 2010 +0000
@@ -1,7 +1,7 @@
-# $NetBSD: Makefile,v 1.35 2010/01/22 13:21:09 joerg Exp $
+# $NetBSD: Makefile,v 1.36 2010/01/23 14:25:26 joerg Exp $
 #
 
-DISTNAME=      libfetch-2.28
+DISTNAME=      libfetch-2.29
 CATEGORIES=    net
 MASTER_SITES=  # empty
 DISTFILES=     # empty
diff -r 5d41de1a6cc6 -r 3efe637c3635 net/libfetch/files/common.c
--- a/net/libfetch/files/common.c       Sat Jan 23 13:39:42 2010 +0000
+++ b/net/libfetch/files/common.c       Sat Jan 23 14:25:26 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: common.c,v 1.23 2010/01/23 13:39:42 joerg Exp $        */
+/*     $NetBSD: common.c,v 1.24 2010/01/23 14:25:26 joerg Exp $        */
 /*-
  * Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
  * Copyright (c) 2008, 2010 Joerg Sonnenberger <joerg%NetBSD.org@localhost>
@@ -65,9 +65,6 @@
 #include "fetch.h"
 #include "common.h"
 
-#define DECONST(x,y) ((x)(uintptr_t)(y))
-
-
 /*** Local data **************************************************************/
 
 /*
@@ -83,10 +80,6 @@
        { -1,           FETCH_UNKNOWN,  "Unknown resolver error" }
 };
 
-/* End-of-Line */
-static const char ENDL[2] = "\r\n";
-
-
 /*** Error-reporting functions ***********************************************/
 
 /*
@@ -620,26 +613,12 @@
        return (0);
 }
 
-
-/*
- * Write to a connection w/ timeout
- */
-ssize_t
-fetch_write(conn_t *conn, const char *buf, size_t len)
-{
-       struct iovec iov;
-
-       iov.iov_base = DECONST(char *, buf);
-       iov.iov_len = len;
-       return fetch_writev(conn, &iov, 1);
-}
-
 /*
  * Write a vector to a connection w/ timeout
  * Note: can modify the iovec.
  */
 ssize_t
-fetch_writev(conn_t *conn, struct iovec *iov, int iovcnt)
+fetch_write(conn_t *conn, const void *buf, size_t len)
 {
        struct timeval now, timeout, waittv;
        fd_set writefds;
@@ -653,7 +632,7 @@
        }
 
        total = 0;
-       while (iovcnt > 0) {
+       while (len) {
                while (fetchTimeout && !FD_ISSET(conn->sd, &writefds)) {
                        FD_SET(conn->sd, &writefds);
                        gettimeofday(&now, NULL);
@@ -679,11 +658,10 @@
                errno = 0;
 #ifdef WITH_SSL
                if (conn->ssl != NULL)
-                       wlen = SSL_write(conn->ssl,
-                           iov->iov_base, iov->iov_len);
+                       wlen = SSL_write(conn->ssl, buf, len);
                else
 #endif
-                       wlen = writev(conn->sd, iov, iovcnt);
+                       wlen = send(conn->sd, buf, len, MSG_NOSIGNAL);
                if (wlen == 0) {
                        /* we consider a short write a failure */
                        errno = EPIPE;
@@ -696,44 +674,14 @@
                        return (-1);
                }
                total += wlen;
-               while (iovcnt > 0 && wlen >= (ssize_t)iov->iov_len) {
-                       wlen -= iov->iov_len;
-                       iov++;
-                       iovcnt--;
-               }
-               if (iovcnt > 0) {
-                       iov->iov_len -= wlen;
-                       iov->iov_base = DECONST(char *, iov->iov_base) + wlen;
-               }
+               buf = (const char *)buf + wlen;
+               len -= wlen;
        }
        return (total);
 }
 
 
 /*
- * Write a line of text to a connection w/ timeout
- */
-int
-fetch_putln(conn_t *conn, const char *str, size_t len)
-{
-       struct iovec iov[2];
-       ssize_t ret;
-
-       iov[0].iov_base = DECONST(char *, str);
-       iov[0].iov_len = len;
-       iov[1].iov_base = DECONST(char *, ENDL);
-       iov[1].iov_len = sizeof(ENDL);
-       if (len == 0)
-               ret = fetch_writev(conn, &iov[1], 1);
-       else
-               ret = fetch_writev(conn, iov, 2);
-       if (ret == -1)
-               return (-1);
-       return (0);
-}
-
-
-/*
  * Close connection
  */
 int
diff -r 5d41de1a6cc6 -r 3efe637c3635 net/libfetch/files/common.h
--- a/net/libfetch/files/common.h       Sat Jan 23 13:39:42 2010 +0000
+++ b/net/libfetch/files/common.h       Sat Jan 23 14:25:26 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: common.h,v 1.14 2010/01/23 13:39:42 joerg Exp $        */
+/*     $NetBSD: common.h,v 1.15 2010/01/23 14:25:26 joerg Exp $        */
 /*-
  * Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
  * All rights reserved.
@@ -86,9 +86,6 @@
        const char      *string;
 };
 
-/* for fetch_writev */
-struct iovec;
-
 void            fetch_seterr(struct fetcherr *, int);
 void            fetch_syserr(void);
 void            fetch_info(const char *, ...);
@@ -102,9 +99,7 @@
 int             fetch_ssl(conn_t *, int);
 ssize_t                 fetch_read(conn_t *, char *, size_t);
 int             fetch_getln(conn_t *);
-ssize_t                 fetch_write(conn_t *, const char *, size_t);
-ssize_t                 fetch_writev(conn_t *, struct iovec *, int);
-int             fetch_putln(conn_t *, const char *, size_t);
+ssize_t                 fetch_write(conn_t *, const void *, size_t);
 int             fetch_close(conn_t *);
 int             fetch_add_entry(struct url_list *, struct url *, const char *, int);
 int             fetch_netrc_auth(struct url *url);
diff -r 5d41de1a6cc6 -r 3efe637c3635 net/libfetch/files/ftp.c
--- a/net/libfetch/files/ftp.c  Sat Jan 23 13:39:42 2010 +0000
+++ b/net/libfetch/files/ftp.c  Sat Jan 23 14:25:26 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ftp.c,v 1.33 2010/01/23 13:39:42 joerg Exp $   */
+/*     $NetBSD: ftp.c,v 1.34 2010/01/23 14:25:26 joerg Exp $   */
 /*-
  * Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
  * Copyright (c) 2008, 2009, 2010 Joerg Sonnenberger <joerg%NetBSD.org@localhost>
@@ -214,7 +214,7 @@
                return (-1);
        }
 
-       r = fetch_putln(conn, msg, len);
+       r = fetch_write(conn, msg, len);
        free(msg);
 
        if (r == -1) {
@@ -296,7 +296,7 @@
                end = file + strlen(file);
        else if ((end = strrchr(file, '/')) == NULL)
                return (0);
-       if ((e = ftp_cmd(conn, "PWD")) != FTP_WORKING_DIRECTORY ||
+       if ((e = ftp_cmd(conn, "PWD\r\n")) != FTP_WORKING_DIRECTORY ||
            (e = ftp_pwd(conn, pwd, sizeof(pwd))) != FTP_OK) {
                ftp_seterr(e);
                return (-1);
@@ -313,8 +313,8 @@
                        break;
                if (pwd[i] == '\0' && (file[i - 1] == '/' || file[i] == '/'))
                        break;
-               if ((e = ftp_cmd(conn, "CDUP")) != FTP_FILE_ACTION_OK ||
-                   (e = ftp_cmd(conn, "PWD")) != FTP_WORKING_DIRECTORY ||
+               if ((e = ftp_cmd(conn, "CDUP\r\n")) != FTP_FILE_ACTION_OK ||
+                   (e = ftp_cmd(conn, "PWD\r\n")) != FTP_WORKING_DIRECTORY ||
                    (e = ftp_pwd(conn, pwd, sizeof(pwd))) != FTP_OK) {
                        ftp_seterr(e);
                        return (-1);
@@ -331,7 +331,7 @@
                return (0);
 
        /* Change to the directory all in one chunk (e.g., foo/bar/baz). */
-       e = ftp_cmd(conn, "CWD %.*s", (int)(end - beg), beg);
+       e = ftp_cmd(conn, "CWD %.*s\r\n", (int)(end - beg), beg);
        if (e == FTP_FILE_ACTION_OK)
                return (0);
 #endif /* FTP_COMBINE_CWDS */
@@ -342,7 +342,7 @@
                        ++beg, ++i;
                for (++i; file + i < end && file[i] != '/'; ++i)
                        /* nothing */ ;
-               e = ftp_cmd(conn, "CWD %.*s", file + i - beg, beg);
+               e = ftp_cmd(conn, "CWD %.*s\r\n", file + i - beg, beg);
                if (e != FTP_FILE_ACTION_OK) {
                        ftp_seterr(e);
                        return (-1);
@@ -368,7 +368,7 @@
        default:
                return (FTP_PROTOCOL_ERROR);
        }
-       if ((e = ftp_cmd(conn, "MODE %c", mode)) != FTP_OK) {
+       if ((e = ftp_cmd(conn, "MODE %c\r\n", mode)) != FTP_OK) {
                if (mode == 'S') {
                        /*
                         * Stream mode is supposed to be the default - so
@@ -404,7 +404,7 @@
        default:
                return (FTP_PROTOCOL_ERROR);
        }
-       if ((e = ftp_cmd(conn, "TYPE %c", type)) != FTP_OK)
+       if ((e = ftp_cmd(conn, "TYPE %c\r\n", type)) != FTP_OK)
                return (e);
 
        return (FTP_OK);
@@ -433,7 +433,7 @@
                return (-1);
        }
 
-       e = ftp_cmd(conn, "SIZE %.*s", filenamelen, filename);
+       e = ftp_cmd(conn, "SIZE %.*s\r\n", filenamelen, filename);
        if (e != FTP_FILE_STATUS) {
                ftp_seterr(e);
                return (-1);
@@ -450,7 +450,7 @@
        if (us->size == 0)
                us->size = -1;
 
-       e = ftp_cmd(conn, "MDTM %.*s", filenamelen, filename);
+       e = ftp_cmd(conn, "MDTM %.*s\r\n", filenamelen, filename);
        if (e != FTP_FILE_STATUS) {
                ftp_seterr(e);
                return (-1);
@@ -565,7 +565,7 @@
 static int
 ftp_disconnect(conn_t *conn)
 {
-       ftp_cmd(conn, "QUIT");
+       ftp_cmd(conn, "QUIT\r\n");
        return fetch_close(conn);
 }
 
@@ -680,14 +680,14 @@
                        fetch_info("setting passive mode");
                switch (u.ss.ss_family) {
                case AF_INET:
-                       if ((e = ftp_cmd(conn, "PASV")) != FTP_PASSIVE_MODE)
+                       if ((e = ftp_cmd(conn, "PASV\r\n")) != FTP_PASSIVE_MODE)
                                goto ouch;
                        break;
                case AF_INET6:
-                       if ((e = ftp_cmd(conn, "EPSV")) != FTP_EPASSIVE_MODE) {
+                       if ((e = ftp_cmd(conn, "EPSV\r\n")) != FTP_EPASSIVE_MODE) {
                                if (e == -1)
                                        goto ouch;
-                               if ((e = ftp_cmd(conn, "LPSV")) !=
+                               if ((e = ftp_cmd(conn, "LPSV\r\n")) !=
                                    FTP_LPASSIVE_MODE)
                                        goto ouch;
                        }
@@ -747,7 +747,7 @@
 
                /* seek to required offset */
                if (offset)
-                       if (ftp_cmd(conn, "REST %lu", (unsigned long)offset) != FTP_FILE_OK)
+                       if (ftp_cmd(conn, "REST %lu\r\n", (unsigned long)offset) != FTP_FILE_OK)
                                goto sysouch;
 
                /* construct sockaddr for data socket */
@@ -792,9 +792,9 @@



Home | Main Index | Thread Index | Old Index