summaryrefslogtreecommitdiff
path: root/pkgtools/pkg_install/files/lib
diff options
context:
space:
mode:
authorjoerg <joerg@pkgsrc.org>2008-04-04 15:21:32 +0000
committerjoerg <joerg@pkgsrc.org>2008-04-04 15:21:32 +0000
commit3cb9e8532dd98e3b5ac86fce2612c30b0a10cc57 (patch)
tree17f752445c926f2ac88209d1c9a7f73d9ea8d0e3 /pkgtools/pkg_install/files/lib
parentb93dfe6ceda94c5959dc2bda3c9a554ab4545680 (diff)
downloadpkgsrc-3cb9e8532dd98e3b5ac86fce2612c30b0a10cc57.tar.gz
pkg_install-20080404:
Switch pkg_info to use libfetch for remote access.
Diffstat (limited to 'pkgtools/pkg_install/files/lib')
-rw-r--r--pkgtools/pkg_install/files/lib/Makefile.in4
-rw-r--r--pkgtools/pkg_install/files/lib/lib.h10
-rw-r--r--pkgtools/pkg_install/files/lib/pkg_io.c139
-rw-r--r--pkgtools/pkg_install/files/lib/version.h4
4 files changed, 152 insertions, 5 deletions
diff --git a/pkgtools/pkg_install/files/lib/Makefile.in b/pkgtools/pkg_install/files/lib/Makefile.in
index 42fd666f6e8..f542390de47 100644
--- a/pkgtools/pkg_install/files/lib/Makefile.in
+++ b/pkgtools/pkg_install/files/lib/Makefile.in
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.in,v 1.19 2008/03/10 12:14:32 wiz Exp $
+# $NetBSD: Makefile.in,v 1.20 2008/04/04 15:21:32 joerg Exp $
srcdir= @srcdir@
@@ -29,7 +29,7 @@ LIB= libinstall.a
OBJS= automatic.o conflicts.o decompress.o dewey.o fexec.o file.o \
ftpio.o global.o iterate.o lpkg.o opattern.o \
- path.o pen.o pexec.o pkgdb.o plist.o \
+ path.o pen.o pexec.o pkgdb.o pkg_io.o plist.o \
str.o var.o version.o vulnerabilities-file.o
.if !empty(BOOTSTRAP)
diff --git a/pkgtools/pkg_install/files/lib/lib.h b/pkgtools/pkg_install/files/lib/lib.h
index 04fb9ee452b..03dfc0e68df 100644
--- a/pkgtools/pkg_install/files/lib/lib.h
+++ b/pkgtools/pkg_install/files/lib/lib.h
@@ -1,4 +1,4 @@
-/* $NetBSD: lib.h,v 1.40 2008/02/19 15:16:24 joerg Exp $ */
+/* $NetBSD: lib.h,v 1.41 2008/04/04 15:21:32 joerg Exp $ */
/* from FreeBSD Id: lib.h,v 1.25 1997/10/08 07:48:03 charnier Exp */
@@ -385,6 +385,14 @@ int ftp_cmd(const char *, const char *);
int ftp_start(const char *);
void ftp_stop(void);
+/* pkg_io.c: Local and remote archive handling */
+struct archive;
+
+struct archive *open_remote_archive(const char *, void **);
+void close_remote_archive(void *);
+struct archive *open_local_archive(const char *, void **);
+void close_local_archive(void *);
+
/* Packing list */
plist_t *new_plist_entry(void);
plist_t *last_plist(package_t *);
diff --git a/pkgtools/pkg_install/files/lib/pkg_io.c b/pkgtools/pkg_install/files/lib/pkg_io.c
new file mode 100644
index 00000000000..643262e0221
--- /dev/null
+++ b/pkgtools/pkg_install/files/lib/pkg_io.c
@@ -0,0 +1,139 @@
+/* $NetBSD: pkg_io.c,v 1.1 2008/04/04 15:21:32 joerg Exp $ */
+/*-
+ * Copyright (c) 2008 Joerg Sonnenberger <joerg@NetBSD.org>.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include <nbcompat.h>
+#if HAVE_SYS_CDEFS_H
+#include <sys/cdefs.h>
+#endif
+
+__RCSID("$NetBSD: pkg_io.c,v 1.1 2008/04/04 15:21:32 joerg Exp $");
+
+#include <archive.h>
+#include <archive_entry.h>
+#if HAVE_ERR_H
+#include <err.h>
+#endif
+#if HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#include <fetch.h>
+#include <stdlib.h>
+
+#include "lib.h"
+
+struct fetch_archive {
+ const char *url;
+ fetchIO *fetch;
+ char buffer[32768];
+};
+
+static int
+fetch_archive_open(struct archive *a, void *client_data)
+{
+ struct fetch_archive *f = client_data;
+
+ f->fetch = fetchGetURL(f->url, "");
+ if (f->fetch == NULL)
+ return ENOENT;
+ return 0;
+}
+
+static ssize_t
+fetch_archive_read(struct archive *a, void *client_data,
+ const void **buffer)
+{
+ struct fetch_archive *f = client_data;
+
+ *buffer = f->buffer;
+ return fetchIO_read(f->fetch, f->buffer, sizeof(f->buffer));
+}
+
+static int
+fetch_archive_close(struct archive *a, void *client_data)
+{
+ struct fetch_archive *f = client_data;
+
+ if (f->fetch != NULL)
+ fetchIO_close(f->fetch);
+ return 0;
+}
+
+struct archive *
+open_remote_archive(const char *url, void **cookie)
+{
+ struct fetch_archive *f;
+ struct archive *archive;
+
+ f = malloc(sizeof(*f));
+ if (f == NULL)
+ err(2, "cannot allocate memory for remote archive");
+ f->url = url;
+
+ archive = archive_read_new();
+ archive_read_support_compression_all(archive);
+ archive_read_support_format_all(archive);
+ if (archive_read_open(archive, f, fetch_archive_open, fetch_archive_read,
+ fetch_archive_close))
+ errx(2, "cannot open archive: %s", archive_error_string(archive));
+
+ *cookie = f;
+
+ return archive;
+}
+
+void
+close_remote_archive(void *cookie)
+{
+ free(cookie);
+}
+
+struct archive *
+open_local_archive(const char *path, void **cookie)
+{
+ struct archive *archive;
+
+ archive = archive_read_new();
+ archive_read_support_compression_all(archive);
+ archive_read_support_format_all(archive);
+ if (archive_read_open_filename(archive, path, 1024))
+ errx(2, "cannot open archive: %s",
+ archive_error_string(archive));
+ *cookie = NULL;
+
+ return archive;
+}
+
+void
+close_local_archive(void *cookie)
+{
+}
diff --git a/pkgtools/pkg_install/files/lib/version.h b/pkgtools/pkg_install/files/lib/version.h
index 0a6307c47cb..f6ceb3da2fa 100644
--- a/pkgtools/pkg_install/files/lib/version.h
+++ b/pkgtools/pkg_install/files/lib/version.h
@@ -1,4 +1,4 @@
-/* $NetBSD: version.h,v 1.97 2008/03/13 16:35:31 joerg Exp $ */
+/* $NetBSD: version.h,v 1.98 2008/04/04 15:21:32 joerg Exp $ */
/*
* Copyright (c) 2001 Thomas Klausner. All rights reserved.
@@ -33,6 +33,6 @@
#ifndef _INST_LIB_VERSION_H_
#define _INST_LIB_VERSION_H_
-#define PKGTOOLS_VERSION "20080313"
+#define PKGTOOLS_VERSION "20080402"
#endif /* _INST_LIB_VERSION_H_ */