summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2010-03-05 08:13:25 +0000
committerNatanael Copa <ncopa@alpinelinux.org>2010-06-11 07:02:18 +0000
commit3ec82a5a420fc00d38ad7dded819525a91533652 (patch)
tree84016128e65001e4aed1d45a1402b2fb2375c385 /src
parent60b537e356dfcd0ed9a3516152c6a170912efcef (diff)
downloadapk-tools-3ec82a5a420fc00d38ad7dded819525a91533652.tar.gz
apk-tools-3ec82a5a420fc00d38ad7dded819525a91533652.tar.bz2
apk-tools-3ec82a5a420fc00d38ad7dded819525a91533652.tar.xz
apk-tools-3ec82a5a420fc00d38ad7dded819525a91533652.zip
First steps for libapk
Diffstat (limited to 'src')
-rw-r--r--src/Makefile24
-rw-r--r--src/add.c1
-rw-r--r--src/apk.c60
-rw-r--r--src/apk_database.h2
-rw-r--r--src/apk_defines.h9
-rw-r--r--src/apk_print.h27
-rw-r--r--src/apk_state.h3
-rw-r--r--src/archive.c1
-rw-r--r--src/cache.c1
-rw-r--r--src/database.c7
-rw-r--r--src/del.c1
-rw-r--r--src/fetch.c1
-rw-r--r--src/fix.c1
-rw-r--r--src/index.c1
-rw-r--r--src/info.c1
-rw-r--r--src/package.c1
-rw-r--r--src/print.c70
-rw-r--r--src/state.c1
-rw-r--r--src/update.c1
-rw-r--r--src/upgrade.c1
-rw-r--r--src/ver.c1
-rw-r--r--src/verify.c1
22 files changed, 142 insertions, 74 deletions
diff --git a/src/Makefile b/src/Makefile
index 0f60fa9..b0b2a67 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -4,24 +4,34 @@ ifeq ($(shell pkg-config --print-errors --exists $(PKGDEPS) || echo fail),fail)
$(error Build dependencies are not met)
endif
+shlibs-y += libapk.so
+libapk.so-objs := common.o state.o database.o package.o archive.o \
+ version.o io.o url.o gunzip.o blob.o hash.o print.o
+
progs-y += apk
-apk-objs := common.o state.o database.o package.o archive.o \
- version.o io.o url.o gunzip.o blob.o hash.o apk.o \
- add.o del.o fix.o update.o info.o search.o upgrade.o \
- cache.o ver.o index.o fetch.o audit.o verify.o
+apk-objs := apk.o add.o del.o fix.o update.o info.o \
+ search.o upgrade.o cache.o ver.o index.o fetch.o \
+ audit.o verify.o
+
CFLAGS += -D_ATFILE_SOURCE
CFLAGS_apk.o := -DAPK_VERSION=\"$(FULL_VERSION)\"
+LIBS_apk := -lapk
progs-$(STATIC) += apk.static
apk.static-objs := $(apk-objs)
LDFLAGS_apk.static := -static
-LDFLAGS_apk += -nopie
+LDFLAGS_apk += -nopie -L$(obj)
CFLAGS += $(shell pkg-config --cflags $(PKGDEPS))
LIBS := -Wl,--as-needed \
$(shell pkg-config --libs $(PKGDEPS)) \
-Wl,--no-as-needed
-install:
- $(INSTALLDIR) $(DESTDIR)$(SBINDIR)
+
+$(obj)/apk: $(obj)/libapk.so
+
+install: $(obj)/apk $(obj)/libapk.so
+ $(INSTALLDIR) $(DESTDIR)$(SBINDIR) $(DESTDIR)$(LIBDIR)
$(INSTALL) $(obj)/apk $(DESTDIR)$(SBINDIR)
+ $(INSTALL) $(obj)/libapk.so $(DESTDIR)$(LIBDIR)
+
diff --git a/src/add.c b/src/add.c
index 91570fe..f13215a 100644
--- a/src/add.c
+++ b/src/add.c
@@ -14,6 +14,7 @@
#include "apk_applet.h"
#include "apk_database.h"
#include "apk_state.h"
+#include "apk_print.h"
struct add_ctx {
const char *virtpkg;
diff --git a/src/apk.c b/src/apk.c
index 2273fa4..8575f66 100644
--- a/src/apk.c
+++ b/src/apk.c
@@ -24,9 +24,7 @@
#include "apk_database.h"
#include "apk_applet.h"
#include "apk_blob.h"
-
-int apk_verbosity = 1, apk_wait;
-unsigned int apk_flags = 0;
+#include "apk_print.h"
static struct apk_option generic_options[] = {
{ 'h', "help", "Show generic help or applet specific help" },
@@ -60,64 +58,12 @@ static struct apk_option generic_options[] = {
{ 0x111, "overlay-from-stdin", "Read list of overlay files from stdin" },
};
-const char *apk_error_str(int error)
-{
- if (error < 0)
- error = -error;
- switch (error) {
- case ENOKEY:
- return "UNTRUSTED signature";
- case EKEYREJECTED:
- return "BAD signature";
- case EIO:
- return "IO ERROR";
- case EBADMSG:
- return "BAD archive";
- case ENOMSG:
- return "archive does not contain expected data";
- default:
- return strerror(error);
- }
-}
-
-void apk_log(const char *prefix, const char *format, ...)
-{
- va_list va;
-
- if (prefix != NULL)
- fprintf(stderr, "%s", prefix);
- va_start(va, format);
- vfprintf(stderr, format, va);
- va_end(va);
- fprintf(stderr, "\n");
-}
-
static int version(void)
{
printf("apk-tools " APK_VERSION "\n");
return 0;
}
-int apk_print_indented(struct apk_indent *i, apk_blob_t blob)
-{
- static const int wrap_length = 80;
-
- if (i->x + blob.len + 1 >= wrap_length) {
- i->x = i->indent;
- printf("\n%*s", i->indent - 1, "");
- } else if (i->x+1 < i->indent) {
- printf("%*s", i->indent - i->x - 1, "");
- }
- i->x += printf(" %.*s", blob.len, blob.ptr);
- return 0;
-}
-
-void apk_print_indented_words(struct apk_indent *i, const char *text)
-{
- apk_blob_for_each_segment(APK_BLOB_STR(text), " ",
- (apk_blob_cb) apk_print_indented, i);
-}
-
static int format_option(char *buf, size_t len, struct apk_option *o,
const char *separator)
{
@@ -289,7 +235,7 @@ int main(int argc, char **argv)
struct apk_applet *applet;
char short_options[256], *sopt;
struct option *opt, *all_options;
- int r, optindex, num_options;
+ int r, optindex, num_options, apk_wait = 0;
void *ctx = NULL;
struct apk_repository_list *repo = NULL;
struct apk_database db;
@@ -410,7 +356,7 @@ int main(int argc, char **argv)
argv++;
}
- r = apk_db_open(&db, &dbopts);
+ r = apk_db_open(&db, &dbopts, apk_wait);
if (r != 0) {
apk_error("Failed to open apk database: %s",
apk_error_str(r));
diff --git a/src/apk_database.h b/src/apk_database.h
index da3b0ae..ffb1bce 100644
--- a/src/apk_database.h
+++ b/src/apk_database.h
@@ -155,7 +155,7 @@ struct apk_db_file *apk_db_file_query(struct apk_database *db,
APK_OPENF_NO_SCRIPTS | \
APK_OPENF_NO_WORLD)
-int apk_db_open(struct apk_database *db, struct apk_db_options *dbopts);
+int apk_db_open(struct apk_database *db, struct apk_db_options *dbopts, int apk_wait);
void apk_db_close(struct apk_database *db);
int apk_db_write_config(struct apk_database *db);
int apk_db_run_triggers(struct apk_database *db);
diff --git a/src/apk_defines.h b/src/apk_defines.h
index 4a07414..30927bd 100644
--- a/src/apk_defines.h
+++ b/src/apk_defines.h
@@ -47,7 +47,7 @@
(type *)( (char *)__mptr - offsetof(type,member) );})
#endif
-extern int apk_verbosity, apk_wait;
+extern int apk_verbosity;
extern unsigned int apk_flags;
#define APK_FORCE 0x0001
@@ -65,13 +65,6 @@ extern unsigned int apk_flags;
#define APK_NO_NETWORK 0x1000
#define APK_OVERLAY_FROM_STDIN 0x2000
-#define apk_error(args...) do { apk_log("ERROR: ", args); } while (0)
-#define apk_warning(args...) do { if (apk_verbosity > 0) { apk_log("WARNING: ", args); } } while (0)
-#define apk_message(args...) do { if (apk_verbosity > 0) { apk_log(NULL, args); } } while (0)
-
-void apk_log(const char *prefix, const char *format, ...);
-const char *apk_error_str(int error);
-
static inline size_t apk_calc_installed_size(size_t size)
{
const size_t bsize = 4 * 1024;
diff --git a/src/apk_print.h b/src/apk_print.h
new file mode 100644
index 0000000..fdbab11
--- /dev/null
+++ b/src/apk_print.h
@@ -0,0 +1,27 @@
+/* apk_state.h - Alpine Package Keeper (APK)
+ *
+ * Copyright (C) 2005-2008 Natanael Copa <n@tanael.org>
+ * Copyright (C) 2008 Timo Teräs <timo.teras@iki.fi>
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation. See http://www.gnu.org/ for details.
+ */
+
+#ifndef APK_PRINT_H
+#define APK_PRINT_H
+
+#include "apk_blob.h"
+
+#define apk_error(args...) do { apk_log("ERROR: ", args); } while (0)
+#define apk_warning(args...) do { if (apk_verbosity > 0) { apk_log("WARNING: ", args); } } while (0)
+#define apk_message(args...) do { if (apk_verbosity > 0) { apk_log(NULL, args); } } while (0)
+
+void apk_log(const char *prefix, const char *format, ...);
+const char *apk_error_str(int error);
+
+int apk_print_indented(struct apk_indent *i, apk_blob_t blob);
+void apk_print_indented_words(struct apk_indent *i, const char *text);
+
+#endif
diff --git a/src/apk_state.h b/src/apk_state.h
index 42d3f3f..345acf3 100644
--- a/src/apk_state.h
+++ b/src/apk_state.h
@@ -43,4 +43,7 @@ int apk_state_lock_name(struct apk_state *state,
struct apk_name *name,
struct apk_package *newpkg);
+int apk_print_indented(struct apk_indent *i, apk_blob_t blob);
+void apk_print_indented_words(struct apk_indent *i, const char *text);
+
#endif
diff --git a/src/archive.c b/src/archive.c
index b27c039..2df93d9 100644
--- a/src/archive.c
+++ b/src/archive.c
@@ -24,6 +24,7 @@
#include <stdint.h>
#include "apk_defines.h"
+#include "apk_print.h"
#include "apk_archive.h"
struct tar_header {
diff --git a/src/cache.c b/src/cache.c
index 4ed89fa..5311815 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -19,6 +19,7 @@
#include "apk_database.h"
#include "apk_state.h"
#include "apk_package.h"
+#include "apk_print.h"
#define CACHE_CLEAN BIT(0)
#define CACHE_DOWNLOAD BIT(1)
diff --git a/src/database.c b/src/database.c
index 11864cb..3d49c9e 100644
--- a/src/database.c
+++ b/src/database.c
@@ -27,6 +27,10 @@
#include "apk_state.h"
#include "apk_applet.h"
#include "apk_archive.h"
+#include "apk_print.h"
+
+int apk_verbosity = 1;
+unsigned int apk_flags = 0;
const char * const apkindex_tar_gz = "APKINDEX.tar.gz";
const char * const apk_index_gz = "APK_INDEX.gz";
@@ -1021,7 +1025,8 @@ static void handle_alarm(int sig)
{
}
-int apk_db_open(struct apk_database *db, struct apk_db_options *dbopts)
+int apk_db_open(struct apk_database *db, struct apk_db_options *dbopts,
+ int apk_wait)
{
const char *msg = NULL;
struct apk_repository_list *repo = NULL;
diff --git a/src/del.c b/src/del.c
index 7ac7625..f4437b9 100644
--- a/src/del.c
+++ b/src/del.c
@@ -13,6 +13,7 @@
#include "apk_applet.h"
#include "apk_state.h"
#include "apk_database.h"
+#include "apk_print.h"
static int del_parse(void *ctx, struct apk_db_options *db,
int optch, int optindex, const char *optarg)
diff --git a/src/fetch.c b/src/fetch.c
index dc9bff2..b7da2f5 100644
--- a/src/fetch.c
+++ b/src/fetch.c
@@ -20,6 +20,7 @@
#include "apk_database.h"
#include "apk_state.h"
#include "apk_io.h"
+#include "apk_print.h"
#define FETCH_RECURSIVE 1
#define FETCH_STDOUT 2
diff --git a/src/fix.c b/src/fix.c
index 8b9021a..1bacce2 100644
--- a/src/fix.c
+++ b/src/fix.c
@@ -14,6 +14,7 @@
#include "apk_applet.h"
#include "apk_database.h"
#include "apk_state.h"
+#include "apk_print.h"
struct fix_ctx {
unsigned int reinstall : 1;
diff --git a/src/index.c b/src/index.c
index 2676269..e7ed0c3 100644
--- a/src/index.c
+++ b/src/index.c
@@ -15,6 +15,7 @@
#include "apk_applet.h"
#include "apk_database.h"
+#include "apk_print.h"
#define INDEX_OLD_FORMAT 0x10000
diff --git a/src/info.c b/src/info.c
index dfb3712..19a3f48 100644
--- a/src/info.c
+++ b/src/info.c
@@ -16,6 +16,7 @@
#include "apk_package.h"
#include "apk_database.h"
#include "apk_state.h"
+#include "apk_print.h"
struct info_ctx {
int (*action)(struct info_ctx *ctx, struct apk_database *db,
diff --git a/src/package.c b/src/package.c
index f981f45..10f0d1b 100644
--- a/src/package.c
+++ b/src/package.c
@@ -27,6 +27,7 @@
#include "apk_package.h"
#include "apk_database.h"
#include "apk_state.h"
+#include "apk_print.h"
void apk_pkg_format_plain(struct apk_package *pkg, apk_blob_t to)
{
diff --git a/src/print.c b/src/print.c
new file mode 100644
index 0000000..4b3d246
--- /dev/null
+++ b/src/print.c
@@ -0,0 +1,70 @@
+/* state.c - Alpine Package Keeper (APK)
+ *
+ * Copyright (C) 2005-2008 Natanael Copa <n@tanael.org>
+ * Copyright (C) 2008 Timo Teräs <timo.teras@iki.fi>
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation. See http://www.gnu.org/ for details.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <malloc.h>
+#include <errno.h>
+
+#include "apk_defines.h"
+#include "apk_print.h"
+
+int apk_print_indented(struct apk_indent *i, apk_blob_t blob)
+{
+ static const int wrap_length = 80;
+
+ if (i->x + blob.len + 1 >= wrap_length) {
+ i->x = i->indent;
+ printf("\n%*s", i->indent - 1, "");
+ }
+ i->x += printf(" %.*s", blob.len, blob.ptr);
+ return 0;
+}
+
+void apk_print_indented_words(struct apk_indent *i, const char *text)
+{
+ apk_blob_for_each_segment(APK_BLOB_STR(text), " ",
+ (apk_blob_cb) apk_print_indented, i);
+}
+
+const char *apk_error_str(int error)
+{
+ if (error < 0)
+ error = -error;
+ switch (error) {
+ case ENOKEY:
+ return "UNTRUSTED signature";
+ case EKEYREJECTED:
+ return "BAD signature";
+ case EIO:
+ return "IO ERROR";
+ case EBADMSG:
+ return "BAD archive";
+ case ENOMSG:
+ return "archive does not contain expected data";
+ default:
+ return strerror(error);
+ }
+}
+
+void apk_log(const char *prefix, const char *format, ...)
+{
+ va_list va;
+
+ if (prefix != NULL)
+ fprintf(stderr, "%s", prefix);
+ va_start(va, format);
+ vfprintf(stderr, format, va);
+ va_end(va);
+ fprintf(stderr, "\n");
+}
+
diff --git a/src/state.c b/src/state.c
index 178e4c9..7c758cc 100644
--- a/src/state.c
+++ b/src/state.c
@@ -16,6 +16,7 @@
#include "apk_state.h"
#include "apk_database.h"
+#include "apk_print.h"
struct apk_name_choices {
unsigned short refs, num;
diff --git a/src/update.c b/src/update.c
index b558342..945258d 100644
--- a/src/update.c
+++ b/src/update.c
@@ -14,6 +14,7 @@
#include "apk_applet.h"
#include "apk_database.h"
#include "apk_version.h"
+#include "apk_print.h"
static int update_main(void *ctx, struct apk_database *db, int argc, char **argv)
{
diff --git a/src/upgrade.c b/src/upgrade.c
index 611f677..2d7fd39 100644
--- a/src/upgrade.c
+++ b/src/upgrade.c
@@ -15,6 +15,7 @@
#include "apk_applet.h"
#include "apk_database.h"
#include "apk_state.h"
+#include "apk_print.h"
static int upgrade_parse(void *ctx, struct apk_db_options *dbopts,
int optch, int optindex, const char *optarg)
diff --git a/src/ver.c b/src/ver.c
index a617bdb..36c389d 100644
--- a/src/ver.c
+++ b/src/ver.c
@@ -14,6 +14,7 @@
#include "apk_applet.h"
#include "apk_database.h"
#include "apk_version.h"
+#include "apk_print.h"
struct ver_ctx {
int (*action)(struct apk_database *db, int argc, char **argv);
diff --git a/src/verify.c b/src/verify.c
index e9505ca..006b548 100644
--- a/src/verify.c
+++ b/src/verify.c
@@ -15,6 +15,7 @@
#include "apk_applet.h"
#include "apk_database.h"
+#include "apk_print.h"
static int verify_main(void *ctx, struct apk_database *db, int argc, char **argv)
{