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



details:   https://anonhg.NetBSD.org/pkgsrc/rev/b9daf9423b18
branches:  trunk
changeset: 541396:b9daf9423b18
user:      joerg <joerg%pkgsrc.org@localhost>
date:      Mon Apr 21 17:15:31 2008 +0000

description:
libfetch-2.9:
Add fetch_extract_filename to extract the unquoted filename of a URL.

diffstat:

 net/libfetch/Makefile      |   4 +-
 net/libfetch/files/fetch.c |  50 +++++++++++++++++++++++++++++++++++++++++++++-
 net/libfetch/files/fetch.h |   3 +-
 3 files changed, 53 insertions(+), 4 deletions(-)

diffs (91 lines):

diff -r 7a5dd385a59e -r b9daf9423b18 net/libfetch/Makefile
--- a/net/libfetch/Makefile     Mon Apr 21 17:11:57 2008 +0000
+++ b/net/libfetch/Makefile     Mon Apr 21 17:15:31 2008 +0000
@@ -1,7 +1,7 @@
-# $NetBSD: Makefile,v 1.11 2008/04/21 13:09:57 joerg Exp $
+# $NetBSD: Makefile,v 1.12 2008/04/21 17:15:31 joerg Exp $
 #
 
-DISTNAME=      libfetch-2.8
+DISTNAME=      libfetch-2.9
 CATEGORIES=    net
 MASTER_SITES=  # empty
 DISTFILES=     # empty
diff -r 7a5dd385a59e -r b9daf9423b18 net/libfetch/files/fetch.c
--- a/net/libfetch/files/fetch.c        Mon Apr 21 17:11:57 2008 +0000
+++ b/net/libfetch/files/fetch.c        Mon Apr 21 17:15:31 2008 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fetch.c,v 1.5 2008/04/20 15:29:26 joerg Exp $  */
+/*     $NetBSD: fetch.c,v 1.6 2008/04/21 17:15:31 joerg Exp $  */
 /*-
  * Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
  * All rights reserved.
@@ -451,3 +451,51 @@
        free(u->doc);
        free(u);
 }
+
+static char
+xdigit2digit(char digit)
+{
+       digit = tolower((unsigned char)digit);
+       if (digit >= 'a' && digit <= 'f')
+               digit = digit - 'a' + 10;
+       else
+               digit = digit - '0';
+
+       return digit;
+}
+
+/*
+ * Extract the file name component of a URL.
+ */
+char *
+fetch_extract_filename(struct url *url)
+{
+       char *name, *name_iter;
+       const char *last_slash, *iter;
+
+       last_slash = url->doc;
+       if (*last_slash == '\0')
+               return strdup("");
+       for (iter = last_slash + 1; *iter; ++iter) {
+               if (*iter == '#' || *iter == '?')
+                       break;
+               if (*iter == '/')
+                       last_slash = iter;
+       }
+       if (last_slash + 1 == iter)
+               return strdup("");
+       name_iter = name = malloc(iter - last_slash);
+       while (++last_slash < iter) {
+               if (*last_slash != '%' ||
+                   !isxdigit((unsigned char)last_slash[1]) ||
+                   !isxdigit((unsigned char)last_slash[2])) {
+                       *name_iter++ = *last_slash;
+                       continue;
+               }
+               *name_iter++ = xdigit2digit(last_slash[1]) * 16 +
+                   xdigit2digit(last_slash[2]);
+               last_slash += 2;
+       }
+       *name_iter = '\0';
+       return name;
+}
diff -r 7a5dd385a59e -r b9daf9423b18 net/libfetch/files/fetch.h
--- a/net/libfetch/files/fetch.h        Mon Apr 21 17:11:57 2008 +0000
+++ b/net/libfetch/files/fetch.h        Mon Apr 21 17:15:31 2008 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fetch.h,v 1.7 2008/04/20 15:29:26 joerg Exp $  */
+/*     $NetBSD: fetch.h,v 1.8 2008/04/21 17:15:31 joerg Exp $  */
 /*-
  * Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
  * All rights reserved.
@@ -151,6 +151,7 @@
 /* URL listening */
 void            fetch_init_url_list(struct url_list *);
 void            fetch_free_url_list(struct url_list *);
+char           *fetch_extract_filename(struct url *);
 
 /* Authentication */
 typedef int (*auth_t)(struct url *);



Home | Main Index | Thread Index | Old Index