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.4.10:



details:   https://anonhg.NetBSD.org/pkgsrc/rev/90eed96d919a
branches:  trunk
changeset: 541661:90eed96d919a
user:      joerg <joerg%pkgsrc.org@localhost>
date:      Thu Apr 24 07:55:00 2008 +0000

description:
libfetch-2.4.10:
Start URL quoting cleanup.  All URLs are now quoted correctly on parsing
and when appending URLs.  URLs without schema and starting with slash are
considered to be file:// URLs.

diffstat:

 net/libfetch/Makefile       |    4 +-
 net/libfetch/files/common.c |   50 ++++++++++++--
 net/libfetch/files/common.h |    5 +-
 net/libfetch/files/fetch.c  |  154 +++++++++++++++++++++++++++++++------------
 net/libfetch/files/file.c   |   14 +---
 net/libfetch/files/ftp.c    |    4 +-
 net/libfetch/files/http.c   |    4 +-
 7 files changed, 162 insertions(+), 73 deletions(-)

diffs (truncated from 405 to 300 lines):

diff -r 110f221b5526 -r 90eed96d919a net/libfetch/Makefile
--- a/net/libfetch/Makefile     Thu Apr 24 07:45:49 2008 +0000
+++ b/net/libfetch/Makefile     Thu Apr 24 07:55:00 2008 +0000
@@ -1,7 +1,7 @@
-# $NetBSD: Makefile,v 1.12 2008/04/21 17:15:31 joerg Exp $
+# $NetBSD: Makefile,v 1.13 2008/04/24 07:55:00 joerg Exp $
 #
 
-DISTNAME=      libfetch-2.9
+DISTNAME=      libfetch-2.10
 CATEGORIES=    net
 MASTER_SITES=  # empty
 DISTFILES=     # empty
diff -r 110f221b5526 -r 90eed96d919a net/libfetch/files/common.c
--- a/net/libfetch/files/common.c       Thu Apr 24 07:45:49 2008 +0000
+++ b/net/libfetch/files/common.c       Thu Apr 24 07:55:00 2008 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: common.c,v 1.9 2008/04/21 21:15:53 joerg Exp $ */
+/*     $NetBSD: common.c,v 1.10 2008/04/24 07:55:00 joerg Exp $        */
 /*-
  * Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
  * Copyright (c) 2008 Joerg Sonnenberger <joerg%NetBSD.org@localhost>
@@ -620,18 +620,33 @@
 /*** Directory-related utility functions *************************************/
 
 int
-fetch_add_entry(struct url_list *ue, struct url *base, const char *name)
+fetch_add_entry(struct url_list *ue, struct url *base, const char *name,
+    int pre_quoted)
 {
        struct url *tmp;
        char *tmp_name;
-       size_t base_doc_len, name_len;
+       size_t base_doc_len, name_len, i;
+       unsigned char c;
 
        if (strchr(name, '/') != NULL ||
            strcmp(name, "..") == 0 ||
            strcmp(name, ".") == 0)
                return 0;
 
-       base_doc_len = strlen(base->doc);
+       if (strcmp(base->doc, "/") == 0)
+               base_doc_len = 0;
+       else
+               base_doc_len = strlen(base->doc);
+
+       name_len = 1;
+       for (i = 0; name[i] != '\0'; ++i) {
+               if ((!pre_quoted && name[i] == '%') ||
+                   !fetch_urlpath_safe(name[i]))
+                       name_len += 3;
+               else
+                       ++name_len;
+       }
+
        name_len = strlen(name);
        tmp_name = malloc( base_doc_len + name_len + 2);
        if (tmp_name == NULL) {
@@ -658,11 +673,30 @@
        strcpy(tmp->pwd, base->pwd);
        strcpy(tmp->host, base->host);
        tmp->port = base->port;
-       memcpy(tmp_name, base->doc, base_doc_len);
-       tmp_name[base_doc_len] = '/';
-       memcpy(tmp_name + base_doc_len + 1, name, name_len);
-       tmp_name[base_doc_len + name_len + 1] = '\0';
        tmp->doc = tmp_name;
+       memcpy(tmp->doc, base->doc, base_doc_len);
+       tmp->doc[base_doc_len] = '/';
+
+       for (i = base_doc_len + 1; *name != '\0'; ++name) {
+               if ((!pre_quoted && *name == '%') ||
+                   !fetch_urlpath_safe(*name)) {
+                       tmp->doc[i++] = '%';
+                       c = (unsigned char)*name / 16;
+                       if (c < 160)
+                               tmp->doc[i++] = '0' + c;
+                       else
+                               tmp->doc[i++] = 'a' - 10 + c;
+                       c = (unsigned char)*name % 16;
+                       if (c < 16)
+                               tmp->doc[i++] = '0' + c;
+                       else
+                               tmp->doc[i++] = 'a' - 10 + c;
+               } else {
+                       tmp->doc[i++] = *name;
+               }
+       }
+       tmp->doc[i] = '\0';
+
        tmp->offset = 0;
        tmp->length = 0;
 
diff -r 110f221b5526 -r 90eed96d919a net/libfetch/files/common.h
--- a/net/libfetch/files/common.h       Thu Apr 24 07:45:49 2008 +0000
+++ b/net/libfetch/files/common.h       Thu Apr 24 07:55:00 2008 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: common.h,v 1.6 2008/04/19 14:49:23 joerg Exp $ */
+/*     $NetBSD: common.h,v 1.7 2008/04/24 07:55:00 joerg Exp $ */
 /*-
  * Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
  * All rights reserved.
@@ -93,9 +93,10 @@
 ssize_t                 fetch_writev(conn_t *, struct iovec *, int);
 int             fetch_putln(conn_t *, const char *, size_t);
 int             fetch_close(conn_t *);
-int             fetch_add_entry(struct url_list *, struct url *, const char *);
+int             fetch_add_entry(struct url_list *, struct url *, const char *, int);
 int             fetch_netrc_auth(struct url *url);
 int             fetch_no_proxy_match(const char *);
+int             fetch_urlpath_safe(char);
 
 #define ftp_seterr(n)   fetch_seterr(ftp_errlist, n)
 #define http_seterr(n)  fetch_seterr(http_errlist, n)
diff -r 110f221b5526 -r 90eed96d919a net/libfetch/files/fetch.c
--- a/net/libfetch/files/fetch.c        Thu Apr 24 07:45:49 2008 +0000
+++ b/net/libfetch/files/fetch.c        Thu Apr 24 07:55:00 2008 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fetch.c,v 1.6 2008/04/21 17:15:31 joerg Exp $  */
+/*     $NetBSD: fetch.c,v 1.7 2008/04/24 07:55:00 joerg Exp $  */
 /*-
  * Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
  * All rights reserved.
@@ -296,6 +296,40 @@
        return (u);
 }
 
+int
+fetch_urlpath_safe(char x)
+{
+       switch (x) {
+       case 'a'...'z':
+       case 'A'...'Z':
+       case '0'...'9':
+       case '$':
+       case '-':
+       case '_':
+       case '.':
+       case '+':
+       case '!':
+       case '*':
+       case '\'':
+       case '(':
+       case ')':
+       case ',':
+       /* The following are allowed in segment and path components: */
+       case '?':
+       case ':':
+       case '@':
+       case '&':
+       case '=':
+       case '/':
+       case ';':
+       /* If something is already quoted... */
+       case '%':
+               return 1;
+       default:
+               return 0;
+       }
+}
+
 /*
  * Copy an existing URL.
  */
@@ -329,10 +363,9 @@
 struct url *
 fetchParseURL(const char *URL)
 {
-       char *doc;
        const char *p, *q;
        struct url *u;
-       int i;
+       size_t i, count;
 
        /* allocate struct url */
        if ((u = calloc(1, sizeof(*u))) == NULL) {
@@ -340,43 +373,76 @@
                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 {
+       if (*URL == '/') {
+               strcpy(u->scheme, SCHEME_FILE);
                p = URL;
+               goto quote_doc;
        }
-       if (!*URL || *URL == '/' || *URL == '.' ||
-           (u->scheme[0] == '\0' &&
-               strchr(URL, '/') == NULL && strchr(URL, ':') == NULL))
-               goto nohost;
+       if (strncmp(URL, "file:", 5) == 0) {
+               strcpy(u->scheme, SCHEME_FILE);
+               URL += 5;
+               if (URL[0] != '/' || URL[1] != '/' || URL[2] != '/') {
+                       url_seterr(URL_MALFORMED);
+                       goto ouch;
+               }
+               p = URL + 2;
+               goto quote_doc;
+       }
+       if (strncmp(URL, "http:", 5) == 0 ||
+           strncmp(URL, "https:", 6) == 0) {
+               if (URL[4] == ':') {
+                       strcpy(u->scheme, SCHEME_HTTP);
+                       URL += 5;
+               } else {
+                       strcpy(u->scheme, SCHEME_HTTPS);
+                       URL += 6;
+               }
 
+               if (URL[0] != '/' || URL[1] != '/') {
+                       url_seterr(URL_MALFORMED);
+                       goto ouch;
+               }
+               URL += 2;
+               p = URL;
+               goto find_hostname;
+       }
+       if (strncmp(URL, "ftp:", 4) == 0) {
+               strcpy(u->scheme, SCHEME_FTP);
+               URL += 4;
+               if (URL[0] != '/' || URL[1] != '/') {
+                       url_seterr(URL_MALFORMED);
+                       goto ouch;
+               }
+               URL += 2;
+               p = URL;
+               goto find_user;                 
+       }
+
+       url_seterr(URL_BAD_SCHEME);
+       goto ouch;
+
+find_user:
        p = strpbrk(URL, "/@");
-       if (p && *p == '@') {
+       if (p != NULL && *p == '@') {
                /* username */
-               for (q = URL, i = 0; (*q != ':') && (*q != '@'); q++)
+               for (q = URL, i = 0; (*q != ':') && (*q != '@'); q++) {
                        if (i < URL_USERLEN)
                                u->user[i++] = *q;
+               }
 
                /* password */
-               if (*q == ':')
+               if (*q == ':') {
                        for (q++, i = 0; (*q != ':') && (*q != '@'); q++)
                                if (i < URL_PWDLEN)
                                        u->pwd[i++] = *q;
+               }
 
                p++;
        } else {
                p = URL;
        }
 
+find_hostname:
        /* hostname */
 #ifdef INET6
        if (*p == '[' && (q = strchr(p + 1, ']')) != NULL &&
@@ -404,36 +470,34 @@
                p = q;
        }
 
-nohost:
        /* document */
        if (!*p)
                p = "/";
 
-       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((unsigned char)*p)) {
-                               *doc++ = *p++;
-                       } else {
-                               *doc++ = '%';
-                               *doc++ = hexnums[((unsigned int)*p) >> 4];
-                               *doc++ = hexnums[((unsigned int)*p) & 0xf];
-                               p++;



Home | Main Index | Thread Index | Old Index