Merge commit 'grg' into HEAD
authorgraham.gower <graham.gower@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>
Wed, 9 Dec 2009 01:20:03 +0000 (01:20 +0000)
committergraham.gower <graham.gower@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>
Wed, 9 Dec 2009 01:20:03 +0000 (01:20 +0000)
git-svn-id: http://opkg.googlecode.com/svn/trunk@471 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358

64 files changed:
libbb/Makefile.am
libbb/error_msg.c [deleted file]
libbb/error_msg_and_die.c [deleted file]
libbb/gz_open.c
libbb/libbb.h
libbb/messages.c [deleted file]
libbb/perror_msg.c [deleted file]
libbb/perror_msg_and_die.c [deleted file]
libbb/unarchive.c
libbb/unzip.c
libbb/verror_msg.c [deleted file]
libbb/vperror_msg.c [deleted file]
libbb/xfuncs.c
libbb/xreadlink.c
libopkg/Makefile.am
libopkg/active_list.c
libopkg/active_list.h
libopkg/args.c
libopkg/args.h
libopkg/conffile.c
libopkg/conffile.h
libopkg/file_util.c
libopkg/hash_table.c
libopkg/libopkg.c
libopkg/libopkg.h
libopkg/opkg.c
libopkg/opkg.h
libopkg/opkg_cmd.c
libopkg/opkg_cmd.h
libopkg/opkg_conf.c
libopkg/opkg_conf.h
libopkg/opkg_configure.c
libopkg/opkg_configure.h
libopkg/opkg_download.c
libopkg/opkg_download.h
libopkg/opkg_error.h [deleted file]
libopkg/opkg_install.c
libopkg/opkg_install.h
libopkg/opkg_message.c
libopkg/opkg_message.h
libopkg/opkg_pathfinder.c
libopkg/opkg_remove.c
libopkg/opkg_remove.h
libopkg/opkg_upgrade.c
libopkg/opkg_upgrade.h
libopkg/opkg_utils.c
libopkg/opkg_utils.h
libopkg/pkg.c
libopkg/pkg.h
libopkg/pkg_depends.c
libopkg/pkg_depends.h
libopkg/pkg_extract.c
libopkg/pkg_hash.c
libopkg/pkg_hash.h
libopkg/pkg_parse.c
libopkg/pkg_vec.c
libopkg/pkg_vec.h
libopkg/sprintf_alloc.c
libopkg/user.c [deleted file]
libopkg/user.h [deleted file]
libopkg/void_list.c
libopkg/xregex.c
libopkg/xsystem.c
tests/libopkg_test.c

index 2da2dfd..1cc82df 100644 (file)
@@ -11,12 +11,9 @@ libbb_la_SOURCES = gz_open.c \
        unarchive.c \
        copy_file.c \
        copy_file_chunk.c \
-       error_msg.c error_msg_and_die.c \
-       perror_msg.c perror_msg_and_die.c \
        xreadlink.c \
        concat_path_file.c \
-       verror_msg.c vperror_msg.c \
-       xfuncs.c messages.c \
+       xfuncs.c \
        last_char_is.c \
        make_directory.c \
        safe_strncpy.c \
diff --git a/libbb/error_msg.c b/libbb/error_msg.c
deleted file mode 100644 (file)
index 58308b6..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * Utility routines.
- *
- * Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-#include "libbb.h"
-
-extern void error_msg(const char *s, ...)
-{
-       va_list p;
-
-       va_start(p, s);
-       verror_msg(s, p);
-       va_end(p);
-       putc('\n', stderr);
-}
-
-
-/* END CODE */
-/*
-Local Variables:
-c-file-style: "linux"
-c-basic-offset: 4
-tab-width: 4
-End:
-*/
diff --git a/libbb/error_msg_and_die.c b/libbb/error_msg_and_die.c
deleted file mode 100644 (file)
index 67a79c3..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * Utility routines.
- *
- * Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-#include "libbb.h"
-
-extern void error_msg_and_die(const char *s, ...)
-{
-       va_list p;
-
-       va_start(p, s);
-       verror_msg(s, p);
-       va_end(p);
-       putc('\n', stderr);
-       exit(EXIT_FAILURE);
-}
-
-
-/* END CODE */
-/*
-Local Variables:
-c-file-style: "linux"
-c-basic-offset: 4
-tab-width: 4
-End:
-*/
index 3d07b58..7c7c722 100644 (file)
@@ -35,11 +35,11 @@ gz_open(FILE *compressed_file, int *pid)
        int unzip_pipe[2];
 
        if (pipe(unzip_pipe)!=0) {
-               perror_msg("%s: pipe", __FUNCTION__);
+               perror_msg("pipe");
                return(NULL);
        }
        if ((*pid = fork()) == -1) {
-               perror_msg("%s: fork", __FUNCTION__);
+               perror_msg("fork");
                return(NULL);
        }
        if (*pid==0) {
@@ -62,26 +62,26 @@ gz_close(int gunzip_pid)
        int ret;
 
        if (waitpid(gunzip_pid, &status, 0) == -1) {
-               perror_msg("%s: waitpid", __FUNCTION__);
+               perror_msg("waitpid");
                return -1;
        }
        
        if (WIFSIGNALED(status)) {
-               error_msg("%s: unzip process killed by signal %d\n",
-                       __FUNCTION__, WTERMSIG(status));
+               error_msg("Unzip process killed by signal %d.\n",
+                       WTERMSIG(status));
                return -1;
        }
 
        if (!WIFEXITED(status)) {
                /* shouldn't happen */
-               error_msg("%s: Your system is broken: got status %d from waitpid\n",
-                               __FUNCTION__, status);
+               error_msg("Your system is broken: got status %d from waitpid.\n",
+                               status);
                return -1;
        }
 
        if ((ret = WEXITSTATUS(status))) {
-               error_msg("%s: unzip process failed with return code %d.\n",
-                               __FUNCTION__, ret);
+               error_msg("Unzip process failed with return code %d.\n",
+                               ret);
                return -1;
        }
 
index 619b400..4e1fafc 100644 (file)
 #include <stdarg.h>
 #include <sys/stat.h>
 #include <sys/types.h>
-
+#include <stdlib.h>
 #include <netdb.h>
 
-#include <features.h>
+#include "../libopkg/opkg_message.h"
 
 #ifndef FALSE
 #define FALSE   ((int) 0)
 #define TRUE    ((int) 1)
 #endif
 
-extern void error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
-extern void error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
-extern void perror_msg(const char *s, ...);
-extern void perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn));
-extern void archive_xread_all(int fd, char *buf, size_t count);
+#define error_msg(fmt, args...) opkg_msg(ERROR, fmt"\n", ##args)
+#define perror_msg(fmt, args...) opkg_perror(ERROR, fmt, ##args)
+#define error_msg_and_die(fmt, args...) \
+       do { \
+               error_msg(fmt, ##args); \
+               exit(EXIT_FAILURE); \
+       } while (0)
+#define perror_msg_and_die(fmt, args...) \
+       do { \
+               perror_msg(fmt, ##args); \
+               exit(EXIT_FAILURE); \
+       } while (0)
 
-/* These two are used internally -- you shouldn't need to use them */
-extern void verror_msg(const char *s, va_list p);
-extern void vperror_msg(const char *s, va_list p);
+extern void archive_xread_all(int fd, char *buf, size_t count);
 
 const char *mode_string(int mode);
 const char *time_string(time_t timeVal);
@@ -115,7 +120,4 @@ enum {
        FILEUTILS_FORCE = 8,
 };
 
-extern const char *applet_name;
-extern const char * const memory_exhausted;
-
 #endif /* __LIBBB_H__ */
diff --git a/libbb/messages.c b/libbb/messages.c
deleted file mode 100644 (file)
index b9334c4..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * Copyright (C) 1999,2000 by Lineo, inc. and Erik Andersen
- * Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
-
-#include "libbb.h"
-
-const char * const memory_exhausted = "memory exhausted";
diff --git a/libbb/perror_msg.c b/libbb/perror_msg.c
deleted file mode 100644 (file)
index 8c57b0d..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * Utility routines.
- *
- * Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-#include "libbb.h"
-
-extern void perror_msg(const char *s, ...)
-{
-       va_list p;
-
-       va_start(p, s);
-       vperror_msg(s, p);
-       va_end(p);
-}
-
-
-/* END CODE */
-/*
-Local Variables:
-c-file-style: "linux"
-c-basic-offset: 4
-tab-width: 4
-End:
-*/
diff --git a/libbb/perror_msg_and_die.c b/libbb/perror_msg_and_die.c
deleted file mode 100644 (file)
index 9004925..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * Utility routines.
- *
- * Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-#include "libbb.h"
-
-extern void perror_msg_and_die(const char *s, ...)
-{
-       va_list p;
-
-       va_start(p, s);
-       vperror_msg(s, p);
-       va_end(p);
-       exit(EXIT_FAILURE);
-}
-
-
-/* END CODE */
-/*
-Local Variables:
-c-file-style: "linux"
-c-basic-offset: 4
-tab-width: 4
-End:
-*/
index 31c76d2..03a63bd 100644 (file)
@@ -185,7 +185,7 @@ extract_archive(FILE *src_stream, FILE *out_stream,
                                                goto cleanup;
                                        }
                                        archive_offset += file_entry->size;
-                                       copy_file_chunk(src_stream, dst_stream, file_entry->size);                      
+                                       *err = copy_file_chunk(src_stream, dst_stream, file_entry->size);                       
                                        fclose(dst_stream);
                                }
                                break;
@@ -194,7 +194,7 @@ extract_archive(FILE *src_stream, FILE *out_stream,
                                        if (mkdir(full_name, file_entry->mode) < 0) {
                                                if ((function & extract_quiet) != extract_quiet) {
                                                        *err = -1;
-                                                       perror_msg("%s: %s", __FUNCTION__, full_name);
+                                                       perror_msg("Cannot make dir %s", full_name);
                                                }
                                        }
                                }
@@ -641,7 +641,8 @@ deb_extract(const char *package_filename, FILE *out_stream,
        else if (extract_function & extract_data_tar_gz) {              
                ared_file = "data.tar.gz";
        } else {
-                fprintf(stderr, "no file specified to extract -- extract_function=%x\n", extract_function);
+                opkg_msg(ERROR, "Internal error: extract_function=%x\n",
+                               extract_function);
                *err = -1;
                goto cleanup;
         }
@@ -668,7 +669,6 @@ deb_extract(const char *package_filename, FILE *out_stream,
                                /* open a stream of decompressed data */
                                uncompressed_stream = gz_open(deb_stream, &gunzip_pid);
                                if (uncompressed_stream == NULL) {
-                                       printf("%s: %d\n", __FUNCTION__, __LINE__);
                                        *err = -1;
                                        goto cleanup;
                                }
index 7ff07a5..e0a2388 100644 (file)
@@ -57,9 +57,6 @@ static unsigned long *crc_table = NULL;
 
 static unsigned long crc; /* shift register contents */
 
-/* Return codes from gzip */
-static const int ERROR = 1;
-
 /*
  * window size--must be a power of two, and
  *  at least 32K for zip's deflate method 
@@ -100,7 +97,7 @@ static const unsigned short mask_bits[] = {
 static void abort_gzip()
 {
        error_msg("gzip aborted\n");
-       _exit(ERROR);
+       _exit(-1);
 }
 
 static void make_crc_table()
@@ -975,8 +972,7 @@ extern int unzip(FILE *l_in_file, FILE *l_out_file)
        }
 
        if (method < 0) {
-               printf("it failed\n");
-               return(exit_code);              /* error message already emitted */
+               return(exit_code);
        }
 
        make_crc_table();
@@ -987,7 +983,7 @@ extern int unzip(FILE *l_in_file, FILE *l_out_file)
                int res = inflate();
 
                if (res == 3) {
-                       error_msg(memory_exhausted);
+                       perror_msg("inflate");
                        exit_code = 1;
                } else if (res != 0) {
                        error_msg("invalid compressed data--format violated");
diff --git a/libbb/verror_msg.c b/libbb/verror_msg.c
deleted file mode 100644 (file)
index 21cde20..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * Utility routines.
- *
- * Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-#include "libbb.h"
-
-extern void verror_msg(const char *s, va_list p)
-{
-       fflush(stdout);
-       fprintf(stderr, "%s: ", applet_name);
-       vfprintf(stderr, s, p);
-}
-
-
-/* END CODE */
-/*
-Local Variables:
-c-file-style: "linux"
-c-basic-offset: 4
-tab-width: 4
-End:
-*/
diff --git a/libbb/vperror_msg.c b/libbb/vperror_msg.c
deleted file mode 100644 (file)
index 7da5bae..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * Utility routines.
- *
- * Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-#include "libbb.h"
-
-extern void vperror_msg(const char *s, va_list p)
-{
-       int err=errno;
-       if(s == 0) s = "";
-       verror_msg(s, p);
-       if (*s) s = ": ";
-       fprintf(stderr, "%s%s\n", s, strerror(err));
-}
-
-
-/* END CODE */
-/*
-Local Variables:
-c-file-style: "linux"
-c-basic-offset: 4
-tab-width: 4
-End:
-*/
index c12b282..4374048 100644 (file)
@@ -30,7 +30,7 @@ extern void *xmalloc(size_t size)
 {
        void *ptr = malloc(size);
        if (ptr == NULL && size != 0)
-               error_msg_and_die(memory_exhausted);
+               perror_msg_and_die("malloc");
        return ptr;
 }
 
@@ -38,7 +38,7 @@ extern void *xrealloc(void *ptr, size_t size)
 {
        ptr = realloc(ptr, size);
        if (ptr == NULL && size != 0)
-               error_msg_and_die(memory_exhausted);
+               perror_msg_and_die("realloc");
        return ptr;
 }
 
@@ -46,7 +46,7 @@ extern void *xcalloc(size_t nmemb, size_t size)
 {
        void *ptr = calloc(nmemb, size);
        if (ptr == NULL && nmemb != 0 && size != 0)
-               error_msg_and_die(memory_exhausted);
+               perror_msg_and_die("calloc");
        return ptr;
 }
 
@@ -59,7 +59,7 @@ extern char * xstrdup (const char *s) {
        t = strdup (s);
 
        if (t == NULL)
-               error_msg_and_die(memory_exhausted);
+               perror_msg_and_die("strdup");
 
        return t;
 }
index 932e487..5b0504c 100644 (file)
@@ -24,7 +24,7 @@ extern char *xreadlink(const char *path)
                buf = xrealloc(buf, bufsize += GROWBY);
                readsize = readlink(path, buf, bufsize); /* 1st try */
                if (readsize == -1) {
-                   perror_msg("%s:%s", applet_name, path);
+                   perror_msg("%s", path);
                    return NULL;
                }
        }           
index d860be7..13d4960 100644 (file)
@@ -6,9 +6,9 @@ libopkg_include_HEADERS= opkg.h
 
 
 opkg_libcore_sources = args.c args.h libopkg.c libopkg.h\
-                   user.c user.h \
-                   opkg.c opkg.h includes.h \
-                   opkg_error.h opkg_defines.h
+                   includes.h \
+                   opkg.c opkg.h \
+                   opkg_defines.h
 opkg_cmd_sources = opkg_cmd.c opkg_cmd.h \
                   opkg_configure.c opkg_configure.h \
                   opkg_download.c opkg_download.h \
index 6b177c6..ffc6db0 100644 (file)
@@ -34,7 +34,7 @@ void active_list_init(struct active_list *ptr) {
 struct active_list * active_list_next(struct active_list *head, struct active_list *ptr) {
     struct active_list *next=NULL;
     if ( !head ) {
-        fprintf(stderr, "active_list_next head = %p, ptr = %p invalid value!!\n", head, ptr);
+        opkg_msg(ERROR, "Internal error: head=%p, ptr=%p\n", head, ptr);
         return NULL;
     }
     if ( !ptr )
@@ -56,7 +56,7 @@ struct active_list * active_list_next(struct active_list *head, struct active_li
 struct active_list * active_list_prev(struct active_list *head, struct active_list *ptr) {
     struct active_list *prev=NULL;
     if ( !head ) {
-        fprintf(stderr, "active_list_prev head = %p, ptr = %p invalid value!!\n", head, ptr);
+        opkg_msg(ERROR, "Internal error: head=%p, ptr=%p\n", head, ptr);
         return NULL;
     }
     if ( !ptr )
@@ -119,7 +119,7 @@ void active_list_add(struct active_list *head, struct active_list *node) {
     node->depended  = head;
 }
 
-struct active_list * active_list_head_new() {
+struct active_list * active_list_head_new(void) {
     struct active_list * head = xcalloc(1, sizeof(struct active_list));
     active_list_init(head);
     return head;
index 70d2af8..c9d90c0 100644 (file)
@@ -27,7 +27,7 @@ struct active_list {
 };
 
 
-struct active_list * active_list_head_new();
+struct active_list * active_list_head_new(void);
 void active_list_head_delete(struct active_list *);
 void active_list_init(struct active_list *ptr);
 void active_list_clear(struct active_list *head);
index d5e379c..bc2fb61 100644 (file)
 #include "args.h"
 #include "sprintf_alloc.h"
 #include "libbb/libbb.h"
+#include "opkg_conf.h"
 
 static void print_version(void);
 
 enum long_args_opt
 {
-     ARGS_OPT_FORCE_DEFAULTS = 129,
-     ARGS_OPT_FORCE_MAINTAINER, 
+     ARGS_OPT_FORCE_MAINTAINER = 129, 
      ARGS_OPT_FORCE_DEPENDS,
      ARGS_OPT_FORCE_OVERWRITE,
      ARGS_OPT_FORCE_DOWNGRADE,
@@ -42,7 +42,6 @@ enum long_args_opt
      ARGS_OPT_FORCE_SPACE,
      ARGS_OPT_NOACTION,
      ARGS_OPT_NODEPS,
-     ARGS_OPT_MULTIPLE_PROVIDERS,
      ARGS_OPT_AUTOREMOVE,
      ARGS_OPT_CACHE,
 };
@@ -55,38 +54,12 @@ void args_init(args_t *args)
 
      sprintf_alloc(&args->conf_file, "%s/%s", OPKGETCDIR,
                   ARGS_DEFAULT_CONF_FILE_NAME);
-
-     args->force_defaults = ARGS_DEFAULT_FORCE_DEFAULTS;
-     args->force_maintainer = ARGS_DEFAULT_FORCE_MAINTAINER;
-     args->force_depends = ARGS_DEFAULT_FORCE_DEPENDS;
-     args->force_overwrite = ARGS_DEFAULT_FORCE_OVERWRITE;
-     args->force_downgrade = ARGS_DEFAULT_FORCE_DOWNGRADE;
-     args->force_reinstall = ARGS_DEFAULT_FORCE_REINSTALL;
-     args->force_removal_of_dependent_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES;
-     args->force_removal_of_essential_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES;
-     args->autoremove = ARGS_DEFAULT_AUTOREMOVE;
-     args->noaction = ARGS_DEFAULT_NOACTION;
-     args->nodeps = ARGS_DEFAULT_NODEPS;
-     args->verbosity = ARGS_DEFAULT_VERBOSITY;
-     args->offline_root = ARGS_DEFAULT_OFFLINE_ROOT;
-     args->offline_root_path = ARGS_DEFAULT_OFFLINE_ROOT_PATH;
-     args->offline_root_pre_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD;
-     args->offline_root_post_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD;
-     args->multiple_providers = 0;
-     args->nocheckfordirorfile = 0;
-     args->noreadfeedsfile = 0;
+     conf->verbosity = ARGS_DEFAULT_VERBOSITY;
 }
 
 void args_deinit(args_t *args)
 {
-     free (args->offline_root);
-     free (args->offline_root_path);
-     free (args->offline_root_pre_script_cmd);
-     free (args->offline_root_post_script_cmd);
-
      free (args->dest);
-     free (args->tmp_dir);
-     free (args->cache);
      free(args->conf_file);
      args->conf_file = NULL;
 }
@@ -103,10 +76,8 @@ int args_parse(args_t *args, int argc, char *argv[])
          {"conf-file", 1, 0, 'f'},
          {"conf", 1, 0, 'f'},
          {"dest", 1, 0, 'd'},
-         {"force-defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
-         {"force_defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
-          {"force-maintainer", 0, 0, ARGS_OPT_FORCE_MAINTAINER}, 
-          {"force_maintainer", 0, 0, ARGS_OPT_FORCE_MAINTAINER}, 
+          {"force-maintainer", 0, 0, ARGS_OPT_FORCE_MAINTAINER},
+          {"force_maintainer", 0, 0, ARGS_OPT_FORCE_MAINTAINER},
          {"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
          {"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
          {"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
@@ -127,14 +98,10 @@ int args_parse(args_t *args, int argc, char *argv[])
           ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
          {"force_removal_of_essential_packages", 0, 0,
           ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
-         {"multiple-providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
-         {"multiple_providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
          {"noaction", 0, 0, ARGS_OPT_NOACTION},
          {"nodeps", 0, 0, ARGS_OPT_NODEPS},
          {"offline", 1, 0, 'o'},
          {"offline-root", 1, 0, 'o'},
-         {"offline-path", 1, 0, 'p'},
-         {"offline-root-path", 1, 0, 'p'},
          {"test", 0, 0, ARGS_OPT_NOACTION},
          {"tmp-dir", 1, 0, 't'},
          {"tmp_dir", 1, 0, 't'},
@@ -150,7 +117,7 @@ int args_parse(args_t *args, int argc, char *argv[])
 
          switch (c) {
          case 'A':
-              args->query_all = 1;
+              conf->query_all = 1;
               break;
          case 'd':
               args->dest = xstrdup(optarg);
@@ -160,68 +127,59 @@ int args_parse(args_t *args, int argc, char *argv[])
               args->conf_file = xstrdup(optarg);
               break;
          case 'o':
-              args->offline_root = xstrdup(optarg);
-              break;
-         case 'p':
-              args->offline_root_path = xstrdup(optarg);
+              conf->offline_root = xstrdup(optarg);
               break;
          case 't':
-              args->tmp_dir = xstrdup(optarg);
+              conf->tmp_dir = xstrdup(optarg);
               break;
          case 'v':
               print_version();
               exit(0);
          case 'V':
-              args->verbosity = atoi(optarg);
+              conf->verbosity = atoi(optarg);
               break;
          case ARGS_OPT_AUTOREMOVE:
-              args->autoremove = 1;
+              conf->autoremove = 1;
               break;
          case ARGS_OPT_CACHE:
-              free(args->cache);
-              args->cache = xstrdup(optarg);
-              break;
-         case ARGS_OPT_FORCE_DEFAULTS:
-              args->force_defaults = 1;
+              free(conf->cache);
+              conf->cache = xstrdup(optarg);
               break;
           case ARGS_OPT_FORCE_MAINTAINER:
-               args->force_maintainer = 1;
+               conf->force_maintainer = 1;
                break;
          case ARGS_OPT_FORCE_DEPENDS:
-              args->force_depends = 1;
+              conf->force_depends = 1;
               break;
          case ARGS_OPT_FORCE_OVERWRITE:
-              args->force_overwrite = 1;
+              conf->force_overwrite = 1;
               break;
          case ARGS_OPT_FORCE_DOWNGRADE:
-              args->force_downgrade = 1;
+              conf->force_downgrade = 1;
               break;
          case ARGS_OPT_FORCE_REINSTALL:
-              args->force_reinstall = 1;
+              conf->force_reinstall = 1;
               break;
          case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES:
-              args->force_removal_of_essential_packages = 1;
+              conf->force_removal_of_essential_packages = 1;
               break;
          case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES:
-              args->force_removal_of_dependent_packages = 1;
+              conf->force_removal_of_dependent_packages = 1;
               break;
          case ARGS_OPT_FORCE_SPACE:
-              args->force_space = 1;
-              break;
-         case ARGS_OPT_MULTIPLE_PROVIDERS:
-              args->multiple_providers = 1;
+              conf->force_space = 1;
               break;
          case ARGS_OPT_NODEPS:
-              args->nodeps = 1;
+              conf->nodeps = 1;
               break;
          case ARGS_OPT_NOACTION:
-              args->noaction = 1;
+              conf->noaction = 1;
               break;
          case ':':
-              parse_err++;
+              parse_err = -1;
               break;
          case '?':
-              parse_err++;
+              parse_err = -1;
               break;
          default:
               printf("Confusion: getopt_long returned %d\n", c);
@@ -229,13 +187,13 @@ int args_parse(args_t *args, int argc, char *argv[])
      }
     
      if (parse_err) {
-         return -parse_err;
+         return parse_err;
      } else {
          return optind;
      }
 }
 
-void args_usage(char *complaint)
+void args_usage(const char *complaint)
 {
      if (complaint) {
          printf("opkg: %s\n", complaint);
@@ -291,11 +249,10 @@ void args_usage(char *complaint)
      printf("                          directory name in a pinch).\n");
      printf("\t-o <dir>                Use <dir> as the root directory for\n");
      printf("\t--offline-root <dir>    offline installation of packages.\n");
-     printf("\t--offline-path <path>   $PATH for postinsts scripts in offline mode\n");
 
      printf("\nForce Options:\n");
      printf("\t--force-depends         Install/remove despite failed dependences\n");
-     printf("\t--force-defaults        Use default options for questions asked by opkg\n");
+     printf("\t--force-maintainer      Overwrite preexisting config files\n");
      printf("\t--force-reinstall       Reinstall package(s)\n");
      printf("\t--force-overwrite       Overwrite files from other package(s)\n");
      printf("\t--force-downgrade       Allow opkg to downgrade packages\n");
index 7992844..176d354 100644 (file)
@@ -22,57 +22,20 @@ struct args
 {
     char *conf_file;
     char *dest;
-    char *tmp_dir;
-    int force_defaults;
-    int force_maintainer;
-    int force_depends;
-    int force_overwrite;
-    int force_downgrade;
-    int force_reinstall;
-    int force_removal_of_essential_packages;
-    int force_removal_of_dependent_packages;
-    int force_space;
-    int noaction;
-    int nodeps;
-    int multiple_providers;
-    int query_all;
-    int verbosity;
+
     int nocheckfordirorfile;
     int noreadfeedsfile;
-    int autoremove;
-    char *offline_root;
-    char *offline_root_path;
-    char *offline_root_pre_script_cmd;
-    char *offline_root_post_script_cmd;
-    char *cache;
 };
 typedef struct args args_t;
 
 #define ARGS_DEFAULT_CONF_FILE_DIR OPKGETCDIR"/opkg"
 #define ARGS_DEFAULT_CONF_FILE_NAME "opkg.conf"
 #define ARGS_DEFAULT_DEST NULL
-#define ARGS_DEFAULT_FORCE_DEFAULTS 0
-#define ARGS_DEFAULT_FORCE_MAINTAINER 0 
-#define ARGS_DEFAULT_FORCE_DEPENDS 0
-#define ARGS_DEFAULT_FORCE_OVERWRITE 0 
-#define ARGS_DEFAULT_FORCE_DOWNGRADE 0 
-#define ARGS_DEFAULT_FORCE_REINSTALL 0
-#define ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES 0
-#define ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES 0
-#define ARGS_DEFAULT_FORCE_SPACE 0
-#define ARGS_DEFAULT_OFFLINE_ROOT NULL
-#define ARGS_DEFAULT_OFFLINE_ROOT_PATH NULL
-#define ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD NULL
-#define ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD NULL
-#define ARGS_DEFAULT_NOACTION 0
-#define ARGS_DEFAULT_NODEPS 0
-#define ARGS_DEFAULT_VERBOSE_WGET 0
 #define ARGS_DEFAULT_VERBOSITY 1
-#define ARGS_DEFAULT_AUTOREMOVE 0
 
 void args_init(args_t *args);
 void args_deinit(args_t *args);
 int args_parse(args_t *args, int argc, char *argv[]);
-void args_usage(char *complaint);
+void args_usage(const char *complaint);
 
 #endif
index 4bedf73..984a191 100644 (file)
@@ -35,7 +35,7 @@ void conffile_deinit(conffile_t *conffile)
     nv_pair_deinit(conffile);
 }
 
-int conffile_has_been_modified(opkg_conf_t *conf, conffile_t *conffile)
+int conffile_has_been_modified(conffile_t *conffile)
 {
     char *md5sum;
     char *filename = conffile->name;
@@ -43,17 +43,17 @@ int conffile_has_been_modified(opkg_conf_t *conf, conffile_t *conffile)
     int ret = 1;
 
     if (conffile->value == NULL) {
-        opkg_message(conf, OPKG_NOTICE, "%s: conffile %s has no md5sum\n", __FUNCTION__, conffile->name);
+        opkg_msg(NOTICE, "Conffile %s has no md5sum.\n", conffile->name);
         return 1;
     }
 
-    root_filename = root_filename_alloc(conf, filename);
+    root_filename = root_filename_alloc(filename);
 
     md5sum = file_md5sum_alloc(root_filename);
 
     if (md5sum && (ret = strcmp(md5sum, conffile->value))) {
-      opkg_message(conf, OPKG_INFO, "%s: conffile %s: \t\nold md5=%s \t\nnew md5=%s\n", __FUNCTION__,
-              conffile->name, md5sum, conffile->value);
+        opkg_msg(INFO, "Conffile %s:\n\told md5=%s\n\tnew md5=%s\n",
+               conffile->name, md5sum, conffile->value);
     }
 
     free(root_filename);
index 68ba3dc..5031835 100644 (file)
@@ -25,7 +25,7 @@ typedef struct nv_pair conffile_t;
 
 int conffile_init(conffile_t *conffile, const char *file_name, const char *md5sum);
 void conffile_deinit(conffile_t *conffile);
-int conffile_has_been_modified(struct opkg_conf *conf, conffile_t *conffile);
+int conffile_has_been_modified(conffile_t *conffile);
 
 #endif
 
index e625984..f5519c8 100644 (file)
@@ -63,9 +63,9 @@ char *
 file_read_line_alloc(FILE *fp)
 {
        char buf[BUFSIZ];
-       int buf_len;
+       unsigned int buf_len;
        char *line = NULL;
-       int line_size = 0;
+       unsigned int line_size = 0;
        int got_nl = 0;
 
        buf[0] = '\0';
@@ -105,8 +105,8 @@ file_move(const char *src, const char *dest)
                        if (err == 0)
                                unlink(src);
                } else {
-                       fprintf(stderr, "%s: rename(%s, %s): %s\n",
-                               __FUNCTION__, src, dest, strerror(errno));
+                       opkg_perror(ERROR, "Failed to rename %s to %s",
+                               src, dest);
                }
        }
 
@@ -120,8 +120,8 @@ file_copy(const char *src, const char *dest)
 
        err = copy_file(src, dest, FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS);
        if (err)
-               fprintf(stderr, "%s: copy_file(%s, %s)\n",
-                               __FUNCTION__, src, dest);
+               opkg_msg(ERROR, "Failed to copy file %s to %s.\n",
+                               src, dest);
 
        return err;
 }
@@ -153,16 +153,14 @@ char *file_md5sum_alloc(const char *file_name)
 
     file = fopen(file_name, "r");
     if (file == NULL) {
-       fprintf(stderr, "%s: Failed to open file %s: %s\n",
-               __FUNCTION__, file_name, strerror(errno));
+       opkg_perror(ERROR, "Failed to open file %s", file_name);
        free(md5sum_hex);
        return NULL;
     }
 
     err = md5_stream(file, md5sum_bin);
     if (err) {
-       fprintf(stderr, "%s: ERROR computing md5sum for %s: %s\n",
-               __FUNCTION__, file_name, strerror(err));
+       opkg_msg(ERROR, "Could't compute md5sum for %s.\n", file_name);
        fclose(file);
        free(md5sum_hex);
        return NULL;
@@ -202,16 +200,14 @@ char *file_sha256sum_alloc(const char *file_name)
 
     file = fopen(file_name, "r");
     if (file == NULL) {
-       fprintf(stderr, "%s: Failed to open file %s: %s\n",
-               __FUNCTION__, file_name, strerror(errno));
+       opkg_perror(ERROR, "Failed to open file %s", file_name);
        free(sha256sum_hex);
        return NULL;
     }
 
     err = sha256_stream(file, sha256sum_bin);
     if (err) {
-       fprintf(stderr, "%s: ERROR computing sha256sum for %s: %s\n",
-               __FUNCTION__, file_name, strerror(err));
+       opkg_msg(ERROR, "Could't compute sha256sum for %s.\n", file_name);
        fclose(file);
        free(sha256sum_hex);
        return NULL;
@@ -241,12 +237,12 @@ rm_r(const char *path)
 
        dir = opendir(path);
        if (dir == NULL) {
-               perror_msg("%s: opendir(%s)", __FUNCTION__, path);
+               opkg_perror(ERROR, "Failed to open dir %s", path);
                return -1;
        }
 
        if (fchdir(dirfd(dir)) == -1) {
-               perror_msg("%s: fchdir(%s)", __FUNCTION__, path);
+               opkg_perror(ERROR, "Failed to change to dir %s", path);
                closedir(dir);
                return -1;
        }
@@ -255,8 +251,8 @@ rm_r(const char *path)
                errno = 0;
                if ((dent = readdir(dir)) == NULL) {
                        if (errno) {
-                               perror_msg("%s: readdir(%s)",
-                                               __FUNCTION__, path);
+                               opkg_perror(ERROR, "Failed to read dir %s",
+                                               path);
                                ret = -1;
                        }
                        break;
@@ -275,8 +271,8 @@ rm_r(const char *path)
                {
                        struct stat st;
                        if ((ret = lstat(dent->d_name, &st)) == -1) {
-                               perror_msg("%s: lstat(%s)",
-                                               __FUNCTION__, dent->d_name);
+                               opkg_perror(ERROR, "Failed to lstat %s",
+                                               dent->d_name);
                                break;
                        }
                        if (S_ISDIR(st.st_mode)) {
@@ -287,25 +283,24 @@ rm_r(const char *path)
                }
 
                if ((ret = unlink(dent->d_name)) == -1) {
-                       perror_msg("%s: unlink(%s)",
-                                       __FUNCTION__, dent->d_name);
+                       opkg_perror(ERROR, "Failed to unlink %s", dent->d_name);
                        break;
                }
        }
 
        if (chdir("..") == -1) {
                ret = -1;
-               perror_msg("%s: chdir(%s/..)", __FUNCTION__, path);
+               opkg_perror(ERROR, "Failed to change to dir %s/..", path);
        }
 
        if (rmdir(path) == -1 ) {
                ret = -1;
-               perror_msg("%s: rmdir(%s)", __FUNCTION__, path);
+               opkg_perror(ERROR, "Failed to remove dir %s", path);
        }
 
        if (closedir(dir) == -1) {
                ret = -1;
-               perror_msg("%s: closedir(%s)", __FUNCTION__, path);
+               opkg_perror(ERROR, "Failed to close dir %s", path);
        }
 
        return ret;
index 2d42d91..f3705ea 100644 (file)
@@ -46,8 +46,7 @@ void
 hash_table_init(const char *name, hash_table_t *hash, int len)
 {
        if (hash->entries != NULL) {
-               fprintf(stderr, "ERROR: %s called on a non empty hash table\n",
-                               __FUNCTION__);
+               opkg_msg(ERROR, "Internal error: non empty hash table.\n");
                return;
        }
 
@@ -114,7 +113,6 @@ void *hash_table_get(hash_table_t *hash, const char *key)
     if (hash_entry->key) 
     {
       if (strcmp(key, hash_entry->key) == 0) {
-         // opkg_message(NULL, OPKG_DEBUG, "Function: %s. Key found for '%s' \n", __FUNCTION__, key);
         hash->n_hits++;
         return hash_entry->data;
       }
index 3121984..f6fc251 100644 (file)
 #include "file_util.h"
 
 #include "opkg_message.h"
-#include "opkg_error.h"
 
 /* This is used for backward compatibility */
 int
 opkg_op (int argc, char *argv[])
 {
-       int err, optind;
+       int err, opts;
        args_t args;
        char *cmd_name;
        opkg_cmd_t *cmd;
-       opkg_conf_t opkg_conf;
 
        args_init (&args);
 
-       optind = args_parse (&args, argc, argv);
-       if (optind == argc || optind < 0)
+       opts = args_parse (&args, argc, argv);
+       if (opts == argc || opts < 0)
        {
                args_usage ("opkg must have one sub-command argument");
        }
 
-       cmd_name = argv[optind++];
-/* Pigi: added a flag to disable the checking of structures if the command does not need to 
-         read anything from there.
-*/
+       cmd_name = argv[opts++];
+
         if ( !strcmp(cmd_name,"print-architecture") ||
              !strcmp(cmd_name,"print_architecture") ||
              !strcmp(cmd_name,"print-installation-architecture") ||
              !strcmp(cmd_name,"print_installation_architecture") )
            args.nocheckfordirorfile = 1;
 
-/* Pigi: added a flag to disable the reading of feed files  if the command does not need to 
-         read anything from there.
-*/
         if ( !strcmp(cmd_name,"flag") ||
              !strcmp(cmd_name,"configure") ||
              !strcmp(cmd_name,"remove") ||
@@ -69,8 +62,17 @@ opkg_op (int argc, char *argv[])
              !strcmp(cmd_name,"status") )
            args.noreadfeedsfile = 1;
 
+       cmd = opkg_cmd_find (cmd_name);
+       if (cmd == NULL)
+       {
+               fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
+                        cmd_name);
+               args_usage (NULL);
+       }
 
-       err = opkg_conf_init (&opkg_conf, &args);
+       conf->pfm = cmd->pfm;
+
+       err = opkg_conf_init (&args);
        args_deinit (&args);
        if (err)
        {
@@ -79,28 +81,20 @@ opkg_op (int argc, char *argv[])
                return err;
        }
 
-       cmd = opkg_cmd_find (cmd_name);
-       if (cmd == NULL)
-       {
-               fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
-                        cmd_name);
-               args_usage (NULL);
-       }
-
-       if (cmd->requires_args && optind == argc)
+       if (cmd->requires_args && opts == argc)
        {
                fprintf (stderr,
                         "%s: the ``%s'' command requires at least one argument\n",
-                        __FUNCTION__, cmd_name);
+                        argv[0], cmd_name);
                args_usage (NULL);
        }
 
-       err = opkg_cmd_exec (cmd, &opkg_conf, argc - optind, (const char **) (argv + optind), NULL);
+       err = opkg_cmd_exec (cmd, argc - opts, (const char **) (argv + opts));
 
 #ifdef HAVE_CURL
        opkg_curl_cleanup();
 #endif
-       opkg_conf_deinit (&opkg_conf);
+       opkg_conf_deinit ();
 
        return err;
 }
index 72d3640..01ce6f0 100644 (file)
@@ -28,7 +28,6 @@
 
 #include "args.h"
 #include "pkg.h"
-#include "user.h"
 
 extern int opkg_op(int argc, char *argv[]); /* opkglib.c */
 
index 51989f7..24469ba 100644 (file)
 #include "opkg_download.h"
 #include "opkg_remove.h"
 #include "opkg_upgrade.h"
-#include "opkg_error.h"
 
 #include "sprintf_alloc.h"
 #include "file_util.h"
 
 #include <libbb/libbb.h>
 
-struct _opkg_t
-{
-  args_t *args;
-  opkg_conf_t *conf;
-  opkg_option_t *options;
-};
+args_t *args;
 
 #define opkg_assert(expr) if (!(expr)) { \
     printf ("opkg: file %s: line %d (%s): Assertation '%s' failed",\
             __FILE__, __LINE__, __PRETTY_FUNCTION__, # expr); abort (); }
 
-#define progress(d, p) d.percentage = p; if (progress_callback) progress_callback (opkg, &d, user_data);
-#define SSTRCMP(x,y) (x && y) ? strcmp (x, y) : 0
+#define progress(d, p) d.percentage = p; if (progress_callback) progress_callback (&d, user_data);
 
 /** Private Functions ***/
 
@@ -67,16 +60,15 @@ pkg_t_to_opkg_package_t (pkg_t *old)
     new->repository = xstrdup(old->src->name);
   new->description = xstrdup(old->description);
   new->tags = xstrdup(old->tags);
-  new->url = xstrdup(old->url);
 
-  new->size = (old->size) ? atoi (old->size) : 0;
+  new->size = old->size;
   new->installed = (old->state_status == SS_INSTALLED);
 
   return new;
 }
 
 static int
-opkg_configure_packages(opkg_conf_t *conf, char *pkg_name)
+opkg_configure_packages(char *pkg_name)
 {
   pkg_vec_t *all;
   int i;
@@ -84,7 +76,7 @@ opkg_configure_packages(opkg_conf_t *conf, char *pkg_name)
   int r, err = 0;
 
   all = pkg_vec_alloc ();
-  pkg_hash_fetch_available (&conf->pkg_hash, all);
+  pkg_hash_fetch_available (all);
 
   for (i = 0; i < all->len; i++)
   {
@@ -95,7 +87,7 @@ opkg_configure_packages(opkg_conf_t *conf, char *pkg_name)
 
     if (pkg->state_status == SS_UNPACKED)
     {
-      r = opkg_configure (conf, pkg);
+      r = opkg_configure (pkg);
       if (r == 0)
       {
         pkg->state_status = SS_INSTALLED;
@@ -118,7 +110,6 @@ struct _curl_cb_data
 {
   opkg_progress_callback_t cb;
   opkg_progress_data_t *progress_data;
-  opkg_t *opkg;
   void *user_data;
   int start_range;
   int finish_range;
@@ -146,8 +137,7 @@ curl_progress_cb (struct _curl_cb_data *cb_data,
   progress = cb_data->start_range + (d / t * ((cb_data->finish_range - cb_data->start_range)));
   cb_data->progress_data->percentage = progress;
 
-  (cb_data->cb)(cb_data->opkg,
-                cb_data->progress_data,
+  (cb_data->cb)(cb_data->progress_data,
                 cb_data->user_data);
 
   return 0;
@@ -175,127 +165,56 @@ opkg_package_free (opkg_package_t *p)
   free (p->architecture);
   free (p->description);
   free (p->tags);
-  free (p->url);
   free (p->repository);
 
   free (p);
 }
 
-opkg_t *
+int
 opkg_new ()
 {
-  opkg_t *opkg;
   int err;
 
-  opkg = xcalloc(1, sizeof (opkg_t));
-
-  opkg->args = xcalloc(1, sizeof (args_t));
-  args_init (opkg->args);
+  args = xcalloc(1, sizeof (args_t));
+  args_init (args);
 
-  opkg->conf = xcalloc(1, sizeof (opkg_conf_t));
-  err = opkg_conf_init (opkg->conf, opkg->args);
+  err = opkg_conf_init (args);
   if (err)
   {
-    free (opkg->conf);
-    free (opkg->args);
-    free (opkg);
-    return NULL;
+    args_deinit (args);
+    free (args);
+    return -1;
   }
 
-  opkg_init_options_array (opkg->conf, &opkg->options);
-  return opkg;
+  return 0;
 }
 
 void
-opkg_free (opkg_t *opkg)
+opkg_free (void)
 {
-  opkg_assert (opkg != NULL);
-
 #ifdef HAVE_CURL
   opkg_curl_cleanup();
 #endif
-  opkg_conf_deinit (opkg->conf);
-  args_deinit (opkg->args);
-  free (opkg->options);
-  free (opkg->args);
-  free (opkg->conf);
-  free (opkg);
+  opkg_conf_deinit ();
+  args_deinit (args);
+  free (args);
 }
 
 int
-opkg_re_read_config_files (opkg_t *opkg)
+opkg_re_read_config_files (void)
 {
-  args_t *a;
-  opkg_conf_t *c;
-
-  opkg_assert (opkg != NULL);
-
-  a = opkg->args;
-  c = opkg->conf;
-
-  /* Unfortunatly, the easiest way to re-read the config files right now is to
-   * throw away opkg->conf and start again */
-
-  /* copy the settings we need to keep */
-  a->autoremove = c->autoremove;
-  a->force_depends = c->force_depends;
-  a->force_defaults = c->force_defaults;
-  a->force_maintainer = c->force_maintainer;
-  a->force_overwrite = c->force_overwrite;
-  a->force_downgrade = c->force_downgrade;
-  a->force_reinstall = c->force_reinstall;
-  a->force_removal_of_dependent_packages = c->force_removal_of_dependent_packages;
-  a->force_removal_of_essential_packages = c->force_removal_of_essential_packages;
-  a->nodeps = c->nodeps;
-  a->noaction = c->noaction;
-  a->query_all = c->query_all;
-  a->verbosity = c->verbosity;
-
-  if (c->offline_root)
-  {
-    if (a->offline_root) free (a->offline_root);
-    a->offline_root = xstrdup(c->offline_root);
-  }
-
-  if (c->offline_root_pre_script_cmd)
-  {
-    if (a->offline_root_pre_script_cmd) free (a->offline_root_pre_script_cmd);
-    a->offline_root_pre_script_cmd = xstrdup(c->offline_root_pre_script_cmd);
-  }
-
-  if (c->offline_root_post_script_cmd)
-  {
-    if (a->offline_root_post_script_cmd) free (a->offline_root_post_script_cmd);
-    a->offline_root_post_script_cmd = xstrdup(c->offline_root_post_script_cmd);
-  }
-
-  if (c->cache) {
-    if (a->cache)
-       free (a->cache);
-    a->cache = xstrdup(c->cache);
-  }
-
-  /* throw away old opkg_conf and start again */
-  opkg_conf_deinit (opkg->conf);
-  opkg_conf_init (opkg->conf, opkg->args);
-
-  free (opkg->options);
-  opkg_init_options_array (opkg->conf, &opkg->options);
-
-  return 0;
+  /* Unfortunately, the easiest way to re-read the config files right now is to
+   * throw away conf and start again */
+  opkg_free();
+  memset(conf, '\0', sizeof(opkg_conf_t));
+  return opkg_new();
 }
 
 void
-opkg_get_option (opkg_t *opkg, char *option, void **value)
+opkg_get_option (char *option, void **value)
 {
   int i = 0;
-  opkg_option_t *options;
-
-  opkg_assert (opkg != NULL);
-  opkg_assert (option != NULL);
-  opkg_assert (value != NULL);
-
-  options = opkg->options;
+  extern opkg_option_t options[];
 
   /* look up the option
    * TODO: this would be much better as a hash table
@@ -328,17 +247,14 @@ opkg_get_option (opkg_t *opkg, char *option, void **value)
 }
 
 void
-opkg_set_option (opkg_t *opkg, char *option, void *value)
+opkg_set_option (char *option, void *value)
 {
   int i = 0, found = 0;
-  opkg_option_t *options;
+  extern opkg_option_t options[];
 
-  opkg_assert (opkg != NULL);
   opkg_assert (option != NULL);
   opkg_assert (value != NULL);
 
-  options = opkg->options;
-
   /* look up the option
    * TODO: this would be much better as a hash table
    */
@@ -381,12 +297,11 @@ opkg_set_option (opkg_t *opkg, char *option, void *value)
 
 /**
  * @brief libopkg API: Install package
- * @param opkg Then opkg handler
  * @param package_name The name of package in which is going to install
  * @param progress_callback The callback function that report the status to caller. 
  */ 
 int
-opkg_install_package (opkg_t *opkg, const char *package_name, opkg_progress_callback_t progress_callback, void *user_data)
+opkg_install_package (const char *package_name, opkg_progress_callback_t progress_callback, void *user_data)
 {
   int err;
   char *stripped_filename;
@@ -396,22 +311,21 @@ opkg_install_package (opkg_t *opkg, const char *package_name, opkg_progress_call
   int i, ndepends;
   char **unresolved = NULL;
 
-  opkg_assert (opkg != NULL);
   opkg_assert (package_name != NULL);
 
   /* ... */
-  pkg_info_preinstall_check (opkg->conf);
+  pkg_info_preinstall_check ();
 
 
   /* check to ensure package is not already installed */
-  old = pkg_hash_fetch_installed_by_name(&opkg->conf->pkg_hash, package_name);
+  old = pkg_hash_fetch_installed_by_name(package_name);
   if (old)
   {
     /* XXX: Error: Package is already installed. */
     return OPKG_PACKAGE_ALREADY_INSTALLED;
   }
 
-  new = pkg_hash_fetch_best_installation_candidate_by_name(opkg->conf, package_name);
+  new = pkg_hash_fetch_best_installation_candidate_by_name(package_name);
   if (!new)
   {
     /* XXX: Error: Could not find package to install */
@@ -428,7 +342,7 @@ opkg_install_package (opkg_t *opkg, const char *package_name, opkg_progress_call
   /* find dependancies and download them */
   deps = pkg_vec_alloc ();
   /* this function does not return the original package, so we insert it later */
-  ndepends = pkg_hash_fetch_unsatisfied_dependencies (opkg->conf, new, deps, &unresolved);
+  ndepends = pkg_hash_fetch_unsatisfied_dependencies (new, deps, &unresolved);
   if (unresolved)
   {
     /* XXX: Error: Could not satisfy dependencies */
@@ -467,17 +381,16 @@ opkg_install_package (opkg_t *opkg, const char *package_name, opkg_progress_call
     if ( ! stripped_filename )
         stripped_filename = pkg->filename;
 
-    sprintf_alloc(&pkg->local_filename, "%s/%s", opkg->conf->tmp_dir, stripped_filename);
+    sprintf_alloc(&pkg->local_filename, "%s/%s", conf->tmp_dir, stripped_filename);
 
     cb_data.cb = progress_callback;
     cb_data.progress_data = &pdata;
-    cb_data.opkg = opkg;
     cb_data.user_data = user_data;
     /* 75% of "install" progress is for downloading */
     cb_data.start_range = 75 * i / deps->len;
     cb_data.finish_range = 75 * (i + 1) / deps->len;
 
-    err = opkg_download(opkg->conf, url, pkg->local_filename,
+    err = opkg_download(url, pkg->local_filename,
               (curl_progress_func) curl_progress_cb, &cb_data);
     free(url);
 
@@ -493,7 +406,7 @@ opkg_install_package (opkg_t *opkg, const char *package_name, opkg_progress_call
 
   /* clear depenacy checked marks, left by pkg_hash_fetch_unsatisfied_dependencies */
   all = pkg_vec_alloc ();
-  pkg_hash_fetch_available (&opkg->conf->pkg_hash, all);
+  pkg_hash_fetch_available (all);
   for (i = 0; i < all->len; i++)
   {
     all->pkgs[i]->parent->dependencies_checked = 0;
@@ -508,7 +421,7 @@ opkg_install_package (opkg_t *opkg, const char *package_name, opkg_progress_call
   progress (pdata, 75);
 
   /* unpack the package */
-  err = opkg_install_pkg(opkg->conf, new, 0);
+  err = opkg_install_pkg(new, 0);
 
   if (err)
   {
@@ -519,7 +432,7 @@ opkg_install_package (opkg_t *opkg, const char *package_name, opkg_progress_call
   progress (pdata, 75);
 
   /* run configure scripts, etc. */
-  err = opkg_configure_packages (opkg->conf, NULL);
+  err = opkg_configure_packages (NULL);
   if (err)
   {
     opkg_package_free (pdata.package);
@@ -527,8 +440,8 @@ opkg_install_package (opkg_t *opkg, const char *package_name, opkg_progress_call
   }
 
   /* write out status files and file lists */
-  opkg_conf_write_status_files (opkg->conf);
-  pkg_write_changed_filelists (opkg->conf);
+  opkg_conf_write_status_files ();
+  pkg_write_changed_filelists ();
 
   progress (pdata, 100);
   opkg_package_free (pdata.package);
@@ -536,19 +449,18 @@ opkg_install_package (opkg_t *opkg, const char *package_name, opkg_progress_call
 }
 
 int
-opkg_remove_package (opkg_t *opkg, const char *package_name, opkg_progress_callback_t progress_callback, void *user_data)
+opkg_remove_package (const char *package_name, opkg_progress_callback_t progress_callback, void *user_data)
 {
   int err;
   pkg_t *pkg = NULL;
   pkg_t *pkg_to_remove;
   opkg_progress_data_t pdata;
 
-  opkg_assert (opkg != NULL);
   opkg_assert (package_name != NULL);
 
-  pkg_info_preinstall_check (opkg->conf);
+  pkg_info_preinstall_check ();
 
-  pkg = pkg_hash_fetch_installed_by_name (&opkg->conf->pkg_hash, package_name);
+  pkg = pkg_hash_fetch_installed_by_name (package_name);
 
   if (pkg == NULL)
   {
@@ -569,25 +481,24 @@ opkg_remove_package (opkg_t *opkg, const char *package_name, opkg_progress_callb
   }
   progress (pdata, 25);
 
-  if (opkg->conf->restrict_to_default_dest)
+  if (conf->restrict_to_default_dest)
   {
-    pkg_to_remove = pkg_hash_fetch_installed_by_name_dest (&opkg->conf->pkg_hash,
-                                                           pkg->name,
-                                                           opkg->conf->default_dest);
+    pkg_to_remove = pkg_hash_fetch_installed_by_name_dest (pkg->name,
+                                                           conf->default_dest);
   }
   else
   {
-    pkg_to_remove = pkg_hash_fetch_installed_by_name (&opkg->conf->pkg_hash, pkg->name );
+    pkg_to_remove = pkg_hash_fetch_installed_by_name (pkg->name);
   }
 
 
   progress (pdata, 75);
 
-  err = opkg_remove_pkg (opkg->conf, pkg_to_remove, 0);
+  err = opkg_remove_pkg (pkg_to_remove, 0);
 
   /* write out status files and file lists */
-  opkg_conf_write_status_files (opkg->conf);
-  pkg_write_changed_filelists (opkg->conf);
+  opkg_conf_write_status_files ();
+  pkg_write_changed_filelists ();
 
 
   progress (pdata, 100);
@@ -596,24 +507,20 @@ opkg_remove_package (opkg_t *opkg, const char *package_name, opkg_progress_callb
 }
 
 int
-opkg_upgrade_package (opkg_t *opkg, const char *package_name, opkg_progress_callback_t progress_callback, void *user_data)
+opkg_upgrade_package (const char *package_name, opkg_progress_callback_t progress_callback, void *user_data)
 {
   int err;
   pkg_t *pkg;
   opkg_progress_data_t pdata;
 
-
-
-  opkg_assert (opkg != NULL);
   opkg_assert (package_name != NULL);
 
-  pkg_info_preinstall_check (opkg->conf);
+  pkg_info_preinstall_check ();
 
-  if (opkg->conf->restrict_to_default_dest)
+  if (conf->restrict_to_default_dest)
   {
-    pkg = pkg_hash_fetch_installed_by_name_dest (&opkg->conf->pkg_hash,
-                                                 package_name,
-                                                 opkg->conf->default_dest);
+    pkg = pkg_hash_fetch_installed_by_name_dest (package_name,
+                                                 conf->default_dest);
     if (pkg == NULL)
     {
       /* XXX: Error: Package not installed in default_dest */
@@ -622,8 +529,7 @@ opkg_upgrade_package (opkg_t *opkg, const char *package_name, opkg_progress_call
   }
   else
   {
-    pkg = pkg_hash_fetch_installed_by_name (&opkg->conf->pkg_hash,
-                                            package_name);
+    pkg = pkg_hash_fetch_installed_by_name (package_name);
   }
 
   if (!pkg)
@@ -636,7 +542,7 @@ opkg_upgrade_package (opkg_t *opkg, const char *package_name, opkg_progress_call
   pdata.package = pkg_t_to_opkg_package_t (pkg);
   progress (pdata, 0);
 
-  err = opkg_upgrade_pkg (opkg->conf, pkg);
+  err = opkg_upgrade_pkg (pkg);
   /* opkg_upgrade_pkg returns the error codes of opkg_install_pkg */
   if (err)
   {
@@ -645,15 +551,15 @@ opkg_upgrade_package (opkg_t *opkg, const char *package_name, opkg_progress_call
   }
   progress (pdata, 75);
 
-  err = opkg_configure_packages (opkg->conf, NULL);
+  err = opkg_configure_packages (NULL);
   if (err) {
     opkg_package_free (pdata.package);  
     return OPKG_UNKNOWN_ERROR;
   }
 
   /* write out status files and file lists */
-  opkg_conf_write_status_files (opkg->conf);
-  pkg_write_changed_filelists (opkg->conf);
+  opkg_conf_write_status_files ();
+  pkg_write_changed_filelists ();
 
   progress (pdata, 100);
   opkg_package_free (pdata.package);
@@ -661,7 +567,7 @@ opkg_upgrade_package (opkg_t *opkg, const char *package_name, opkg_progress_call
 }
 
 int
-opkg_upgrade_all (opkg_t *opkg, opkg_progress_callback_t progress_callback, void *user_data)
+opkg_upgrade_all (opkg_progress_callback_t progress_callback, void *user_data)
 {
   pkg_vec_t *installed;
   int err = 0;
@@ -672,13 +578,12 @@ opkg_upgrade_all (opkg_t *opkg, opkg_progress_callback_t progress_callback, void
   pdata.action = OPKG_INSTALL;
   pdata.package = NULL;
 
-  opkg_assert (opkg != NULL);
   progress (pdata, 0);
 
   installed = pkg_vec_alloc ();
-  pkg_info_preinstall_check (opkg->conf);
+  pkg_info_preinstall_check ();
 
-  pkg_hash_fetch_all_installed (&opkg->conf->pkg_hash, installed);
+  pkg_hash_fetch_all_installed (installed);
   for (i = 0; i < installed->len; i++)
   {
     pkg = installed->pkgs[i];
@@ -687,14 +592,14 @@ opkg_upgrade_all (opkg_t *opkg, opkg_progress_callback_t progress_callback, void
     progress (pdata, 99 * i / installed->len);
     opkg_package_free (pdata.package);
 
-    err += opkg_upgrade_pkg (opkg->conf, pkg);
+    err += opkg_upgrade_pkg (pkg);
   }
   pkg_vec_free (installed);
 
   if (err)
     return 1;
 
-  err = opkg_configure_packages (opkg->conf, NULL);
+  err = opkg_configure_packages (NULL);
   if (err)
     return 1;
 
@@ -704,7 +609,7 @@ opkg_upgrade_all (opkg_t *opkg, opkg_progress_callback_t progress_callback, void
 }
 
 int
-opkg_update_package_lists (opkg_t *opkg, opkg_progress_callback_t progress_callback, void *user_data)
+opkg_update_package_lists (opkg_progress_callback_t progress_callback, void *user_data)
 {
   char *tmp;
   int err, result = 0;
@@ -714,16 +619,14 @@ opkg_update_package_lists (opkg_t *opkg, opkg_progress_callback_t progress_callb
   int sources_list_count, sources_done;
   opkg_progress_data_t pdata;
 
-  opkg_assert (opkg != NULL);
-
   pdata.action = OPKG_DOWNLOAD;
   pdata.package = NULL;
   progress (pdata, 0);
 
   sprintf_alloc (&lists_dir, "%s",
-                 (opkg->conf->restrict_to_default_dest)
-                 ? opkg->conf->default_dest->lists_dir
-                 : opkg->conf->lists_dir);
+                 (conf->restrict_to_default_dest)
+                 ? conf->default_dest->lists_dir
+                 : conf->lists_dir);
 
   if (!file_is_dir (lists_dir))
   {
@@ -743,7 +646,7 @@ opkg_update_package_lists (opkg_t *opkg, opkg_progress_callback_t progress_callb
     }
   }
 
-  sprintf_alloc(&tmp, "%s/update-XXXXXX", opkg->conf->tmp_dir);
+  sprintf_alloc(&tmp, "%s/update-XXXXXX", conf->tmp_dir);
   if (mkdtemp (tmp) == NULL) {
     /* XXX: Error: could not create temporary file name */
     free (lists_dir);
@@ -754,12 +657,12 @@ opkg_update_package_lists (opkg_t *opkg, opkg_progress_callback_t progress_callb
   /* count the number of sources so we can give some progress updates */
   sources_list_count = 0;
   sources_done = 0;
-  list_for_each_entry(iter, &opkg->conf->pkg_src_list.head, node)
+  list_for_each_entry(iter, &conf->pkg_src_list.head, node)
   {
     sources_list_count++;
   }
 
-  list_for_each_entry(iter, &opkg->conf->pkg_src_list.head, node)
+  list_for_each_entry(iter, &conf->pkg_src_list.head, node)
   {
     char *url, *list_file_name = NULL;
 
@@ -784,12 +687,11 @@ opkg_update_package_lists (opkg_t *opkg, opkg_progress_callback_t progress_callb
 
       cb_data.cb = progress_callback;
       cb_data.progress_data = &pdata;
-      cb_data.opkg = opkg;
       cb_data.user_data = user_data;
       cb_data.start_range = 100 * sources_done / sources_list_count;
       cb_data.finish_range = 100 * (sources_done + 1) / sources_list_count;
 
-      err = opkg_download (opkg->conf, url, tmp_file_name, (curl_progress_func) curl_progress_cb, &cb_data);
+      err = opkg_download (url, tmp_file_name, (curl_progress_func) curl_progress_cb, &cb_data);
 
       if (err == 0)
       {
@@ -809,7 +711,7 @@ opkg_update_package_lists (opkg_t *opkg, opkg_progress_callback_t progress_callb
       free (tmp_file_name);
     }
     else
-      err = opkg_download (opkg->conf, url, list_file_name, NULL, NULL);
+      err = opkg_download (url, list_file_name, NULL, NULL);
 
     if (err)
     {
@@ -819,7 +721,7 @@ opkg_update_package_lists (opkg_t *opkg, opkg_progress_callback_t progress_callb
     free (url);
 
 #if defined(HAVE_GPGME) || defined(HAVE_OPENSSL)
-    if ( opkg->conf->check_signature ) {
+    if ( conf->check_signature ) {
         char *sig_file_name;
         /* download detached signitures to verify the package lists */
         /* get the url for the sig file */
@@ -835,7 +737,7 @@ opkg_update_package_lists (opkg_t *opkg, opkg_progress_callback_t progress_callb
         /* make sure there is no existing signature file */
         unlink (sig_file_name);
 
-        err = opkg_download (opkg->conf, url, sig_file_name, NULL, NULL);
+        err = opkg_download (url, sig_file_name, NULL, NULL);
         if (err)
         {
             /* XXX: Warning: Download failed */
@@ -843,7 +745,7 @@ opkg_update_package_lists (opkg_t *opkg, opkg_progress_callback_t progress_callb
         else
         {
             int err;
-            err = opkg_verify_file (opkg->conf, list_file_name, sig_file_name);
+            err = opkg_verify_file (list_file_name, sig_file_name);
             if (err == 0)
             {
                 /* XXX: Notice: Signature check passed */
@@ -872,23 +774,22 @@ opkg_update_package_lists (opkg_t *opkg, opkg_progress_callback_t progress_callb
   free (lists_dir);
 
   /* Now re-read the package lists to update package hash tables. */
-  opkg_re_read_config_files (opkg);
+  opkg_re_read_config_files ();
 
   return result;
 }
 
 
 int
-opkg_list_packages (opkg_t *opkg, opkg_package_callback_t callback, void *user_data)
+opkg_list_packages (opkg_package_callback_t callback, void *user_data)
 {
   pkg_vec_t *all;
   int i;
 
-  opkg_assert (opkg);
   opkg_assert (callback);
 
   all = pkg_vec_alloc ();
-  pkg_hash_fetch_available (&opkg->conf->pkg_hash, all);
+  pkg_hash_fetch_available (all);
   for (i = 0; i < all->len; i++)
   {
     pkg_t *pkg;
@@ -897,7 +798,7 @@ opkg_list_packages (opkg_t *opkg, opkg_package_callback_t callback, void *user_d
     pkg = all->pkgs[i];
 
     package = pkg_t_to_opkg_package_t (pkg);
-    callback (opkg, package, user_data);
+    callback (package, user_data);
     opkg_package_free (package);
   }
 
@@ -907,28 +808,26 @@ opkg_list_packages (opkg_t *opkg, opkg_package_callback_t callback, void *user_d
 }
 
 int
-opkg_list_upgradable_packages (opkg_t *opkg, opkg_package_callback_t callback, void *user_data)
+opkg_list_upgradable_packages (opkg_package_callback_t callback, void *user_data)
 {
     struct active_list *head;
     struct active_list *node;
     pkg_t *old=NULL, *new = NULL;
     static opkg_package_t* package=NULL;
 
-
-    opkg_assert (opkg);
     opkg_assert (callback);
 
     /* ensure all data is valid */
-    pkg_info_preinstall_check (opkg->conf);
+    pkg_info_preinstall_check ();
 
-    head  =  prepare_upgrade_list(opkg->conf);
+    head  =  prepare_upgrade_list();
     for (node=active_list_next(head, head); node; active_list_next(head,node)) {
         old = list_entry(node, pkg_t, list);
-        new = pkg_hash_fetch_best_installation_candidate_by_name(opkg->conf, old->name);
+        new = pkg_hash_fetch_best_installation_candidate_by_name(old->name);
        if (new == NULL)
                continue;
         package = pkg_t_to_opkg_package_t (new);
-        callback (opkg, package, user_data);
+        callback (package, user_data);
         opkg_package_free (package);
     }
     active_list_head_delete(head);
@@ -936,17 +835,15 @@ opkg_list_upgradable_packages (opkg_t *opkg, opkg_package_callback_t callback, v
 }
 
 opkg_package_t*
-opkg_find_package (opkg_t *opkg, const char *name, const char *ver, const char *arch, const char *repo)
+opkg_find_package (const char *name, const char *ver, const char *arch, const char *repo)
 {
   pkg_vec_t *all;
   opkg_package_t *package = NULL;
   int i;
 #define sstrcmp(x,y) (x && y) ? strcmp (x, y) : 0
 
-  opkg_assert (opkg);
-
   all = pkg_vec_alloc ();
-  pkg_hash_fetch_available (&opkg->conf->pkg_hash, all);
+  pkg_hash_fetch_available (all);
   for (i = 0; i < all->len; i++)
   {
     pkg_t *pkg;
@@ -996,10 +893,9 @@ opkg_find_package (opkg_t *opkg, const char *name, const char *ver, const char *
 #endif
 /**
  * @brief Check the accessibility of repositories. It will try to access the repository to check if the respository is accessible throught current network status. 
- * @param opkg The opkg_t
  * @return return how many repositories cannot access. 0 means all okay. 
  */ 
-int opkg_repository_accessibility_check(opkg_t *opkg
+int opkg_repository_accessibility_check(void
 {
   pkg_src_list_elt_t *iter;
   str_list_elt_t *iter1;
@@ -1009,11 +905,10 @@ int opkg_repository_accessibility_check(opkg_t *opkg)
   int err;
   char *repo_ptr;
   char *stmp;
-  opkg_assert(opkg != NULL);
 
   src = str_list_alloc();
 
-  list_for_each_entry(iter, &opkg->conf->pkg_src_list.head, node)
+  list_for_each_entry(iter, &conf->pkg_src_list.head, node)
   {
     if (strstr(((pkg_src_t *)iter->data)->value, "://") && 
                    index(strstr(((pkg_src_t *)iter->data)->value, "://") + 3, '/')) 
@@ -1043,7 +938,7 @@ int opkg_repository_accessibility_check(opkg_t *opkg)
     iter1 = str_list_pop(src);
     repositories--;
 
-    err = opkg_download(opkg->conf, iter1->data, "/dev/null", NULL, NULL);
+    err = opkg_download(iter1->data, "/dev/null", NULL, NULL);
 #ifdef HAVE_CURL
     if (!(err == CURLE_OK || 
                err == CURLE_HTTP_RETURNED_ERROR || 
index 4c34c32..7444faf 100644 (file)
 #ifndef OPKG_H
 #define OPKG_H
 
-typedef struct _opkg_t opkg_t;
 typedef struct _opkg_package_t opkg_package_t;
 typedef struct _opkg_progress_data_t opkg_progress_data_t;
 
-typedef void (*opkg_progress_callback_t) (opkg_t *opkg, const opkg_progress_data_t *progress, void *user_data);
-typedef void (*opkg_package_callback_t) (opkg_t *opkg, opkg_package_t *package, void *user_data);
+typedef void (*opkg_progress_callback_t) (const opkg_progress_data_t *progress, void *user_data);
+typedef void (*opkg_package_callback_t) (opkg_package_t *package, void *user_data);
 
 enum _opkg_action_t
 {
@@ -55,7 +54,6 @@ struct _opkg_package_t
   char *repository;
   char *description;
   char *tags;
-  char *url;
   int size;
   int installed;
 };
@@ -70,22 +68,22 @@ struct _opkg_progress_data_t
 opkg_package_t* opkg_package_new ();
 void opkg_package_free (opkg_package_t *package);
 
-opkg_t* opkg_new ();
-void opkg_free (opkg_t *opkg);
-void opkg_get_option (opkg_t *opkg, char *option, void **value);
-void opkg_set_option (opkg_t *opkg, char *option, void *value);
-int opkg_re_read_config_files (opkg_t *opkg);
+int opkg_new (void);
+void opkg_free (void);
+int opkg_re_read_config_files (void);
+void opkg_get_option (char *option, void **value);
+void opkg_set_option (char *option, void *value);
 
-int opkg_install_package (opkg_t *opkg, const char *package_name, opkg_progress_callback_t callback, void *user_data);
-int opkg_remove_package (opkg_t *opkg, const char *package_name, opkg_progress_callback_t callback, void *user_data);
-int opkg_upgrade_package (opkg_t *opkg, const char *package_name, opkg_progress_callback_t callback, void *user_data);
-int opkg_upgrade_all (opkg_t *opkg, opkg_progress_callback_t callback, void *user_data);
-int opkg_update_package_lists (opkg_t *opkg, opkg_progress_callback_t callback, void *user_data);
+int opkg_install_package (const char *package_name, opkg_progress_callback_t callback, void *user_data);
+int opkg_remove_package (const char *package_name, opkg_progress_callback_t callback, void *user_data);
+int opkg_upgrade_package (const char *package_name, opkg_progress_callback_t callback, void *user_data);
+int opkg_upgrade_all (opkg_progress_callback_t callback, void *user_data);
+int opkg_update_package_lists (opkg_progress_callback_t callback, void *user_data);
 
-int opkg_list_packages (opkg_t *opkg, opkg_package_callback_t callback, void *user_data);
-int opkg_list_upgradable_packages (opkg_t *opkg, opkg_package_callback_t callback, void *user_data);
-opkg_package_t* opkg_find_package (opkg_t *opkg, const char *name, const char *version, const char *architecture, const char *repository);
+int opkg_list_packages (opkg_package_callback_t callback, void *user_data);
+int opkg_list_upgradable_packages (opkg_package_callback_t callback, void *user_data);
+opkg_package_t* opkg_find_package (const char *name, const char *version, const char *architecture, const char *repository);
 
-int opkg_repository_accessibility_check(opkg_t *opkg);
+int opkg_repository_accessibility_check(void);
 
 #endif /* OPKG_H */
index ca9d9c9..30d3126 100644 (file)
 #include "opkg_upgrade.h"
 #include "opkg_remove.h"
 #include "opkg_configure.h"
-#include "opkg_message.h"
 #include "libopkg.h"
 #include "xsystem.h"
 
-static int opkg_update_cmd(opkg_conf_t *conf, int argc, char **argv);
-static int opkg_upgrade_cmd(opkg_conf_t *conf, int argc, char **argv);
-static int opkg_list_cmd(opkg_conf_t *conf, int argc, char **argv);
-static int opkg_info_cmd(opkg_conf_t *conf, int argc, char **argv);
-static int opkg_status_cmd(opkg_conf_t *conf, int argc, char **argv);
-static int opkg_install_cmd(opkg_conf_t *conf, int argc, char **argv);
-static int opkg_list_installed_cmd(opkg_conf_t *conf, int argc, char **argv);
-static int opkg_list_upgradable_cmd(opkg_conf_t *conf, int argc, char **argv);
-static int opkg_remove_cmd(opkg_conf_t *conf, int argc, char **argv);
-static int opkg_flag_cmd(opkg_conf_t *conf, int argc, char **argv);
-static int opkg_files_cmd(opkg_conf_t *conf, int argc, char **argv);
-static int opkg_search_cmd(opkg_conf_t *conf, int argc, char **argv);
-static int opkg_download_cmd(opkg_conf_t *conf, int argc, char **argv);
-static int opkg_depends_cmd(opkg_conf_t *conf, int argc, char **argv);
-static int opkg_whatdepends_cmd(opkg_conf_t *conf, int argc, char **argv);
-static int opkg_whatdepends_recursively_cmd(opkg_conf_t *conf, int argc, char **argv);
-static int opkg_whatsuggests_cmd(opkg_conf_t *conf, int argc, char **argv);
-static int opkg_whatrecommends_cmd(opkg_conf_t *conf, int argc, char **argv);
-static int opkg_whatprovides_cmd(opkg_conf_t *conf, int argc, char **argv);
-static int opkg_whatconflicts_cmd(opkg_conf_t *conf, int argc, char **argv);
-static int opkg_whatreplaces_cmd(opkg_conf_t *conf, int argc, char **argv);
-static int opkg_compare_versions_cmd(opkg_conf_t *conf, int argc, char **argv);
-static int opkg_print_architecture_cmd(opkg_conf_t *conf, int argc, char **argv);
-static int opkg_configure_cmd(opkg_conf_t *conf, int argc, char **argv);
-static int pkg_mark_provides(pkg_t *pkg);
-
-/* XXX: CLEANUP: The usage strings should be incorporated into this
-   array for easier maintenance */
-static opkg_cmd_t cmds[] = {
-     {"update", 0, (opkg_cmd_fun_t)opkg_update_cmd}, 
-     {"upgrade", 0, (opkg_cmd_fun_t)opkg_upgrade_cmd},
-     {"list", 0, (opkg_cmd_fun_t)opkg_list_cmd},
-     {"list_installed", 0, (opkg_cmd_fun_t)opkg_list_installed_cmd},
-     {"list-installed", 0, (opkg_cmd_fun_t)opkg_list_installed_cmd},
-     {"list_upgradable", 0, (opkg_cmd_fun_t)opkg_list_upgradable_cmd},
-     {"list-upgradable", 0, (opkg_cmd_fun_t)opkg_list_upgradable_cmd},
-     {"info", 0, (opkg_cmd_fun_t)opkg_info_cmd},
-     {"flag", 1, (opkg_cmd_fun_t)opkg_flag_cmd},
-     {"status", 0, (opkg_cmd_fun_t)opkg_status_cmd},
-     {"install", 1, (opkg_cmd_fun_t)opkg_install_cmd},
-     {"remove", 1, (opkg_cmd_fun_t)opkg_remove_cmd},
-     {"configure", 0, (opkg_cmd_fun_t)opkg_configure_cmd},
-     {"files", 1, (opkg_cmd_fun_t)opkg_files_cmd},
-     {"search", 1, (opkg_cmd_fun_t)opkg_search_cmd},
-     {"download", 1, (opkg_cmd_fun_t)opkg_download_cmd},
-     {"compare_versions", 1, (opkg_cmd_fun_t)opkg_compare_versions_cmd},
-     {"compare-versions", 1, (opkg_cmd_fun_t)opkg_compare_versions_cmd},
-     {"print-architecture", 0, (opkg_cmd_fun_t)opkg_print_architecture_cmd},
-     {"print_architecture", 0, (opkg_cmd_fun_t)opkg_print_architecture_cmd},
-     {"print-installation-architecture", 0, (opkg_cmd_fun_t)opkg_print_architecture_cmd},
-     {"print_installation_architecture", 0, (opkg_cmd_fun_t)opkg_print_architecture_cmd},
-     {"depends", 1, (opkg_cmd_fun_t)opkg_depends_cmd},
-     {"whatdepends", 1, (opkg_cmd_fun_t)opkg_whatdepends_cmd},
-     {"whatdependsrec", 1, (opkg_cmd_fun_t)opkg_whatdepends_recursively_cmd},
-     {"whatrecommends", 1, (opkg_cmd_fun_t)opkg_whatrecommends_cmd},
-     {"whatsuggests", 1, (opkg_cmd_fun_t)opkg_whatsuggests_cmd},
-     {"whatprovides", 1, (opkg_cmd_fun_t)opkg_whatprovides_cmd},
-     {"whatreplaces", 1, (opkg_cmd_fun_t)opkg_whatreplaces_cmd},
-     {"whatconflicts", 1, (opkg_cmd_fun_t)opkg_whatconflicts_cmd},
-};
-
-static void print_pkg(pkg_t *pkg)
+static void
+print_pkg(pkg_t *pkg)
 {
        char *version = pkg_version_str_alloc(pkg);
        if (pkg->description)
@@ -114,49 +53,30 @@ static void print_pkg(pkg_t *pkg)
 }
 
 int opkg_state_changed;
-static void write_status_files_if_changed(opkg_conf_t *conf)
+
+static void
+write_status_files_if_changed(void)
 {
      if (opkg_state_changed && !conf->noaction) {
-         opkg_message(conf, OPKG_INFO,
-                      "  writing status file\n");
-         opkg_conf_write_status_files(conf);
-         pkg_write_changed_filelists(conf);
+         opkg_msg(INFO, "Writing status file.\n");
+         opkg_conf_write_status_files();
+         pkg_write_changed_filelists();
      } else { 
-         opkg_message(conf, OPKG_DEBUG, "Nothing to be done\n");
-     }
-}
-
-
-static int num_cmds = sizeof(cmds) / sizeof(opkg_cmd_t);
-
-opkg_cmd_t *opkg_cmd_find(const char *name)
-{
-     int i;
-     opkg_cmd_t *cmd;
-
-     for (i=0; i < num_cmds; i++) {
-         cmd = &cmds[i];
-         if (strcmp(name, cmd->name) == 0) {
-              return cmd;
-         }
+         opkg_msg(DEBUG, "Nothing to be done.\n");
      }
-
-     return NULL;
 }
 
-int opkg_cmd_exec(opkg_cmd_t *cmd, opkg_conf_t *conf, int argc, const char **argv, void *userdata)
+static void
+sigint_handler(int sig)
 {
-       int result;
-
-       result = (cmd->fun)(conf, argc, argv);
-
-       print_error_list();
-       free_error_list();
-
-       return result;
+     signal(sig, SIG_DFL);
+     opkg_msg(NOTICE, "Interrupted. Writing out status database.\n");
+     write_status_files_if_changed();
+     exit(128 + sig);
 }
 
-static int opkg_update_cmd(opkg_conf_t *conf, int argc, char **argv)
+static int
+opkg_update_cmd(int argc, char **argv)
 {
      char *tmp;
      int err;
@@ -170,17 +90,13 @@ static int opkg_update_cmd(opkg_conf_t *conf, int argc, char **argv)
  
     if (! file_is_dir(lists_dir)) {
          if (file_exists(lists_dir)) {
-              opkg_message(conf, OPKG_ERROR,
-                           "%s: ERROR: %s exists, but is not a directory\n",
-                           __FUNCTION__, lists_dir);
+              opkg_msg(ERROR, "%s exists, but is not a directory.\n",
+                           lists_dir);
               free(lists_dir);
               return -1;
          }
          err = file_mkdir_hier(lists_dir, 0755);
          if (err) {
-              opkg_message(conf, OPKG_ERROR,
-                           "%s: ERROR: failed to make directory %s: %s\n",
-                           __FUNCTION__, lists_dir, strerror(errno));
               free(lists_dir);
               return -1;
          }     
@@ -190,7 +106,7 @@ static int opkg_update_cmd(opkg_conf_t *conf, int argc, char **argv)
 
      sprintf_alloc(&tmp, "%s/update-XXXXXX", conf->tmp_dir);
      if (mkdtemp (tmp) == NULL) {
-        perror ("mkdtemp");
+        opkg_perror(ERROR, "Failed to make temp dir %s", conf->tmp_dir);
         return -1;
      }
 
@@ -212,9 +128,9 @@ static int opkg_update_cmd(opkg_conf_t *conf, int argc, char **argv)
              FILE *in, *out;
              
              sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name);
-             err = opkg_download(conf, url, tmp_file_name, NULL, NULL);
+             err = opkg_download(url, tmp_file_name, NULL, NULL);
              if (err == 0) {
-                  opkg_message (conf, OPKG_NOTICE, "Inflating %s\n", url);
+                  opkg_msg(NOTICE, "Inflating %s.\n", url);
                   in = fopen (tmp_file_name, "r");
                   out = fopen (list_file_name, "w");
                   if (in && out)
@@ -229,12 +145,11 @@ static int opkg_update_cmd(opkg_conf_t *conf, int argc, char **argv)
              }
              free(tmp_file_name);
          } else
-             err = opkg_download(conf, url, list_file_name, NULL, NULL);
+             err = opkg_download(url, list_file_name, NULL, NULL);
          if (err) {
               failures++;
          } else {
-              opkg_message(conf, OPKG_NOTICE,
-                           "Updated list of available packages in %s\n",
+              opkg_msg(NOTICE, "Updated list of available packages in %s.\n",
                            list_file_name);
          }
          free(url);
@@ -254,17 +169,16 @@ static int opkg_update_cmd(opkg_conf_t *conf, int argc, char **argv)
               /* Put the signature in the right place */
               sprintf_alloc (&tmp_file_name, "%s/%s.sig", lists_dir, src->name);
 
-              err = opkg_download(conf, url, tmp_file_name, NULL, NULL);
+              err = opkg_download(url, tmp_file_name, NULL, NULL);
               if (err) {
                   failures++;
-                  opkg_message (conf, OPKG_NOTICE, "Signature check failed\n");
+                  opkg_msg(NOTICE, "Signature check failed.\n");
               } else {
-                  int err;
-                  err = opkg_verify_file (conf, list_file_name, tmp_file_name);
+                  err = opkg_verify_file (list_file_name, tmp_file_name);
                   if (err == 0)
-                      opkg_message (conf, OPKG_NOTICE, "Signature check passed\n");
+                      opkg_msg(NOTICE, "Signature check passed.\n");
                   else
-                      opkg_message (conf, OPKG_NOTICE, "Signature check failed\n");
+                      opkg_msg(NOTICE, "Signature check failed.\n");
               }
               /* We shouldn't unlink the signature ! */
               // unlink (tmp_file_name);
@@ -292,7 +206,8 @@ struct opkg_intercept
 
 typedef struct opkg_intercept *opkg_intercept_t;
 
-static opkg_intercept_t opkg_prep_intercepts(opkg_conf_t *conf)
+static opkg_intercept_t
+opkg_prep_intercepts(void)
 {
     opkg_intercept_t ctx;
     char *newpath;
@@ -303,7 +218,7 @@ static opkg_intercept_t opkg_prep_intercepts(opkg_conf_t *conf)
     sprintf_alloc(&ctx->statedir, "%s/opkg-intercept-XXXXXX", conf->tmp_dir);
 
     if (mkdtemp(ctx->statedir) == NULL) {
-        fprintf(stderr, "%s: mkdtemp: %s\n", __FUNCTION__, strerror(errno));
+        opkg_perror(ERROR,"Failed to make temp dir %s", ctx->statedir);
        free(ctx->oldpath);
        free(ctx->statedir);
         free(newpath);
@@ -318,7 +233,8 @@ static opkg_intercept_t opkg_prep_intercepts(opkg_conf_t *conf)
     return ctx;
 }
 
-static int opkg_finalize_intercepts(opkg_intercept_t ctx)
+static int
+opkg_finalize_intercepts(opkg_intercept_t ctx)
 {
     DIR *dir;
     int err = 0;
@@ -344,7 +260,7 @@ static int opkg_finalize_intercepts(opkg_intercept_t ctx)
        }
         closedir(dir);
     } else
-       perror (ctx->statedir);
+       opkg_perror(ERROR, "Failed to open dir %s", ctx->statedir);
        
     rm_r(ctx->statedir);
     free (ctx->statedir);
@@ -361,7 +277,8 @@ static int opkg_finalize_intercepts(opkg_intercept_t ctx)
    used to end recursion and avoid an infinite loop on graph cycles.
    pkg_vec ordered will finally contain the ordered set of packages.
 */
-static int opkg_recurse_pkgs_in_order(opkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *all,
+static int
+opkg_recurse_pkgs_in_order(pkg_t *pkg, pkg_vec_t *all,
                                pkg_vec_t *visited, pkg_vec_t *ordered)
 {
     int j,k,l,m;
@@ -385,8 +302,7 @@ static int opkg_recurse_pkgs_in_order(opkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *
     /* If the  package has already been visited (by this function), skip it */
     for(j = 0; j < visited->len; j++) 
         if ( ! strcmp(visited->pkgs[j]->name, pkg->name)) {
-            opkg_message(conf, OPKG_INFO,
-                         "  pkg: %s already visited\n", pkg->name);
+            opkg_msg(INFO, "pkg %s already visited, skipping.\n", pkg->name);
             return 0;
         }
     
@@ -395,8 +311,7 @@ static int opkg_recurse_pkgs_in_order(opkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *
     count = pkg->pre_depends_count + pkg->depends_count + \
         pkg->recommends_count + pkg->suggests_count;
 
-    opkg_message(conf, OPKG_INFO,
-                 "  pkg: %s\n", pkg->name);
+    opkg_msg(INFO, "pkg %s.\n", pkg->name);
 
     /* Iterate over all the dependencies of pkg. For each one, find a package 
        that is either installed or unpacked and satisfies this dependency.
@@ -411,8 +326,7 @@ static int opkg_recurse_pkgs_in_order(opkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *
             l = 0;
             if (dependents != NULL)
                 while (l < abpkg->provided_by->len && dependents[l] != NULL) {
-                    opkg_message(conf, OPKG_INFO,
-                                 "  Descending on pkg: %s\n", 
+                    opkg_msg(INFO, "Descending on pkg %s.\n", 
                                  dependents [l]->name);
     
                     /* find whether dependent l is installed or unpacked,
@@ -421,7 +335,7 @@ static int opkg_recurse_pkgs_in_order(opkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *
                         dep = all->pkgs[m];
                         if ( dep->state_status != SS_NOT_INSTALLED)
                             if ( ! strcmp(dep->name, dependents[l]->name)) {
-                                opkg_recurse_pkgs_in_order(conf, dep, all, 
+                                opkg_recurse_pkgs_in_order(dep, all, 
                                                            visited, ordered);
                                 /* Stop the outer loop */
                                 l = abpkg->provided_by->len;
@@ -443,7 +357,8 @@ static int opkg_recurse_pkgs_in_order(opkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *
 
 }
 
-static int opkg_configure_packages(opkg_conf_t *conf, char *pkg_name)
+static int
+opkg_configure_packages(char *pkg_name)
 {
      pkg_vec_t *all, *ordered, *visited;
      int i;
@@ -451,26 +366,23 @@ static int opkg_configure_packages(opkg_conf_t *conf, char *pkg_name)
      opkg_intercept_t ic;
      int r, err = 0;
 
-     opkg_message(conf, OPKG_INFO,
-                 "Configuring unpacked packages\n");
-     fflush( stdout );
+     opkg_msg(INFO, "Configuring unpacked packages.\n");
 
      all = pkg_vec_alloc();
 
-     pkg_hash_fetch_available(&conf->pkg_hash, all);
+     pkg_hash_fetch_available(all);
 
      /* Reorder pkgs in order to be configured according to the Depends: tag
         order */
-     opkg_message(conf, OPKG_INFO,
-                  "Reordering packages before configuring them...\n");
+     opkg_msg(INFO, "Reordering packages before configuring them...\n");
      ordered = pkg_vec_alloc();
      visited = pkg_vec_alloc();
      for(i = 0; i < all->len; i++) {
          pkg = all->pkgs[i];
-         opkg_recurse_pkgs_in_order(conf, pkg, all, visited, ordered);
+         opkg_recurse_pkgs_in_order(pkg, all, visited, ordered);
      }
 
-     ic = opkg_prep_intercepts (conf);
+     ic = opkg_prep_intercepts();
      if (ic == NULL) {
             err = -1;
             goto error;
@@ -483,10 +395,8 @@ static int opkg_configure_packages(opkg_conf_t *conf, char *pkg_name)
               continue;
 
          if (pkg->state_status == SS_UNPACKED) {
-              opkg_message(conf, OPKG_NOTICE,
-                           "Configuring %s\n", pkg->name);
-              fflush( stdout );
-              r = opkg_configure(conf, pkg);
+              opkg_msg(NOTICE, "Configuring %s.\n", pkg->name);
+              r = opkg_configure(pkg);
               if (r == 0) {
                    pkg->state_status = SS_INSTALLED;
                    pkg->parent->state_status = SS_INSTALLED;
@@ -510,24 +420,13 @@ error:
      return err;
 }
 
-static opkg_conf_t *global_conf;
-
-static void sigint_handler(int sig)
-{
-     signal(sig, SIG_DFL);
-     opkg_message(NULL, OPKG_NOTICE,
-                 "opkg: interrupted. writing out status database\n");
-     write_status_files_if_changed(global_conf);
-     exit(128 + sig);
-}
-
-static int opkg_install_cmd(opkg_conf_t *conf, int argc, char **argv)
+static int
+opkg_install_cmd(int argc, char **argv)
 {
      int i;
      char *arg;
      int err=0;
 
-     global_conf = conf;
      signal(SIGINT, sigint_handler);
 
      /*
@@ -536,116 +435,109 @@ static int opkg_install_cmd(opkg_conf_t *conf, int argc, char **argv)
      for (i=0; i < argc; i++) {
          arg = argv[i];
 
-          opkg_message(conf, OPKG_DEBUG2, "Debug install_cmd: %s  \n",arg );
-          err = opkg_prepare_url_for_install(conf, arg, &argv[i]);
+          opkg_msg(DEBUG2, "%s\n", arg);
+          err = opkg_prepare_url_for_install(arg, &argv[i]);
           if (err)
               return err;
      }
-     pkg_info_preinstall_check(conf);
+     pkg_info_preinstall_check();
 
      for (i=0; i < argc; i++) {
          arg = argv[i];
-          err = opkg_install_by_name(conf, arg);
+          err = opkg_install_by_name(arg);
          if (err) {
-              opkg_message(conf, OPKG_ERROR, "Cannot find package %s.\n", arg);
+              opkg_msg(ERROR, "Cannot install package %s.\n", arg);
          }
      }
 
-     opkg_configure_packages(conf, NULL);
+     opkg_configure_packages(NULL);
 
-     write_status_files_if_changed(conf);
+     write_status_files_if_changed();
 
      return err;
 }
 
-static int opkg_upgrade_cmd(opkg_conf_t *conf, int argc, char **argv)
+static int
+opkg_upgrade_cmd(int argc, char **argv)
 {
      int i;
      pkg_t *pkg;
      int err;
 
-     global_conf = conf;
      signal(SIGINT, sigint_handler);
 
      if (argc) {
          for (i=0; i < argc; i++) {
               char *arg = argv[i];
 
-               err = opkg_prepare_url_for_install(conf, arg, &arg);
+               err = opkg_prepare_url_for_install(arg, &arg);
                if (err)
                    return err;
          }
-         pkg_info_preinstall_check(conf);
+         pkg_info_preinstall_check();
 
          for (i=0; i < argc; i++) {
               char *arg = argv[i];
               if (conf->restrict_to_default_dest) {
-                   pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
-                                                               argv[i],
-                                                               conf->default_dest);
+                   pkg = pkg_hash_fetch_installed_by_name_dest(argv[i],
+                                                       conf->default_dest);
                    if (pkg == NULL) {
-                        opkg_message(conf, OPKG_NOTICE,
-                                     "Package %s not installed in %s\n",
+                        opkg_msg(NOTICE, "Package %s not installed in %s.\n",
                                      argv[i], conf->default_dest->name);
                         continue;
                    }
               } else {
-                   pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
-                                                          argv[i]);
+                   pkg = pkg_hash_fetch_installed_by_name(argv[i]);
               }
               if (pkg)
-                   opkg_upgrade_pkg(conf, pkg);
+                   opkg_upgrade_pkg(pkg);
               else {
-                   opkg_install_by_name(conf, arg);
+                   opkg_install_by_name(arg);
                }
          }
      } else {
          pkg_vec_t *installed = pkg_vec_alloc();
 
-         pkg_info_preinstall_check(conf);
+         pkg_info_preinstall_check();
 
-         pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
+         pkg_hash_fetch_all_installed(installed);
          for (i = 0; i < installed->len; i++) {
               pkg = installed->pkgs[i];
-              opkg_upgrade_pkg(conf, pkg);
+              opkg_upgrade_pkg(pkg);
          }
          pkg_vec_free(installed);
      }
 
-     opkg_configure_packages(conf, NULL);
+     opkg_configure_packages(NULL);
 
-     write_status_files_if_changed(conf);
+     write_status_files_if_changed();
 
      return 0;
 }
 
-static int opkg_download_cmd(opkg_conf_t *conf, int argc, char **argv)
+static int
+opkg_download_cmd(int argc, char **argv)
 {
      int i, err;
      char *arg;
      pkg_t *pkg;
 
-     pkg_info_preinstall_check(conf);
+     pkg_info_preinstall_check();
      for (i = 0; i < argc; i++) {
          arg = argv[i];
 
-         pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, arg);
+         pkg = pkg_hash_fetch_best_installation_candidate_by_name(arg);
          if (pkg == NULL) {
-              opkg_message(conf, OPKG_ERROR,
-                           "Cannot find package %s.\n"
-                           "Check the spelling or perhaps run 'opkg update'\n",
-                           arg);
+              opkg_msg(ERROR, "Cannot find package %s.\n", arg);
               continue;
          }
 
-         err = opkg_download_pkg(conf, pkg, ".");
+         err = opkg_download_pkg(pkg, ".");
 
          if (err) {
-              opkg_message(conf, OPKG_ERROR,
-                           "Failed to download %s\n", pkg->name);
+              opkg_msg(ERROR, "Failed to download %s.\n", pkg->name);
          } else {
-              opkg_message(conf, OPKG_NOTICE,
-                           "Downloaded %s as %s\n",
+              opkg_msg(NOTICE, "Downloaded %s as %s.\n",
                            pkg->name, pkg->local_filename);
          }
      }
@@ -654,7 +546,8 @@ static int opkg_download_cmd(opkg_conf_t *conf, int argc, char **argv)
 }
 
 
-static int opkg_list_cmd(opkg_conf_t *conf, int argc, char **argv)
+static int
+opkg_list_cmd(int argc, char **argv)
 {
      int i;
      pkg_vec_t *available;
@@ -665,7 +558,7 @@ static int opkg_list_cmd(opkg_conf_t *conf, int argc, char **argv)
          pkg_name = argv[0];
      }
      available = pkg_vec_alloc();
-     pkg_hash_fetch_available(&conf->pkg_hash, available);
+     pkg_hash_fetch_available(available);
      pkg_vec_sort(available, pkg_compare_names);
      for (i=0; i < available->len; i++) {
          pkg = available->pkgs[i];
@@ -680,7 +573,8 @@ static int opkg_list_cmd(opkg_conf_t *conf, int argc, char **argv)
 }
 
 
-static int opkg_list_installed_cmd(opkg_conf_t *conf, int argc, char **argv)
+static int
+opkg_list_installed_cmd(int argc, char **argv)
 {
      int i ;
      pkg_vec_t *available;
@@ -691,7 +585,7 @@ static int opkg_list_installed_cmd(opkg_conf_t *conf, int argc, char **argv)
          pkg_name = argv[0];
      }
      available = pkg_vec_alloc();
-     pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
+     pkg_hash_fetch_all_installed(available);
      pkg_vec_sort(available, pkg_compare_names);
      for (i=0; i < available->len; i++) {
          pkg = available->pkgs[i];
@@ -706,15 +600,16 @@ static int opkg_list_installed_cmd(opkg_conf_t *conf, int argc, char **argv)
      return 0;
 }
 
-static int opkg_list_upgradable_cmd(opkg_conf_t *conf, int argc, char **argv) 
+static int
+opkg_list_upgradable_cmd(int argc, char **argv)
 {
-    struct active_list *head = prepare_upgrade_list(conf);
+    struct active_list *head = prepare_upgrade_list();
     struct active_list *node=NULL;
     pkg_t *_old_pkg, *_new_pkg;
     char *old_v, *new_v;
     for (node = active_list_next(head, head); node;node = active_list_next(head,node)) {
         _old_pkg = list_entry(node, pkg_t, list);
-        _new_pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, _old_pkg->name);
+        _new_pkg = pkg_hash_fetch_best_installation_candidate_by_name(_old_pkg->name);
        if (_new_pkg == NULL)
                continue;
         old_v = pkg_version_str_alloc(_old_pkg);
@@ -727,7 +622,8 @@ static int opkg_list_upgradable_cmd(opkg_conf_t *conf, int argc, char **argv)
     return 0;
 }
 
-static int opkg_info_status_cmd(opkg_conf_t *conf, int argc, char **argv, int installed_only)
+static int
+opkg_info_status_cmd(int argc, char **argv, int installed_only)
 {
      int i;
      pkg_vec_t *available;
@@ -740,9 +636,9 @@ static int opkg_info_status_cmd(opkg_conf_t *conf, int argc, char **argv, int in
 
      available = pkg_vec_alloc();
      if (installed_only)
-         pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
+         pkg_hash_fetch_all_installed(available);
      else
-         pkg_hash_fetch_available(&conf->pkg_hash, available);
+         pkg_hash_fetch_available(available);
 
      for (i=0; i < available->len; i++) {
          pkg = available->pkgs[i];
@@ -752,14 +648,13 @@ static int opkg_info_status_cmd(opkg_conf_t *conf, int argc, char **argv, int in
 
          pkg_formatted_info(stdout, pkg);
 
-         if (conf->verbosity >= OPKG_NOTICE) {
+         if (conf->verbosity >= NOTICE) {
               conffile_list_elt_t *iter;
               for (iter = nv_pair_list_first(&pkg->conffiles); iter; iter = nv_pair_list_next(&pkg->conffiles, iter)) {
                    conffile_t *cf = (conffile_t *)iter->data;
-                   int modified = conffile_has_been_modified(conf, cf);
+                   int modified = conffile_has_been_modified(cf);
                    if (cf->value)
-                       opkg_message(conf, OPKG_INFO,
-                               "conffile=%s md5sum=%s modified=%d\n",
+                       opkg_msg(INFO, "conffile=%s md5sum=%s modified=%d.\n",
                                 cf->name, cf->value, modified);
               }
          }
@@ -769,52 +664,50 @@ static int opkg_info_status_cmd(opkg_conf_t *conf, int argc, char **argv, int in
      return 0;
 }
 
-static int opkg_info_cmd(opkg_conf_t *conf, int argc, char **argv)
+static int
+opkg_info_cmd(int argc, char **argv)
 {
-     return opkg_info_status_cmd(conf, argc, argv, 0);
+     return opkg_info_status_cmd(argc, argv, 0);
 }
 
-static int opkg_status_cmd(opkg_conf_t *conf, int argc, char **argv)
+static int
+opkg_status_cmd(int argc, char **argv)
 {
-     return opkg_info_status_cmd(conf, argc, argv, 1);
+     return opkg_info_status_cmd(argc, argv, 1);
 }
 
-static int opkg_configure_cmd(opkg_conf_t *conf, int argc, char **argv)
+static int
+opkg_configure_cmd(int argc, char **argv)
 {
-     
-     int err;
-     if (argc > 0) {
-         char *pkg_name = NULL;
+       int err;
+       char *pkg_name = NULL;
 
-         pkg_name = argv[0];
+       if (argc > 0)
+               pkg_name = argv[0];
 
-         err = opkg_configure_packages (conf, pkg_name);
-     
-     } else {
-         err = opkg_configure_packages (conf, NULL);
-     }
+       err = opkg_configure_packages(pkg_name);
 
-     write_status_files_if_changed(conf);
+       write_status_files_if_changed();
 
-     return err;
+       return err;
 }
 
-static int opkg_remove_cmd(opkg_conf_t *conf, int argc, char **argv)
+static int
+opkg_remove_cmd(int argc, char **argv)
 {
      int i, a, done;
      pkg_t *pkg;
      pkg_t *pkg_to_remove;
      pkg_vec_t *available;
 
-     global_conf = conf;
      done = 0;
 
      signal(SIGINT, sigint_handler);
 
-     pkg_info_preinstall_check(conf);
+     pkg_info_preinstall_check();
 
      available = pkg_vec_alloc();
-     pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
+     pkg_hash_fetch_all_installed(available);
 
      for (i=0; i<argc; i++) {
         for (a=0; a<available->len; a++) {
@@ -823,22 +716,22 @@ static int opkg_remove_cmd(opkg_conf_t *conf, int argc, char **argv)
                continue;
             }
             if (conf->restrict_to_default_dest) {
-                pkg_to_remove = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
+                pkg_to_remove = pkg_hash_fetch_installed_by_name_dest(
                                        pkg->name,
                                        conf->default_dest);
             } else {
-                pkg_to_remove = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name );
+                pkg_to_remove = pkg_hash_fetch_installed_by_name(pkg->name);
             }
         
             if (pkg_to_remove == NULL) {
-                opkg_message(conf, OPKG_ERROR, "Package %s is not installed.\n", pkg->name);
+                opkg_msg(ERROR, "Package %s is not installed.\n", pkg->name);
                 continue;
             }
             if (pkg->state_status == SS_NOT_INSTALLED) {    // Added the control, so every already removed package could be skipped
-                opkg_message(conf, OPKG_ERROR, "Package seems to be %s not installed (STATUS = NOT_INSTALLED).\n", pkg->name);
+                opkg_msg(ERROR, "Package %s not installed.\n", pkg->name);
                  continue;
             }
-            opkg_remove_pkg(conf, pkg_to_remove, 0);
+            opkg_remove_pkg(pkg_to_remove, 0);
             done = 1;
         }
      }
@@ -846,33 +739,31 @@ static int opkg_remove_cmd(opkg_conf_t *conf, int argc, char **argv)
      pkg_vec_free(available);
 
      if (done == 0)
-        opkg_message(conf, OPKG_NOTICE, "No packages removed.\n");
+        opkg_msg(NOTICE, "No packages removed.\n");
 
-     write_status_files_if_changed(conf);
+     write_status_files_if_changed();
      return 0;
 }
 
-static int opkg_flag_cmd(opkg_conf_t *conf, int argc, char **argv)
+static int
+opkg_flag_cmd(int argc, char **argv)
 {
      int i;
      pkg_t *pkg;
      const char *flags = argv[0];
     
-     global_conf = conf;
      signal(SIGINT, sigint_handler);
 
      for (i=1; i < argc; i++) {
          if (conf->restrict_to_default_dest) {
-              pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
-                                                          argv[i],
+              pkg = pkg_hash_fetch_installed_by_name_dest(argv[i],
                                                           conf->default_dest);
          } else {
-              pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
+              pkg = pkg_hash_fetch_installed_by_name(argv[i]);
          }
 
          if (pkg == NULL) {
-              opkg_message(conf, OPKG_ERROR,
-                           "Package %s is not installed.\n", argv[i]);
+              opkg_msg(ERROR, "Package %s is not installed.\n", argv[i]);
               continue;
          }
           if (( strcmp(flags,"hold")==0)||( strcmp(flags,"noprune")==0)||
@@ -889,16 +780,16 @@ static int opkg_flag_cmd(opkg_conf_t *conf, int argc, char **argv)
           }
 
          opkg_state_changed++;
-         opkg_message(conf, OPKG_NOTICE,
-                      "Setting flags for package %s to %s\n",
+         opkg_msg(NOTICE, "Setting flags for package %s to %s.\n",
                       pkg->name, flags);
      }
 
-     write_status_files_if_changed(conf);
+     write_status_files_if_changed();
      return 0;
 }
 
-static int opkg_files_cmd(opkg_conf_t *conf, int argc, char **argv)
+static int
+opkg_files_cmd(int argc, char **argv)
 {
      pkg_t *pkg;
      str_list_t *files;
@@ -906,18 +797,16 @@ static int opkg_files_cmd(opkg_conf_t *conf, int argc, char **argv)
      char *pkg_version;
 
      if (argc < 1) {
-         return EINVAL;
+         return -1;
      }
 
-     pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
-                                           argv[0]);
+     pkg = pkg_hash_fetch_installed_by_name(argv[0]);
      if (pkg == NULL) {
-         opkg_message(conf, OPKG_ERROR,
-                      "Package %s not installed.\n", argv[0]);
+         opkg_msg(ERROR, "Package %s not installed.\n", argv[0]);
          return 0;
      }
 
-     files = pkg_get_installed_files(conf, pkg);
+     files = pkg_get_installed_files(pkg);
      pkg_version = pkg_version_str_alloc(pkg);
 
      printf("Package %s (%s) is installed on %s and has the following files:\n",
@@ -932,7 +821,8 @@ static int opkg_files_cmd(opkg_conf_t *conf, int argc, char **argv)
      return 0;
 }
 
-static int opkg_depends_cmd(opkg_conf_t *conf, int argc, char **argv)
+static int
+opkg_depends_cmd(int argc, char **argv)
 {
        int i, j, k;
        int depends_count;
@@ -941,13 +831,13 @@ static int opkg_depends_cmd(opkg_conf_t *conf, int argc, char **argv)
        pkg_t *pkg;
        char *str;
 
-       pkg_info_preinstall_check(conf);
+       pkg_info_preinstall_check();
 
        available_pkgs = pkg_vec_alloc();
        if (conf->query_all)
-              pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
+              pkg_hash_fetch_available(available_pkgs);
        else
-              pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
+              pkg_hash_fetch_all_installed(available_pkgs);
 
        for (i=0; i<argc; i++) {
                for (j=0; j<available_pkgs->len; j++) {
@@ -961,8 +851,7 @@ static int opkg_depends_cmd(opkg_conf_t *conf, int argc, char **argv)
                                        pkg->recommends_count +
                                        pkg->suggests_count;
 
-                       opkg_message(conf, OPKG_NOTICE, "%s depends on:\n",
-                                     pkg->name);
+                       opkg_msg(NOTICE, "%s depends on:\n", pkg->name);
 
                        for (k=0; k<depends_count; k++) {
                                cdep = &pkg->depends[k];
@@ -971,7 +860,7 @@ static int opkg_depends_cmd(opkg_conf_t *conf, int argc, char **argv)
                                      continue;
 
                                str = pkg_depend_str(pkg, k);
-                               opkg_message(conf, OPKG_NOTICE, "\t%s\n", str);
+                               opkg_msg(NOTICE, "\t%s\n", str);
                                free(str);
                        }
 
@@ -982,6 +871,19 @@ static int opkg_depends_cmd(opkg_conf_t *conf, int argc, char **argv)
        return 0;
 }
 
+static int
+pkg_mark_provides(pkg_t *pkg)
+{
+     int provides_count = pkg->provides_count;
+     abstract_pkg_t **provides = pkg->provides;
+     int i;
+     pkg->parent->state_flag |= SF_MARKED;
+     for (i = 0; i < provides_count; i++) {
+         provides[i]->state_flag |= SF_MARKED;
+     }
+     return 0;
+}
+
 enum what_field_type {
   WHATDEPENDS,
   WHATCONFLICTS,
@@ -991,7 +893,8 @@ enum what_field_type {
   WHATSUGGESTS
 };
 
-static int opkg_what_depends_conflicts_cmd(opkg_conf_t *conf, enum depend_type what_field_type, int recursive, int argc, char **argv)
+static int
+opkg_what_depends_conflicts_cmd(enum depend_type what_field_type, int recursive, int argc, char **argv)
 {
        depend_t *possibility;
        compound_depend_t *cdep;
@@ -1013,13 +916,13 @@ static int opkg_what_depends_conflicts_cmd(opkg_conf_t *conf, enum depend_type w
        available_pkgs = pkg_vec_alloc();
 
        if (conf->query_all)
-              pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
+              pkg_hash_fetch_available(available_pkgs);
        else
-              pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
+              pkg_hash_fetch_all_installed(available_pkgs);
 
        /* mark the root set */
        pkg_vec_clear_marks(available_pkgs);
-       opkg_message(conf, OPKG_NOTICE, "Root set:\n");
+       opkg_msg(NOTICE, "Root set:\n");
        for (i = 0; i < argc; i++)
               pkg_vec_mark_if_matches(available_pkgs, argv[i]);
 
@@ -1028,11 +931,11 @@ static int opkg_what_depends_conflicts_cmd(opkg_conf_t *conf, enum depend_type w
               if (pkg->state_flag & SF_MARKED) {
                    /* mark the parent (abstract) package */
                    pkg_mark_provides(pkg);
-                   opkg_message(conf, OPKG_NOTICE, "  %s\n", pkg->name);
+                   opkg_msg(NOTICE, "  %s\n", pkg->name);
               }
        }
 
-       opkg_message(conf, OPKG_NOTICE, "What %s root set\n", rel_str);
+       opkg_msg(NOTICE, "What %s root set\n", rel_str);
        do {
                changed = 0;
 
@@ -1073,23 +976,21 @@ static int opkg_what_depends_conflicts_cmd(opkg_conf_t *conf, enum depend_type w
                                        changed++;
 
                                        ver = pkg_version_str_alloc(pkg); 
-                                       opkg_message(conf, OPKG_NOTICE,
-                                                       "\t%s %s\t%s %s",
+                                       opkg_msg(NOTICE, "\t%s %s\t%s %s",
                                                        pkg->name,
                                                        ver,
                                                        rel_str,
                                                        possibility->pkg->name);
                                        free(ver);
                                        if (possibility->version) {
-                                               opkg_message(conf, OPKG_NOTICE,
-                                                       " (%s%s)",
+                                               opkg_msg(NOTICE, " (%s%s)",
                                                        constraint_to_str(possibility->constraint),
                                                        possibility->version);
                                        }
-                                       if (!pkg_dependence_satisfiable(conf, possibility))
-                                               opkg_message(conf, OPKG_NOTICE,
+                                       if (!pkg_dependence_satisfiable(possibility))
+                                               opkg_msg(NOTICE,
                                                        " unsatisfiable");
-                                       opkg_message(conf, OPKG_NOTICE, "\n");
+                                       opkg_msg(NOTICE, "\n");
                                        goto next_package;
                                }
                        }
@@ -1103,43 +1004,38 @@ next_package:
        return 0;
 }
 
-static int pkg_mark_provides(pkg_t *pkg)
+static int
+opkg_whatdepends_recursively_cmd(int argc, char **argv)
 {
-     int provides_count = pkg->provides_count;
-     abstract_pkg_t **provides = pkg->provides;
-     int i;
-     pkg->parent->state_flag |= SF_MARKED;
-     for (i = 0; i < provides_count; i++) {
-         provides[i]->state_flag |= SF_MARKED;
-     }
-     return 0;
+     return opkg_what_depends_conflicts_cmd(DEPEND, 1, argc, argv);
 }
 
-static int opkg_whatdepends_recursively_cmd(opkg_conf_t *conf, int argc, char **argv)
-{
-     return opkg_what_depends_conflicts_cmd(conf, DEPEND, 1, argc, argv);
-}
-static int opkg_whatdepends_cmd(opkg_conf_t *conf, int argc, char **argv)
+static int
+opkg_whatdepends_cmd(int argc, char **argv)
 {
-     return opkg_what_depends_conflicts_cmd(conf, DEPEND, 0, argc, argv);
+     return opkg_what_depends_conflicts_cmd(DEPEND, 0, argc, argv);
 }
 
-static int opkg_whatsuggests_cmd(opkg_conf_t *conf, int argc, char **argv)
+static int
+opkg_whatsuggests_cmd(int argc, char **argv)
 {
-     return opkg_what_depends_conflicts_cmd(conf, SUGGEST, 0, argc, argv);
+     return opkg_what_depends_conflicts_cmd(SUGGEST, 0, argc, argv);
 }
 
-static int opkg_whatrecommends_cmd(opkg_conf_t *conf, int argc, char **argv)
+static int
+opkg_whatrecommends_cmd(int argc, char **argv)
 {
-     return opkg_what_depends_conflicts_cmd(conf, RECOMMEND, 0, argc, argv);
+     return opkg_what_depends_conflicts_cmd(RECOMMEND, 0, argc, argv);
 }
 
-static int opkg_whatconflicts_cmd(opkg_conf_t *conf, int argc, char **argv)
+static int
+opkg_whatconflicts_cmd(int argc, char **argv)
 {
-     return opkg_what_depends_conflicts_cmd(conf, CONFLICTS, 0, argc, argv);
+     return opkg_what_depends_conflicts_cmd(CONFLICTS, 0, argc, argv);
 }
 
-static int opkg_what_provides_replaces_cmd(opkg_conf_t *conf, enum what_field_type what_field_type, int argc, char **argv)
+static int
+opkg_what_provides_replaces_cmd(enum what_field_type what_field_type, int argc, char **argv)
 {
 
      if (argc > 0) {
@@ -1147,17 +1043,17 @@ static int opkg_what_provides_replaces_cmd(opkg_conf_t *conf, enum what_field_ty
          const char *rel_str = (what_field_type == WHATPROVIDES ? "provides" : "replaces");
          int i;
      
-         pkg_info_preinstall_check(conf);
+         pkg_info_preinstall_check();
 
          if (conf->query_all)
-              pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
+              pkg_hash_fetch_available(available_pkgs);
          else
-              pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
+              pkg_hash_fetch_all_installed(available_pkgs);
          for (i = 0; i < argc; i++) {
               const char *target = argv[i];
               int j;
 
-              opkg_message(conf, OPKG_ERROR, "What %s %s\n",
+              opkg_msg(NOTICE, "What %s %s\n",
                            rel_str, target);
               for (j = 0; j < available_pkgs->len; j++) {
                    pkg_t *pkg = available_pkgs->pkgs[j];
@@ -1169,10 +1065,11 @@ static int opkg_what_provides_replaces_cmd(opkg_conf_t *conf, enum what_field_ty
                               ? pkg->provides[k]
                               : pkg->replaces[k]);
                         if (fnmatch(target, apkg->name, 0) == 0) {
-                             opkg_message(conf, OPKG_ERROR, "    %s", pkg->name);
+                             opkg_msg(NOTICE, "    %s", pkg->name);
                              if (strcmp(target, apkg->name) != 0)
-                                  opkg_message(conf, OPKG_ERROR, "\t%s %s\n", rel_str, apkg->name);
-                             opkg_message(conf, OPKG_ERROR, "\n");
+                                  opkg_msg(NOTICE, "\t%s %s\n",
+                                                  rel_str, apkg->name);
+                             opkg_msg(NOTICE, "\n");
                         }
                    }
               }
@@ -1182,17 +1079,20 @@ static int opkg_what_provides_replaces_cmd(opkg_conf_t *conf, enum what_field_ty
      return 0;
 }
 
-static int opkg_whatprovides_cmd(opkg_conf_t *conf, int argc, char **argv)
+static int
+opkg_whatprovides_cmd(int argc, char **argv)
 {
-     return opkg_what_provides_replaces_cmd(conf, WHATPROVIDES, argc, argv);
+     return opkg_what_provides_replaces_cmd(WHATPROVIDES, argc, argv);
 }
 
-static int opkg_whatreplaces_cmd(opkg_conf_t *conf, int argc, char **argv)
+static int
+opkg_whatreplaces_cmd(int argc, char **argv)
 {
-     return opkg_what_provides_replaces_cmd(conf, WHATREPLACES, argc, argv);
+     return opkg_what_provides_replaces_cmd(WHATREPLACES, argc, argv);
 }
 
-static int opkg_search_cmd(opkg_conf_t *conf, int argc, char **argv)
+static int
+opkg_search_cmd(int argc, char **argv)
 {
      int i;
 
@@ -1203,17 +1103,17 @@ static int opkg_search_cmd(opkg_conf_t *conf, int argc, char **argv)
      char *installed_file;
 
      if (argc < 1) {
-         return EINVAL;
+         return -1;
      }
  
      installed = pkg_vec_alloc();
-     pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
+     pkg_hash_fetch_all_installed(installed);
      pkg_vec_sort(installed, pkg_compare_names);
 
      for (i=0; i < installed->len; i++) {
          pkg = installed->pkgs[i];
 
-         installed_files = pkg_get_installed_files(conf, pkg);
+         installed_files = pkg_get_installed_files(pkg);
 
          for (iter = str_list_first(installed_files); iter; iter = str_list_next(installed_files, iter)) {
               installed_file = (char *)iter->data;
@@ -1229,7 +1129,8 @@ static int opkg_search_cmd(opkg_conf_t *conf, int argc, char **argv)
      return 0;
 }
 
-static int opkg_compare_versions_cmd(opkg_conf_t *conf, int argc, char **argv)
+static int
+opkg_compare_versions_cmd(int argc, char **argv)
 {
      if (argc == 3) {
          /* this is a bit gross */
@@ -1238,14 +1139,15 @@ static int opkg_compare_versions_cmd(opkg_conf_t *conf, int argc, char **argv)
          parse_version(&p2, argv[2]); 
          return pkg_version_satisfied(&p1, &p2, argv[1]);
      } else {
-         opkg_message(conf, OPKG_ERROR,
+         opkg_msg(ERROR,
                       "opkg compare_versions <v1> <op> <v2>\n"
                       "<op> is one of <= >= << >> =\n");
          return -1;
      }
 }
 
-static int opkg_print_architecture_cmd(opkg_conf_t *conf, int argc, char **argv)
+static int
+opkg_print_architecture_cmd(int argc, char **argv)
 {
      nv_pair_list_elt_t *l;
 
@@ -1255,3 +1157,68 @@ static int opkg_print_architecture_cmd(opkg_conf_t *conf, int argc, char **argv)
      }
      return 0;
 }
+
+
+/* XXX: CLEANUP: The usage strings should be incorporated into this
+   array for easier maintenance */
+static opkg_cmd_t cmds[] = {
+     {"update", 0, (opkg_cmd_fun_t)opkg_update_cmd, PFM_DESCRIPTION|PFM_SOURCE},
+     {"upgrade", 0, (opkg_cmd_fun_t)opkg_upgrade_cmd, PFM_DESCRIPTION|PFM_SOURCE},
+     {"list", 0, (opkg_cmd_fun_t)opkg_list_cmd, PFM_SOURCE},
+     {"list_installed", 0, (opkg_cmd_fun_t)opkg_list_installed_cmd, PFM_SOURCE},
+     {"list-installed", 0, (opkg_cmd_fun_t)opkg_list_installed_cmd, PFM_SOURCE},
+     {"list_upgradable", 0, (opkg_cmd_fun_t)opkg_list_upgradable_cmd, PFM_SOURCE},
+     {"list-upgradable", 0, (opkg_cmd_fun_t)opkg_list_upgradable_cmd, PFM_SOURCE},
+     {"info", 0, (opkg_cmd_fun_t)opkg_info_cmd, 0},
+     {"flag", 1, (opkg_cmd_fun_t)opkg_flag_cmd, PFM_DESCRIPTION|PFM_SOURCE},
+     {"status", 0, (opkg_cmd_fun_t)opkg_status_cmd, PFM_DESCRIPTION|PFM_SOURCE},
+     {"install", 1, (opkg_cmd_fun_t)opkg_install_cmd, PFM_DESCRIPTION|PFM_SOURCE},
+     {"remove", 1, (opkg_cmd_fun_t)opkg_remove_cmd, PFM_DESCRIPTION|PFM_SOURCE},
+     {"configure", 0, (opkg_cmd_fun_t)opkg_configure_cmd, PFM_DESCRIPTION|PFM_SOURCE},
+     {"files", 1, (opkg_cmd_fun_t)opkg_files_cmd, PFM_DESCRIPTION|PFM_SOURCE},
+     {"search", 1, (opkg_cmd_fun_t)opkg_search_cmd, PFM_DESCRIPTION|PFM_SOURCE},
+     {"download", 1, (opkg_cmd_fun_t)opkg_download_cmd, PFM_DESCRIPTION|PFM_SOURCE},
+     {"compare_versions", 1, (opkg_cmd_fun_t)opkg_compare_versions_cmd, PFM_DESCRIPTION|PFM_SOURCE},
+     {"compare-versions", 1, (opkg_cmd_fun_t)opkg_compare_versions_cmd, PFM_DESCRIPTION|PFM_SOURCE},
+     {"print-architecture", 0, (opkg_cmd_fun_t)opkg_print_architecture_cmd, PFM_DESCRIPTION|PFM_SOURCE},
+     {"print_architecture", 0, (opkg_cmd_fun_t)opkg_print_architecture_cmd, PFM_DESCRIPTION|PFM_SOURCE},
+     {"print-installation-architecture", 0, (opkg_cmd_fun_t)opkg_print_architecture_cmd, PFM_DESCRIPTION|PFM_SOURCE},
+     {"print_installation_architecture", 0, (opkg_cmd_fun_t)opkg_print_architecture_cmd, PFM_DESCRIPTION|PFM_SOURCE},
+     {"depends", 1, (opkg_cmd_fun_t)opkg_depends_cmd, PFM_DESCRIPTION|PFM_SOURCE},
+     {"whatdepends", 1, (opkg_cmd_fun_t)opkg_whatdepends_cmd, PFM_DESCRIPTION|PFM_SOURCE},
+     {"whatdependsrec", 1, (opkg_cmd_fun_t)opkg_whatdepends_recursively_cmd, PFM_DESCRIPTION|PFM_SOURCE},
+     {"whatrecommends", 1, (opkg_cmd_fun_t)opkg_whatrecommends_cmd, PFM_DESCRIPTION|PFM_SOURCE},
+     {"whatsuggests", 1, (opkg_cmd_fun_t)opkg_whatsuggests_cmd, PFM_DESCRIPTION|PFM_SOURCE},
+     {"whatprovides", 1, (opkg_cmd_fun_t)opkg_whatprovides_cmd, PFM_DESCRIPTION|PFM_SOURCE},
+     {"whatreplaces", 1, (opkg_cmd_fun_t)opkg_whatreplaces_cmd, PFM_DESCRIPTION|PFM_SOURCE},
+     {"whatconflicts", 1, (opkg_cmd_fun_t)opkg_whatconflicts_cmd, PFM_DESCRIPTION|PFM_SOURCE},
+};
+
+opkg_cmd_t *
+opkg_cmd_find(const char *name)
+{
+       int i;
+       opkg_cmd_t *cmd;
+       int num_cmds = sizeof(cmds) / sizeof(opkg_cmd_t);
+
+       for (i=0; i < num_cmds; i++) {
+               cmd = &cmds[i];
+               if (strcmp(name, cmd->name) == 0)
+                       return cmd;
+       }
+
+       return NULL;
+}
+
+int
+opkg_cmd_exec(opkg_cmd_t *cmd, int argc, const char **argv)
+{
+       int result;
+
+       result = (cmd->fun)(argc, argv);
+
+       print_error_list();
+       free_error_list();
+
+       return result;
+}
index 9c9dad2..6d2f1ad 100644 (file)
 #ifndef OPKG_CMD_H
 #define OPKG_CMD_H
 
-typedef int (*opkg_cmd_fun_t)(opkg_conf_t *conf, int argc, const char **argv);
+typedef int (*opkg_cmd_fun_t)(int argc, const char **argv);
 
 struct opkg_cmd
 {
-    char *name;
+    const char *name;
     int requires_args;
     opkg_cmd_fun_t fun;
+    uint pfm; /* package field mask */
 };
 typedef struct opkg_cmd opkg_cmd_t;
 
 opkg_cmd_t *opkg_cmd_find(const char *name);
-int opkg_cmd_exec(opkg_cmd_t *cmd, opkg_conf_t *conf, int argc, 
-                  const char **argv, void *userdata);
+int opkg_cmd_exec(opkg_cmd_t *cmd, int argc, const char **argv);
 
 extern int opkg_state_changed;
 #endif
index 7405b48..69b6935 100644 (file)
@@ -17,7 +17,6 @@
 
 #include "includes.h"
 #include "opkg_conf.h"
-#include "opkg_error.h"
 
 #include "xregex.h"
 #include "sprintf_alloc.h"
 #include <errno.h>
 #include <glob.h>
 
-static int opkg_conf_parse_file(opkg_conf_t *conf, const char *filename,
-                               pkg_src_list_t *pkg_src_list,
-                               nv_pair_list_t *tmp_dest_nv_pair_list);
-static int opkg_conf_set_option(const opkg_option_t *options,
-                               const char *name, const char *value);
-static int opkg_conf_set_default_dest(opkg_conf_t *conf,
-                                     const char *default_dest_name);
-static int set_and_load_pkg_src_list(opkg_conf_t *conf,
-                                    pkg_src_list_t *nv_pair_list);
-static int set_and_load_pkg_dest_list(opkg_conf_t *conf,
-                                     nv_pair_list_t *nv_pair_list);
-
-void opkg_init_options_array(const opkg_conf_t *conf, opkg_option_t **options)
-{
-     opkg_option_t tmp[] = {
-         { "cache", OPKG_OPT_TYPE_STRING, &conf->cache},
-         { "force_defaults", OPKG_OPT_TYPE_BOOL, &conf->force_defaults },
-          { "force_maintainer", OPKG_OPT_TYPE_BOOL, &conf->force_maintainer }, 
-         { "force_depends", OPKG_OPT_TYPE_BOOL, &conf->force_depends },
-         { "force_overwrite", OPKG_OPT_TYPE_BOOL, &conf->force_overwrite },
-         { "force_downgrade", OPKG_OPT_TYPE_BOOL, &conf->force_downgrade },
-         { "force_reinstall", OPKG_OPT_TYPE_BOOL, &conf->force_reinstall },
-         { "force_space", OPKG_OPT_TYPE_BOOL, &conf->force_space },
-          { "check_signature", OPKG_OPT_TYPE_INT, &conf->check_signature }, 
-         { "ftp_proxy", OPKG_OPT_TYPE_STRING, &conf->ftp_proxy },
-         { "http_proxy", OPKG_OPT_TYPE_STRING, &conf->http_proxy },
-         { "no_proxy", OPKG_OPT_TYPE_STRING, &conf->no_proxy },
-         { "test", OPKG_OPT_TYPE_INT, &conf->noaction },
-         { "noaction", OPKG_OPT_TYPE_INT, &conf->noaction },
-         { "nodeps", OPKG_OPT_TYPE_BOOL, &conf->nodeps },
-         { "offline_root", OPKG_OPT_TYPE_STRING, &conf->offline_root },
-         { "offline_root_path", OPKG_OPT_TYPE_STRING, &conf->offline_root_path },
-         { "offline_root_post_script_cmd", OPKG_OPT_TYPE_STRING, &conf->offline_root_post_script_cmd },
-         { "offline_root_pre_script_cmd", OPKG_OPT_TYPE_STRING, &conf->offline_root_pre_script_cmd },
-         { "proxy_passwd", OPKG_OPT_TYPE_STRING, &conf->proxy_passwd },
-         { "proxy_user", OPKG_OPT_TYPE_STRING, &conf->proxy_user },
-         { "query-all", OPKG_OPT_TYPE_BOOL, &conf->query_all },
-         { "tmp_dir", OPKG_OPT_TYPE_STRING, &conf->tmp_dir },
-         { "verbosity", OPKG_OPT_TYPE_BOOL, &conf->verbosity },
+static int lock_fd;
+
+static opkg_conf_t _conf;
+opkg_conf_t *conf = &_conf;
+
+/*
+ * Config file options
+ */
+opkg_option_t options[] = {
+         { "cache", OPKG_OPT_TYPE_STRING, &_conf.cache},
+         { "force_defaults", OPKG_OPT_TYPE_BOOL, &_conf.force_defaults },
+          { "force_maintainer", OPKG_OPT_TYPE_BOOL, &_conf.force_maintainer }, 
+         { "force_depends", OPKG_OPT_TYPE_BOOL, &_conf.force_depends },
+         { "force_overwrite", OPKG_OPT_TYPE_BOOL, &_conf.force_overwrite },
+         { "force_downgrade", OPKG_OPT_TYPE_BOOL, &_conf.force_downgrade },
+         { "force_reinstall", OPKG_OPT_TYPE_BOOL, &_conf.force_reinstall },
+         { "force_space", OPKG_OPT_TYPE_BOOL, &_conf.force_space },
+          { "check_signature", OPKG_OPT_TYPE_BOOL, &_conf.check_signature }, 
+         { "ftp_proxy", OPKG_OPT_TYPE_STRING, &_conf.ftp_proxy },
+         { "http_proxy", OPKG_OPT_TYPE_STRING, &_conf.http_proxy },
+         { "no_proxy", OPKG_OPT_TYPE_STRING, &_conf.no_proxy },
+         { "test", OPKG_OPT_TYPE_BOOL, &_conf.noaction },
+         { "noaction", OPKG_OPT_TYPE_BOOL, &_conf.noaction },
+         { "nodeps", OPKG_OPT_TYPE_BOOL, &_conf.nodeps },
+         { "offline_root", OPKG_OPT_TYPE_STRING, &_conf.offline_root },
+         { "proxy_passwd", OPKG_OPT_TYPE_STRING, &_conf.proxy_passwd },
+         { "proxy_user", OPKG_OPT_TYPE_STRING, &_conf.proxy_user },
+         { "query-all", OPKG_OPT_TYPE_BOOL, &_conf.query_all },
+         { "tmp_dir", OPKG_OPT_TYPE_STRING, &_conf.tmp_dir },
+         { "verbosity", OPKG_OPT_TYPE_INT, &_conf.verbosity },
 #if defined(HAVE_OPENSSL)
-         { "signature_ca_file", OPKG_OPT_TYPE_STRING, &conf->signature_ca_file },
-         { "signature_ca_path", OPKG_OPT_TYPE_STRING, &conf->signature_ca_path },
+         { "signature_ca_file", OPKG_OPT_TYPE_STRING, &_conf.signature_ca_file },
+         { "signature_ca_path", OPKG_OPT_TYPE_STRING, &_conf.signature_ca_path },
 #endif
 #if defined(HAVE_PATHFINDER)
-          { "check_x509_path", OPKG_OPT_TYPE_INT, &conf->check_x509_path }, 
+          { "check_x509_path", OPKG_OPT_TYPE_BOOL, &_conf.check_x509_path }, 
 #endif
 #if defined(HAVE_SSLCURL) && defined(HAVE_CURL)
-          { "ssl_engine", OPKG_OPT_TYPE_STRING, &conf->ssl_engine },
-          { "ssl_cert", OPKG_OPT_TYPE_STRING, &conf->ssl_cert },
-          { "ssl_cert_type", OPKG_OPT_TYPE_STRING, &conf->ssl_cert_type },
-          { "ssl_key", OPKG_OPT_TYPE_STRING, &conf->ssl_key },
-          { "ssl_key_type", OPKG_OPT_TYPE_STRING, &conf->ssl_key_type },
-          { "ssl_key_passwd", OPKG_OPT_TYPE_STRING, &conf->ssl_key_passwd },
-          { "ssl_ca_file", OPKG_OPT_TYPE_STRING, &conf->ssl_ca_file },
-          { "ssl_ca_path", OPKG_OPT_TYPE_STRING, &conf->ssl_ca_path },
-          { "ssl_dont_verify_peer", OPKG_OPT_TYPE_BOOL, &conf->ssl_dont_verify_peer },
+          { "ssl_engine", OPKG_OPT_TYPE_STRING, &_conf.ssl_engine },
+          { "ssl_cert", OPKG_OPT_TYPE_STRING, &_conf.ssl_cert },
+          { "ssl_cert_type", OPKG_OPT_TYPE_STRING, &_conf.ssl_cert_type },
+          { "ssl_key", OPKG_OPT_TYPE_STRING, &_conf.ssl_key },
+          { "ssl_key_type", OPKG_OPT_TYPE_STRING, &_conf.ssl_key_type },
+          { "ssl_key_passwd", OPKG_OPT_TYPE_STRING, &_conf.ssl_key_passwd },
+          { "ssl_ca_file", OPKG_OPT_TYPE_STRING, &_conf.ssl_ca_file },
+          { "ssl_ca_path", OPKG_OPT_TYPE_STRING, &_conf.ssl_ca_path },
+          { "ssl_dont_verify_peer", OPKG_OPT_TYPE_BOOL, &_conf.ssl_dont_verify_peer },
 #endif
-         { NULL }
-     };
-
-     *options = xcalloc(1, sizeof(tmp));
-     memcpy(*options, tmp, sizeof(tmp));
+         { NULL, 0, NULL }
 };
 
-static void opkg_conf_override_string(char **conf_str, char *arg_str) 
-{
-     if (arg_str) {
-         if (*conf_str) {
-              free(*conf_str);
-         }
-         *conf_str = xstrdup(arg_str);
-     }
-}
-
-static void opkg_conf_free_string(char **conf_str)
-{
-     if (*conf_str) {
-         free(*conf_str);
-         *conf_str = NULL;
-     }
-}
-
-int opkg_conf_init(opkg_conf_t *conf, const args_t *args)
-{
-     int err;
-     int errno_copy;
-     char *tmp_dir_base, *tmp2;
-     nv_pair_list_t tmp_dest_nv_pair_list;
-     char *lock_file = NULL;
-     glob_t globbuf;
-     char *etc_opkg_conf_pattern;
-     char *offline_root = NULL;
-
-     memset(conf, 0, sizeof(opkg_conf_t));
-
-#if defined(HAVE_PATHFINDER)
-     conf->check_x509_path = 1;
-#endif
-
-     pkg_src_list_init(&conf->pkg_src_list);
-
-     nv_pair_list_init(&tmp_dest_nv_pair_list);
-     pkg_dest_list_init(&conf->pkg_dest_list);
-
-     nv_pair_list_init(&conf->arch_list);
-
-     conf->restrict_to_default_dest = 0;
-     conf->default_dest = NULL;
-
-     if (args->conf_file) {
-         struct stat stat_buf;
-         err = stat(args->conf_file, &stat_buf);
-         if (err == 0)
-              if (opkg_conf_parse_file(conf, args->conf_file,
-                                   &conf->pkg_src_list, &tmp_dest_nv_pair_list)<0) {
-                   /* Memory leakage from opkg_conf_parse-file */
-                   return -1;
-               }
-     }
-
-     opkg_conf_override_string(&conf->offline_root, args->offline_root);
-     offline_root = conf->offline_root;
-
-     if (conf->offline_root)
-         sprintf_alloc(&etc_opkg_conf_pattern, "%s/etc/opkg/*.conf", conf->offline_root);
-     else {
-         char *conf_file_dir = getenv("OPKG_CONF_DIR");
-         if (conf_file_dir == NULL)
-                 conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR;
-         sprintf_alloc(&etc_opkg_conf_pattern, "%s/*.conf", conf_file_dir);
-     }
-     memset(&globbuf, 0, sizeof(globbuf));
-     err = glob(etc_opkg_conf_pattern, 0, NULL, &globbuf);
-     free (etc_opkg_conf_pattern);
-     if (!err) {
-         int i;
-         for (i = 0; i < globbuf.gl_pathc; i++) {
-              if (globbuf.gl_pathv[i]) 
-                   if (args->conf_file &&
-                               !strcmp(args->conf_file, globbuf.gl_pathv[i]))
-                           continue;
-                   if ( opkg_conf_parse_file(conf, globbuf.gl_pathv[i], 
-                                        &conf->pkg_src_list, &tmp_dest_nv_pair_list)<0) {
-                        /* Memory leakage from opkg_conf_parse-file */
-                        return -1;
-                   }
-                    if (offline_root != conf->offline_root) {
-                        opkg_message(conf, OPKG_ERROR,
-                                       "Config file %s, within an offline "
-                                       "root contains option offline_root.\n",
-                                      globbuf.gl_pathv[i]);
-                        return -1;
-                    }
-         }
-     }
-     globfree(&globbuf);
-
-     opkg_conf_override_string(&conf->offline_root_path, 
-                              args->offline_root_path);
-     opkg_conf_override_string(&conf->offline_root_pre_script_cmd, 
-                              args->offline_root_pre_script_cmd);
-     opkg_conf_override_string(&conf->offline_root_post_script_cmd, 
-                              args->offline_root_post_script_cmd);
-
-     opkg_conf_override_string(&conf->cache, args->cache);
-     opkg_conf_override_string(&conf->tmp_dir, args->tmp_dir);
-
-     /* check for lock file */
-     if (conf->offline_root)
-       sprintf_alloc (&lock_file, "%s/%s/lock", conf->offline_root, OPKG_STATE_DIR_PREFIX);
-     else
-       sprintf_alloc (&lock_file, "%s/lock", OPKG_STATE_DIR_PREFIX);
-
-     err = conf->lock_fd = creat (lock_file, S_IRUSR | S_IWUSR | S_IRGRP);
-     if (err != -1)
-       err = lockf (conf->lock_fd, F_TLOCK, 0);
-     errno_copy = errno;
-
-     if (err) {
-       opkg_message (conf, OPKG_ERROR, "Could not lock %s: %s\n",
-                 lock_file, strerror(errno_copy));
-       free(lock_file);
-       return -1;
-     }
-     free(lock_file);
-
-     if (conf->tmp_dir)
-         tmp_dir_base = conf->tmp_dir;
-     else 
-         tmp_dir_base = getenv("TMPDIR");
-     sprintf_alloc(&tmp2, "%s/%s",
-                  tmp_dir_base ? tmp_dir_base : OPKG_CONF_DEFAULT_TMP_DIR_BASE,
-                  OPKG_CONF_TMP_DIR_SUFFIX);
-     if (conf->tmp_dir)
-            free(conf->tmp_dir);
-     conf->tmp_dir = mkdtemp(tmp2);
-     if (conf->tmp_dir == NULL) {
-         opkg_message(conf, OPKG_ERROR,
-                         "%s: Creating temp dir %s failed: %s\n",
-                         __FUNCTION__, tmp2, strerror(errno));
-         return -1;
-     }
-
-     pkg_hash_init("pkg-hash", &conf->pkg_hash, OPKG_CONF_DEFAULT_HASH_LEN);
-     hash_table_init("file-hash", &conf->file_hash, OPKG_CONF_DEFAULT_HASH_LEN);
-     hash_table_init("obs-file-hash", &conf->obs_file_hash, OPKG_CONF_DEFAULT_HASH_LEN/16);
-
-     if (conf->lists_dir == NULL)
-        conf->lists_dir = xstrdup(OPKG_CONF_LISTS_DIR);
-
-     if (conf->offline_root) {
-            char *tmp;
-            sprintf_alloc(&tmp, "%s/%s", conf->offline_root, conf->lists_dir);
-            free(conf->lists_dir);
-            conf->lists_dir = tmp;
-     }
-
-     /* if no architectures were defined, then default all, noarch, and host architecture */
-     if (nv_pair_list_empty(&conf->arch_list)) {
-         nv_pair_list_append(&conf->arch_list, "all", "1");
-         nv_pair_list_append(&conf->arch_list, "noarch", "1");
-         nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10");
-     }
-
-     /* Even if there is no conf file, we'll need at least one dest. */
-     if (nv_pair_list_empty(&tmp_dest_nv_pair_list)) {
-         nv_pair_list_append(&tmp_dest_nv_pair_list,
-                             OPKG_CONF_DEFAULT_DEST_NAME,
-                             OPKG_CONF_DEFAULT_DEST_ROOT_DIR);
-     }
-
-     /* After parsing the file, set options from command-line, (so that
-       command-line arguments take precedence) */
-     /* XXX: CLEANUP: The interaction between args.c and opkg_conf.c
-       really needs to be cleaned up. There is so much duplication
-       right now it is ridiculous. Maybe opkg_conf_t should just save
-       a pointer to args_t (which could then not be freed), rather
-       than duplicating every field here? */
-     if (args->autoremove) {
-         conf->autoremove = 1;
-     }
-     if (args->force_depends) {
-         conf->force_depends = 1;
-     }
-     if (args->force_defaults) {
-         conf->force_defaults = 1;
-     }
-     if (args->force_maintainer) {
-          conf->force_maintainer = 1;
-     }
-     if (args->force_overwrite) {
-         conf->force_overwrite = 1;
-     }
-     if (args->force_downgrade) {
-         conf->force_downgrade = 1;
-     }
-     if (args->force_space) {
-         conf->force_space = 1;
-     }
-     if (args->force_reinstall) {
-         conf->force_reinstall = 1;
-     }
-     if (args->force_removal_of_dependent_packages) {
-         conf->force_removal_of_dependent_packages = 1;
-     }
-     if (args->force_removal_of_essential_packages) {
-         conf->force_removal_of_essential_packages = 1;
-     }
-     if (args->nodeps) {
-         conf->nodeps = 1;
-     }
-     if (args->noaction) {
-         conf->noaction = 1;
-     }
-     if (args->query_all) {
-         conf->query_all = 1;
-     }
-     if (args->verbosity != conf->verbosity) {
-         conf->verbosity = args->verbosity;
-     } 
-
-/* Pigi: added a flag to disable the checking of structures if the command does not need to 
-         read anything from there.
-*/
-     if (!(args->nocheckfordirorfile)) {
-
-        if (!(args->noreadfeedsfile)) {
-           if (set_and_load_pkg_src_list(conf, &conf->pkg_src_list)) {
-               nv_pair_list_deinit(&tmp_dest_nv_pair_list);
-              return -1;
-          }
-       }
-   
-        /* Now that we have resolved conf->offline_root, we can commit to
-          the directory names for the dests and load in all the package
-          lists. */
-        if (set_and_load_pkg_dest_list(conf, &tmp_dest_nv_pair_list)) {
-               nv_pair_list_deinit(&tmp_dest_nv_pair_list);
-              return -1;
-       }
-   
-        if (args->dest) {
-            err = opkg_conf_set_default_dest(conf, args->dest);
-            if (err) {
-                  nv_pair_list_deinit(&tmp_dest_nv_pair_list);
-                 return -1;
-            }
-        }
-     }
-     nv_pair_list_deinit(&tmp_dest_nv_pair_list);
-
-     return 0;
-}
-
-void opkg_conf_deinit(opkg_conf_t *conf)
-{
-     rm_r(conf->tmp_dir);
-
-     free(conf->tmp_dir);
-     free(conf->lists_dir);
-
-     pkg_src_list_deinit(&conf->pkg_src_list);
-     pkg_dest_list_deinit(&conf->pkg_dest_list);
-     nv_pair_list_deinit(&conf->arch_list);
-
-     opkg_conf_free_string(&conf->cache);
-
-     opkg_conf_free_string(&conf->ftp_proxy);
-     opkg_conf_free_string(&conf->http_proxy);
-     opkg_conf_free_string(&conf->no_proxy);
-
-     opkg_conf_free_string(&conf->offline_root);
-     opkg_conf_free_string(&conf->offline_root_path);
-     opkg_conf_free_string(&conf->offline_root_pre_script_cmd);
-     opkg_conf_free_string(&conf->offline_root_post_script_cmd);
-
-     opkg_conf_free_string(&conf->proxy_passwd);
-     opkg_conf_free_string(&conf->proxy_user);
-
-#if defined(HAVE_OPENSSL)
-     opkg_conf_free_string(&conf->signature_ca_file);
-     opkg_conf_free_string(&conf->signature_ca_path);
-#endif
-
-#if defined(HAVE_SSLCURL)
-     opkg_conf_free_string(&conf->ssl_engine);
-     opkg_conf_free_string(&conf->ssl_cert);
-     opkg_conf_free_string(&conf->ssl_cert_type);
-     opkg_conf_free_string(&conf->ssl_key);
-     opkg_conf_free_string(&conf->ssl_key_type);
-     opkg_conf_free_string(&conf->ssl_key_passwd);
-     opkg_conf_free_string(&conf->ssl_ca_file);
-     opkg_conf_free_string(&conf->ssl_ca_path);
-#endif
-
-     if (conf->verbosity >= OPKG_DEBUG) { 
-       hash_print_stats(&conf->pkg_hash);
-       hash_print_stats(&conf->file_hash);
-       hash_print_stats(&conf->obs_file_hash);
-     }
-
-     if (&conf->pkg_hash)
-                   pkg_hash_deinit(&conf->pkg_hash);
-     if (&conf->file_hash)
-                   hash_table_deinit(&conf->file_hash);
-     if (&conf->obs_file_hash)
-                   hash_table_deinit(&conf->obs_file_hash);
-
-     /* lockf maybe defined with warn_unused_result */
-     if(lockf(conf->lock_fd, F_ULOCK, 0) != 0){
-              opkg_message(conf, OPKG_DEBUG, "%s: unlock failed: %s\n",
-                              __FUNCTION__, 
-                              strerror(errno));
-     }
-     close(conf->lock_fd);
-}
-
-static int opkg_conf_set_default_dest(opkg_conf_t *conf,
-                                     const char *default_dest_name)
+static int
+opkg_conf_set_default_dest(const char *default_dest_name)
 {
      pkg_dest_list_elt_t *iter;
      pkg_dest_t *dest;
@@ -425,13 +98,13 @@ static int opkg_conf_set_default_dest(opkg_conf_t *conf,
          }
      }
 
-     fprintf(stderr, "ERROR: Unknown dest name: `%s'\n", default_dest_name);
+     opkg_msg(ERROR, "Unknown dest name: `%s'.\n", default_dest_name);
 
      return 1;
 }
 
 static int
-set_and_load_pkg_src_list(opkg_conf_t *conf, pkg_src_list_t *pkg_src_list)
+set_and_load_pkg_src_list(pkg_src_list_t *pkg_src_list)
 {
      pkg_src_list_elt_t *iter;
      pkg_src_t *src;
@@ -448,7 +121,7 @@ set_and_load_pkg_src_list(opkg_conf_t *conf, pkg_src_list_t *pkg_src_list)
                          src->name);
 
          if (file_exists(list_file)) {
-              if (pkg_hash_add_from_file(conf, list_file, src, NULL, 0)) {
+              if (pkg_hash_add_from_file(list_file, src, NULL, 0)) {
                    free(list_file);
                    return -1;
               }
@@ -460,7 +133,7 @@ set_and_load_pkg_src_list(opkg_conf_t *conf, pkg_src_list_t *pkg_src_list)
 }
 
 static int
-set_and_load_pkg_dest_list(opkg_conf_t *conf, nv_pair_list_t *nv_pair_list)
+set_and_load_pkg_dest_list(nv_pair_list_t *nv_pair_list)
 {
      nv_pair_list_elt_t *iter;
      nv_pair_t *nv_pair;
@@ -484,7 +157,7 @@ set_and_load_pkg_dest_list(opkg_conf_t *conf, nv_pair_list_t *nv_pair_list)
               conf->default_dest = dest;
          }
          if (file_exists(dest->status_file_name)) {
-              if (pkg_hash_add_from_file(conf, dest->status_file_name,
+              if (pkg_hash_add_from_file(dest->status_file_name,
                                      NULL, dest, 1))
                       return -1;
          }
@@ -493,38 +166,87 @@ set_and_load_pkg_dest_list(opkg_conf_t *conf, nv_pair_list_t *nv_pair_list)
      return 0;
 }
 
-static int opkg_conf_parse_file(opkg_conf_t *conf, const char *filename,
+static int
+opkg_conf_set_option(const char *name, const char *value)
+{
+     int i = 0;
+     while (options[i].name) {
+         if (strcmp(options[i].name, name) == 0) {
+              switch (options[i].type) {
+              case OPKG_OPT_TYPE_BOOL:
+                   if (*(int *)options[i].value) {
+                           opkg_msg(ERROR, "Duplicate boolean option %s, "
+                               "leaving this option on.\n", name);
+                           return 0;
+                   }
+                   *((int * const)options[i].value) = 1;
+                   return 0;
+              case OPKG_OPT_TYPE_INT:
+                   if (value) {
+                           if (*(int *)options[i].value) {
+                                   opkg_msg(ERROR, "Duplicate option %s, "
+                                       "using first seen value \"%d\".\n",
+                                       name, *((int *)options[i].value));
+                                   return 0;
+                           }
+                        *((int * const)options[i].value) = atoi(value);
+                        return 0;
+                   } else {
+                        opkg_msg(ERROR, "Option %s needs an argument\n",
+                               name);
+                        return -1;
+                   }               
+              case OPKG_OPT_TYPE_STRING:
+                   if (value) {
+                           if (*(char **)options[i].value) {
+                                   opkg_msg(ERROR, "Duplicate option %s, "
+                                       "using first seen value \"%s\".\n",
+                                       name, *((char **)options[i].value));
+                                   return 0;
+                           }
+                        *((char ** const)options[i].value) = xstrdup(value);
+                        return 0;
+                   } else {
+                        opkg_msg(ERROR, "Option %s needs an argument\n",
+                               name);
+                        return -1;
+                   }
+              }
+         }
+         i++;
+     }
+    
+     opkg_msg(ERROR, "Unrecognized option: %s=%s\n", name, value);
+     return -1;
+}
+
+static int
+opkg_conf_parse_file(const char *filename,
                                pkg_src_list_t *pkg_src_list,
                                nv_pair_list_t *tmp_dest_nv_pair_list)
 {
      int err;
-     opkg_option_t * options;
      FILE *file;
      regex_t valid_line_re, comment_re;
 #define regmatch_size 12
      regmatch_t regmatch[regmatch_size];
 
-     opkg_init_options_array(conf, &options);
-
      file = fopen(filename, "r");
      if (file == NULL) {
-         fprintf(stderr, "%s: failed to open %s: %s\n",
-                 __FUNCTION__, filename, strerror(errno));
-         free(options);
+         opkg_perror(ERROR, "Failed to open %s", filename);
          return -1;
      }
-     opkg_message(conf, OPKG_NOTICE, "loading conf file %s\n", filename);
+
+     opkg_msg(INFO, "Loading conf file %s.\n", filename);
 
      err = xregcomp(&comment_re, 
                    "^[[:space:]]*(#.*|[[:space:]]*)$",
                    REG_EXTENDED);
      if (err) {
-         free(options);
          return -1;
      }
      err = xregcomp(&valid_line_re, "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))([[:space:]]+([^[:space:]]+))?[[:space:]]*$", REG_EXTENDED);
      if (err) {
-         free(options);
          return -1;
      }
 
@@ -544,7 +266,7 @@ static int opkg_conf_parse_file(opkg_conf_t *conf, const char *filename,
          }
 
          if (regexec(&valid_line_re, line, regmatch_size, regmatch, 0) == REG_NOMATCH) {
-              fprintf(stderr, "%s:%d: Ignoring invalid line: `%s'\n",
+              opkg_msg(ERROR, "%s:%d: Ignoring invalid line: `%s'\n",
                       filename, line_num, line);
               goto NEXT_LINE;
          }
@@ -584,36 +306,36 @@ static int opkg_conf_parse_file(opkg_conf_t *conf, const char *filename,
             pkg_dest_list_init. (We do a similar thing with
             tmp_src_nv_pair_list for sake of symmetry.) */
          if (strcmp(type, "option") == 0) {
-              opkg_conf_set_option(options, name, value);
+              opkg_conf_set_option(name, value);
          } else if (strcmp(type, "src") == 0) {
               if (!nv_pair_list_find((nv_pair_list_t*) pkg_src_list, name)) {
                    pkg_src_list_append (pkg_src_list, name, value, extra, 0);
               } else {
-                   opkg_message(conf, OPKG_ERROR, "ERROR: duplicate src declaration.  Skipping:\n\t src %s %s\n",
-                                name, value);
+                   opkg_msg(ERROR, "Duplicate src declaration (%s %s). "
+                                   "Skipping.\n", name, value);
               }
          } else if (strcmp(type, "src/gz") == 0) {
               if (!nv_pair_list_find((nv_pair_list_t*) pkg_src_list, name)) {
                    pkg_src_list_append (pkg_src_list, name, value, extra, 1);
               } else {
-                   opkg_message(conf, OPKG_ERROR, "ERROR: duplicate src declaration.  Skipping:\n\t src %s %s\n",
-                                name, value);
+                   opkg_msg(ERROR, "Duplicate src declaration (%s %s). "
+                                  "Skipping.\n", name, value);
               }
          } else if (strcmp(type, "dest") == 0) {
               nv_pair_list_append(tmp_dest_nv_pair_list, name, value);
          } else if (strcmp(type, "lists_dir") == 0) {
               conf->lists_dir = xstrdup(value);
          } else if (strcmp(type, "arch") == 0) {
-              opkg_message(conf, OPKG_INFO, "supported arch %s priority (%s)\n", name, value);
+              opkg_msg(INFO, "Supported arch %s priority (%s)\n", name, value);
               if (!value) {
-                   opkg_message(conf, OPKG_NOTICE, "defaulting architecture %s priority to 10\n", name);
+                   opkg_msg(NOTICE, "No priority given for architecture %s,"
+                                  "defaulting to 10\n", name);
                    value = xstrdup("10");
               }
               nv_pair_list_append(&conf->arch_list, name, value);
          } else {
-              fprintf(stderr, "WARNING: Ignoring unknown configuration "
+              opkg_msg(ERROR, "Ignoring unknown configuration "
                       "parameter: %s %s %s\n", type, name, value);
-              free(options);
               return -1;
          }
 
@@ -627,7 +349,6 @@ static int opkg_conf_parse_file(opkg_conf_t *conf, const char *filename,
          free(line);
      }
 
-     free(options);
      regfree(&comment_re);
      regfree(&valid_line_re);
      fclose(file);
@@ -635,45 +356,8 @@ static int opkg_conf_parse_file(opkg_conf_t *conf, const char *filename,
      return 0;
 }
 
-static int opkg_conf_set_option(const opkg_option_t *options,
-                               const char *name, const char *value)
-{
-     int i = 0;
-     while (options[i].name) {
-         if (strcmp(options[i].name, name) == 0) {
-              switch (options[i].type) {
-              case OPKG_OPT_TYPE_BOOL:
-                   *((int *)options[i].value) = 1;
-                   return 0;
-              case OPKG_OPT_TYPE_INT:
-                   if (value) {
-                        *((int *)options[i].value) = atoi(value);
-                        return 0;
-                   } else {
-                        printf("%s: Option %s need an argument\n",
-                               __FUNCTION__, name);
-                        return EINVAL;
-                   }               
-              case OPKG_OPT_TYPE_STRING:
-                   if (value) {
-                        *((char **)options[i].value) = xstrdup(value);
-                        return 0;
-                   } else {
-                        printf("%s: Option %s need an argument\n",
-                               __FUNCTION__, name);
-                        return EINVAL;
-                   }
-              }
-         }
-         i++;
-     }
-    
-     fprintf(stderr, "%s: Unrecognized option: %s=%s\n",
-            __FUNCTION__, name, value);
-     return EINVAL;
-}
-
-int opkg_conf_write_status_files(opkg_conf_t *conf)
+int
+opkg_conf_write_status_files(void)
 {
      pkg_dest_list_elt_t *iter;
      pkg_dest_t *dest;
@@ -689,14 +373,14 @@ int opkg_conf_write_status_files(opkg_conf_t *conf)
 
           dest->status_fp = fopen(dest->status_file_name, "w");
           if (dest->status_fp == NULL) {
-               fprintf(stderr, "%s: Can't open status file: %s: %s\n",
-                    __FUNCTION__, dest->status_file_name, strerror(errno));
+               opkg_perror(ERROR, "Can't open status file %s",
+                    dest->status_file_name);
                ret = -1;
           }
      }
 
      all = pkg_vec_alloc();
-     pkg_hash_fetch_available(&conf->pkg_hash, all);
+     pkg_hash_fetch_available(all);
 
      for(i = 0; i < all->len; i++) {
          pkg = all->pkgs[i];
@@ -708,9 +392,8 @@ int opkg_conf_write_status_files(opkg_conf_t *conf)
               continue;
          }
          if (pkg->dest == NULL) {
-              fprintf(stderr, "%s: ERROR: Can't write status for "
-                      "package %s since it has a NULL dest\n",
-                      __FUNCTION__, pkg->name);
+              opkg_msg(ERROR, "Internal error: package %s has a NULL dest\n",
+                      pkg->name);
               continue;
          }
          if (pkg->dest->status_fp)
@@ -728,9 +411,210 @@ int opkg_conf_write_status_files(opkg_conf_t *conf)
 }
 
 
-char *root_filename_alloc(opkg_conf_t *conf, char *filename)
+char *
+root_filename_alloc(char *filename)
+{
+       char *root_filename;
+       sprintf_alloc(&root_filename, "%s%s",
+               (conf->offline_root ? conf->offline_root : ""), filename);
+       return root_filename;
+}
+
+int
+opkg_conf_init(const args_t *args)
 {
-     char *root_filename;
-     sprintf_alloc(&root_filename, "%s%s", (conf->offline_root ? conf->offline_root : ""), filename);
-     return root_filename;
+     int err;
+     char *tmp_dir_base, *tmp2;
+     nv_pair_list_t tmp_dest_nv_pair_list;
+     char *lock_file = NULL;
+     glob_t globbuf;
+     char *etc_opkg_conf_pattern;
+
+     conf->restrict_to_default_dest = 0;
+     conf->default_dest = NULL;
+#if defined(HAVE_PATHFINDER)
+     conf->check_x509_path = 1;
+#endif
+
+     pkg_src_list_init(&conf->pkg_src_list);
+
+     nv_pair_list_init(&tmp_dest_nv_pair_list);
+     pkg_dest_list_init(&conf->pkg_dest_list);
+
+     nv_pair_list_init(&conf->arch_list);
+
+     if (args->conf_file) {
+         struct stat stat_buf;
+         err = stat(args->conf_file, &stat_buf);
+         if (err == 0)
+              if (opkg_conf_parse_file(args->conf_file,
+                                   &conf->pkg_src_list, &tmp_dest_nv_pair_list)<0) {
+                   /* Memory leakage from opkg_conf_parse-file */
+                   return -1;
+               }
+     }
+
+     if (conf->offline_root)
+         sprintf_alloc(&etc_opkg_conf_pattern, "%s/etc/opkg/*.conf", conf->offline_root);
+     else {
+         const char *conf_file_dir = getenv("OPKG_CONF_DIR");
+         if (conf_file_dir == NULL)
+                 conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR;
+         sprintf_alloc(&etc_opkg_conf_pattern, "%s/*.conf", conf_file_dir);
+     }
+     memset(&globbuf, 0, sizeof(globbuf));
+     err = glob(etc_opkg_conf_pattern, 0, NULL, &globbuf);
+     free (etc_opkg_conf_pattern);
+     if (!err) {
+         int i;
+         for (i = 0; i < globbuf.gl_pathc; i++) {
+              if (globbuf.gl_pathv[i]) 
+                   if (args->conf_file &&
+                               !strcmp(args->conf_file, globbuf.gl_pathv[i]))
+                           continue;
+                   if ( opkg_conf_parse_file(globbuf.gl_pathv[i], 
+                                        &conf->pkg_src_list, &tmp_dest_nv_pair_list)<0) {
+                        /* Memory leakage from opkg_conf_parse-file */
+                        return -1;
+                   }
+         }
+     }
+     globfree(&globbuf);
+
+     /* check for lock file */
+     if (conf->offline_root)
+       sprintf_alloc (&lock_file, "%s/%s/lock", conf->offline_root, OPKG_STATE_DIR_PREFIX);
+     else
+       sprintf_alloc (&lock_file, "%s/lock", OPKG_STATE_DIR_PREFIX);
+
+     if (creat(lock_file, S_IRUSR | S_IWUSR | S_IRGRP) == -1) {
+            opkg_perror(ERROR, "Could not create lock file %s", lock_file);
+            free(lock_file);
+            return -1;
+     }
+
+     if (lockf(lock_fd, F_TLOCK, (off_t)0) == -1) {
+         opkg_perror(ERROR, "Could not lock %s", lock_file);
+         free(lock_file);
+         return -1;
+     }
+
+     free(lock_file);
+
+     if (conf->tmp_dir)
+         tmp_dir_base = conf->tmp_dir;
+     else 
+         tmp_dir_base = getenv("TMPDIR");
+     sprintf_alloc(&tmp2, "%s/%s",
+                  tmp_dir_base ? tmp_dir_base : OPKG_CONF_DEFAULT_TMP_DIR_BASE,
+                  OPKG_CONF_TMP_DIR_SUFFIX);
+     if (conf->tmp_dir)
+            free(conf->tmp_dir);
+     conf->tmp_dir = mkdtemp(tmp2);
+     if (conf->tmp_dir == NULL) {
+         opkg_perror(ERROR, "Creating temp dir %s failed", tmp2);
+         return -1;
+     }
+
+     pkg_hash_init();
+     hash_table_init("file-hash", &conf->file_hash, OPKG_CONF_DEFAULT_HASH_LEN);
+     hash_table_init("obs-file-hash", &conf->obs_file_hash, OPKG_CONF_DEFAULT_HASH_LEN/16);
+
+     if (conf->lists_dir == NULL)
+        conf->lists_dir = xstrdup(OPKG_CONF_LISTS_DIR);
+
+     if (conf->offline_root) {
+            char *tmp;
+            sprintf_alloc(&tmp, "%s/%s", conf->offline_root, conf->lists_dir);
+            free(conf->lists_dir);
+            conf->lists_dir = tmp;
+     }
+
+     /* if no architectures were defined, then default all, noarch, and host architecture */
+     if (nv_pair_list_empty(&conf->arch_list)) {
+         nv_pair_list_append(&conf->arch_list, "all", "1");
+         nv_pair_list_append(&conf->arch_list, "noarch", "1");
+         nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10");
+     }
+
+     /* Even if there is no conf file, we'll need at least one dest. */
+     if (nv_pair_list_empty(&tmp_dest_nv_pair_list)) {
+         nv_pair_list_append(&tmp_dest_nv_pair_list,
+                             OPKG_CONF_DEFAULT_DEST_NAME,
+                             OPKG_CONF_DEFAULT_DEST_ROOT_DIR);
+     }
+
+     if (!(args->nocheckfordirorfile)) {
+
+        if (!(args->noreadfeedsfile)) {
+           if (set_and_load_pkg_src_list(&conf->pkg_src_list)) {
+               nv_pair_list_deinit(&tmp_dest_nv_pair_list);
+              return -1;
+          }
+       }
+   
+        /* Now that we have resolved conf->offline_root, we can commit to
+          the directory names for the dests and load in all the package
+          lists. */
+        if (set_and_load_pkg_dest_list(&tmp_dest_nv_pair_list)) {
+               nv_pair_list_deinit(&tmp_dest_nv_pair_list);
+              return -1;
+       }
+   
+        if (args->dest) {
+            err = opkg_conf_set_default_dest(args->dest);
+            if (err) {
+                  nv_pair_list_deinit(&tmp_dest_nv_pair_list);
+                 return -1;
+            }
+        }
+     }
+     nv_pair_list_deinit(&tmp_dest_nv_pair_list);
+
+     return 0;
+}
+
+void
+opkg_conf_deinit(void)
+{
+       int i;
+       char **tmp;
+
+       rm_r(conf->tmp_dir);
+
+       free(conf->lists_dir);
+
+       pkg_src_list_deinit(&conf->pkg_src_list);
+       pkg_dest_list_deinit(&conf->pkg_dest_list);
+       nv_pair_list_deinit(&conf->arch_list);
+
+       for (i=0; options[i].name; i++) {
+               if (options[i].type == OPKG_OPT_TYPE_STRING) {
+                       tmp = (char **)options[i].value;
+                       if (*tmp) {
+                               free(*tmp);
+                               *tmp = NULL;
+                       }
+               }
+       }
+
+       if (conf->verbosity >= DEBUG) { 
+               hash_print_stats(&conf->pkg_hash);
+               hash_print_stats(&conf->file_hash);
+               hash_print_stats(&conf->obs_file_hash);
+       }
+
+       if (&conf->pkg_hash)
+               pkg_hash_deinit();
+       if (&conf->file_hash)
+               hash_table_deinit(&conf->file_hash);
+       if (&conf->obs_file_hash)
+               hash_table_deinit(&conf->obs_file_hash);
+
+       /* lockf may be defined with warn_unused_result */
+       if (lockf(lock_fd, F_ULOCK, (off_t)0) != 0) {
+               opkg_perror(ERROR, "unlock failed");
+       }
+
+       close(lock_fd);
 }
index fc14e09..a268bba 100644 (file)
@@ -19,6 +19,7 @@
 #define OPKG_CONF_H
 
 typedef struct opkg_conf opkg_conf_t;
+extern opkg_conf_t *conf;
 
 #include "hash_table.h"
 #include "args.h"
@@ -40,7 +41,6 @@ typedef struct opkg_conf opkg_conf_t;
 
 struct opkg_conf
 {
-     int lock_fd; /* file descriptor for the lock file */
      pkg_src_list_t pkg_src_list;
      pkg_dest_list_t pkg_dest_list;
      nv_pair_list_t arch_list;
@@ -51,6 +51,8 @@ struct opkg_conf
      char *tmp_dir;
      char *lists_dir;
 
+     uint pfm; /* package field mask */
+
      /* options */
      int autoremove;
      int force_depends;
@@ -65,9 +67,6 @@ struct opkg_conf
      int check_signature;
      int nodeps; /* do not follow dependences */
      char *offline_root;
-     char *offline_root_path;
-     char *offline_root_pre_script_cmd;
-     char *offline_root_post_script_cmd;
      int query_all;
      int verbosity;
      int noaction;
@@ -118,16 +117,13 @@ typedef struct opkg_option opkg_option_t;
 struct opkg_option {
      const char *name;
      const opkg_option_type_t type;
-     const void *value;
+     void * const value;
 };
 
-int opkg_conf_init(opkg_conf_t *conf, const args_t *args);
-void opkg_conf_deinit(opkg_conf_t *conf);
-
-int opkg_conf_write_status_files(opkg_conf_t *conf);
-char *root_filename_alloc(opkg_conf_t *conf, char *filename);
-
+int opkg_conf_init(const args_t *args);
+void opkg_conf_deinit(void);
 
-void opkg_init_options_array(const opkg_conf_t *conf, opkg_option_t **options);
+int opkg_conf_write_status_files(void);
+char *root_filename_alloc(char *filename);
 
 #endif
index 2c22bfc..154d3e6 100644 (file)
@@ -21,7 +21,8 @@
 #include "opkg_message.h"
 #include "opkg_cmd.h"
 
-int opkg_configure(opkg_conf_t *conf, pkg_t *pkg)
+int
+opkg_configure(pkg_t *pkg)
 {
     int err;
 
@@ -31,9 +32,9 @@ int opkg_configure(opkg_conf_t *conf, pkg_t *pkg)
     /* DPKG_INCOMPATIBILITY:
        dpkg actually includes a version number to this script call */
 
-    err = pkg_run_script(conf, pkg, "postinst", "configure");
+    err = pkg_run_script(pkg, "postinst", "configure");
     if (err) {
-       opkg_message(conf, OPKG_ERROR, "ERROR: %s.postinst returned %d\n", pkg->name, err);
+       opkg_msg(ERROR, "%s.postinst returned %d.\n", pkg->name, err);
        return err;
     }
 
index e3178b8..25236ae 100644 (file)
@@ -20,6 +20,6 @@
 
 #include "opkg_conf.h"
 
-int opkg_configure(opkg_conf_t *opkg_conf, pkg_t *pkg);
+int opkg_configure(pkg_t *pkg);
 
 #endif
index c4b2f0c..7062766 100644 (file)
@@ -58,7 +58,7 @@ static void openssl_init(void);
 #endif
 
 #ifdef HAVE_OPENSSL
-static X509_STORE *setup_verify(opkg_conf_t *conf, char *CAfile, char *CApath);
+static X509_STORE *setup_verify(char *CAfile, char *CApath);
 #endif
 
 #ifdef HAVE_CURL
@@ -67,7 +67,7 @@ static X509_STORE *setup_verify(opkg_conf_t *conf, char *CAfile, char *CApath);
  * each time
  */
 static CURL *curl = NULL;
-static CURL *opkg_curl_init(opkg_conf_t *conf, curl_progress_func cb, void *data);
+static CURL *opkg_curl_init(curl_progress_func cb, void *data);
 #endif
 
 static int
@@ -76,8 +76,9 @@ str_starts_with(const char *str, const char *prefix)
     return (strncmp(str, prefix, strlen(prefix)) == 0);
 }
 
-int opkg_download(opkg_conf_t *conf, const char *src,
-  const char *dest_file_name, curl_progress_func cb, void *data)
+int
+opkg_download(const char *src, const char *dest_file_name,
+       curl_progress_func cb, void *data)
 {
     int err = 0;
 
@@ -85,37 +86,39 @@ int opkg_download(opkg_conf_t *conf, const char *src,
     char *src_base = basename(src_basec);
     char *tmp_file_location;
 
-    opkg_message(conf,OPKG_NOTICE,"Downloading %s\n", src);
+    free(src_basec);
+
+    opkg_msg(NOTICE,"Downloading %s.\n", src);
        
     if (str_starts_with(src, "file:")) {
        const char *file_src = src + 5;
-       opkg_message(conf,OPKG_INFO,"Copying %s to %s...", file_src, dest_file_name);
+       opkg_msg(INFO, "Copying %s to %s...", file_src, dest_file_name);
        err = file_copy(file_src, dest_file_name);
-       opkg_message(conf,OPKG_INFO,"Done\n");
-        free(src_basec);
+       opkg_msg(INFO, "Done.\n");
        return err;
     }
 
     sprintf_alloc(&tmp_file_location, "%s/%s", conf->tmp_dir, src_base);
     err = unlink(tmp_file_location);
     if (err && errno != ENOENT) {
-       opkg_message(conf,OPKG_ERROR, "%s: ERROR: failed to unlink %s: %s\n",
-               __FUNCTION__, tmp_file_location, strerror(errno));
+       opkg_perror(ERROR, "Failed to unlink %s\n", tmp_file_location);
        free(tmp_file_location);
-        free(src_basec);
        return -1;
     }
 
     if (conf->http_proxy) {
-       opkg_message(conf,OPKG_DEBUG,"Setting environment variable: http_proxy = %s\n", conf->http_proxy);
+       opkg_msg(DEBUG, "Setting environment variable: http_proxy = %s.\n",
+               conf->http_proxy);
        setenv("http_proxy", conf->http_proxy, 1);
     }
     if (conf->ftp_proxy) {
-       opkg_message(conf,OPKG_DEBUG,"Setting environment variable: ftp_proxy = %s\n", conf->ftp_proxy);
+       opkg_msg(DEBUG, "Setting environment variable: ftp_proxy = %s.\n",
+               conf->ftp_proxy);
        setenv("ftp_proxy", conf->ftp_proxy, 1);
     }
     if (conf->no_proxy) {
-       opkg_message(conf,OPKG_DEBUG,"Setting environment variable: no_proxy = %s\n", conf->no_proxy);
+       opkg_msg(DEBUG,"Setting environment variable: no_proxy = %s.\n",
+               conf->no_proxy);
        setenv("no_proxy", conf->no_proxy, 1);
     }
 
@@ -123,7 +126,7 @@ int opkg_download(opkg_conf_t *conf, const char *src,
     CURLcode res;
     FILE * file = fopen (tmp_file_location, "w");
 
-    curl = opkg_curl_init (conf, cb, data);
+    curl = opkg_curl_init (cb, data);
     if (curl)
     {
        curl_easy_setopt (curl, CURLOPT_URL, src);
@@ -135,9 +138,9 @@ int opkg_download(opkg_conf_t *conf, const char *src,
        {
            long error_code;
            curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &error_code);
-           opkg_message(conf, OPKG_ERROR, "Failed to download %s. \nerror detail: %s\n", src, curl_easy_strerror(res));
+           opkg_msg(ERROR, "Failed to download %s: %s.\n",
+                   src, curl_easy_strerror(res));
            free(tmp_file_location);
-            free(src_basec);
            return res;
        }
 
@@ -145,7 +148,6 @@ int opkg_download(opkg_conf_t *conf, const char *src,
     else
     {
        free(tmp_file_location);
-        free(src_basec);
        return -1;
     }
 #else
@@ -167,9 +169,8 @@ int opkg_download(opkg_conf_t *conf, const char *src,
       res = xsystem(argv);
 
       if (res) {
-       opkg_message(conf, OPKG_ERROR, "Failed to download %s, error %d\n", src, res);
+       opkg_msg(ERROR, "Failed to download %s, wget returned %d.\n", src, res);
        free(tmp_file_location);
-        free(src_basec);
        return res;
       }
     }
@@ -178,20 +179,20 @@ int opkg_download(opkg_conf_t *conf, const char *src,
     err = file_move(tmp_file_location, dest_file_name);
 
     free(tmp_file_location);
-    free(src_basec);
 
     return err;
 }
 
-static int opkg_download_cache(opkg_conf_t *conf, const char *src,
-  const char *dest_file_name, curl_progress_func cb, void *data)
+static int
+opkg_download_cache(const char *src, const char *dest_file_name,
+       curl_progress_func cb, void *data)
 {
     char *cache_name = xstrdup(src);
     char *cache_location, *p;
     int err = 0;
 
     if (!conf->cache || str_starts_with(src, "file:")) {
-       err = opkg_download(conf, src, dest_file_name, cb, data);
+       err = opkg_download(src, dest_file_name, cb, data);
        goto out1;
     }
 
@@ -201,9 +202,9 @@ static int opkg_download_cache(opkg_conf_t *conf, const char *src,
 
     sprintf_alloc(&cache_location, "%s/%s", conf->cache, cache_name);
     if (file_exists(cache_location))
-       opkg_message(conf, OPKG_NOTICE, "Copying %s\n", cache_location);
+       opkg_msg(NOTICE, "Copying %s.\n", cache_location);
     else {
-       err = opkg_download(conf, src, cache_location, cb, data);
+       err = opkg_download(src, cache_location, cb, data);
        if (err) {
            (void) unlink(cache_location);
            goto out2;
@@ -220,19 +221,21 @@ out1:
     return err;
 }
 
-int opkg_download_pkg(opkg_conf_t *conf, pkg_t *pkg, const char *dir)
+int
+opkg_download_pkg(pkg_t *pkg, const char *dir)
 {
     int err;
     char *url;
     char *stripped_filename;
 
     if (pkg->src == NULL) {
-       opkg_message(conf,OPKG_ERROR, "ERROR: Package %s (parent %s) is not available from any configured src.\n",
-               pkg->name, pkg->parent->name);
+       opkg_msg(ERROR, "Package %s is not available from any configured src.\n",
+               pkg->name);
        return -1;
     }
     if (pkg->filename == NULL) {
-       opkg_message(conf,OPKG_ERROR, "ERROR: Package %s (parent %s) does not have a valid filename field.\n",pkg->name, pkg->parent->name);
+       opkg_msg(ERROR, "Package %s does not have a valid filename field.\n",
+               pkg->name);
        return -1;
     }
 
@@ -249,7 +252,7 @@ int opkg_download_pkg(opkg_conf_t *conf, pkg_t *pkg, const char *dir)
 
     sprintf_alloc(&pkg->local_filename, "%s/%s", dir, stripped_filename);
 
-    err = opkg_download_cache(conf, url, pkg->local_filename, NULL, NULL);
+    err = opkg_download_cache(url, pkg->local_filename, NULL, NULL);
     free(url);
 
     return err;
@@ -258,7 +261,8 @@ int opkg_download_pkg(opkg_conf_t *conf, pkg_t *pkg, const char *dir)
 /*
  * Downloads file from url, installs in package database, return package name. 
  */
-int opkg_prepare_url_for_install(opkg_conf_t *conf, const char *url, char **namep)
+int
+opkg_prepare_url_for_install(const char *url, char **namep)
 {
      int err = 0;
      pkg_t *pkg;
@@ -272,11 +276,11 @@ int opkg_prepare_url_for_install(opkg_conf_t *conf, const char *url, char **name
          char *file_base = basename(file_basec);
 
          sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base);
-         err = opkg_download(conf, url, tmp_file, NULL, NULL);
+         err = opkg_download(url, tmp_file, NULL, NULL);
          if (err)
               return err;
 
-         err = pkg_init_from_file(conf, pkg, tmp_file);
+         err = pkg_init_from_file(pkg, tmp_file);
          if (err)
               return err;
 
@@ -287,10 +291,11 @@ int opkg_prepare_url_for_install(opkg_conf_t *conf, const char *url, char **name
                 || strcmp(&url[strlen(url) - 4], IPKG_PKG_EXTENSION) == 0
                || strcmp(&url[strlen(url) - 4], DPKG_PKG_EXTENSION) == 0) {
 
-         err = pkg_init_from_file(conf, pkg, url);
+         err = pkg_init_from_file(pkg, url);
          if (err)
               return err;
-         opkg_message(conf, OPKG_DEBUG2, "Package %s provided by hand (%s).\n", pkg->name,pkg->local_filename);
+         opkg_msg(DEBUG2, "Package %s provided by hand (%s).\n",
+                 pkg->name, pkg->local_filename);
           pkg->provided_by_hand = 1;
 
      } else {
@@ -299,15 +304,10 @@ int opkg_prepare_url_for_install(opkg_conf_t *conf, const char *url, char **name
        return 0;
      }
 
-     if (!pkg->architecture) {
-         opkg_message(conf, OPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
-         return -1;
-     }
-
      pkg->dest = conf->default_dest;
      pkg->state_want = SW_INSTALL;
      pkg->state_flag |= SF_PREFER;
-     pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);  
+     hash_insert_pkg(pkg, 1);  
 
      if (namep) {
          *namep = pkg->name;
@@ -316,7 +316,7 @@ int opkg_prepare_url_for_install(opkg_conf_t *conf, const char *url, char **name
 }
 
 int
-opkg_verify_file (opkg_conf_t *conf, char *text_file, char *sig_file)
+opkg_verify_file (char *text_file, char *sig_file)
 {
 #if defined HAVE_GPGME
     if (conf->check_signature == 0 )
@@ -324,7 +324,7 @@ opkg_verify_file (opkg_conf_t *conf, char *text_file, char *sig_file)
     int status = -1;
     gpgme_ctx_t ctx;
     gpgme_data_t sig, text, key;
-    gpgme_error_t err = -1;
+    gpgme_error_t err;
     gpgme_verify_result_t result;
     gpgme_signature_t s;
     char *trusted_path = NULL;
@@ -397,31 +397,29 @@ opkg_verify_file (opkg_conf_t *conf, char *text_file, char *sig_file)
     openssl_init();
 
     // Set-up the key store
-    if(!(store = setup_verify(conf, conf->signature_ca_file, conf->signature_ca_path))){
-        opkg_message(conf, OPKG_ERROR,
-                "Can't open CA certificates\n");
+    if(!(store = setup_verify(conf->signature_ca_file, conf->signature_ca_path))){
+        opkg_msg(ERROR, "Can't open CA certificates.\n");
         goto verify_file_end;
     }
 
     // Open a BIO to read the sig file
     if (!(in = BIO_new_file(sig_file, "rb"))){
-        opkg_message(conf, OPKG_ERROR,
-                "Can't open signature file %s\n", sig_file);
+        opkg_msg(ERROR, "Can't open signature file %s.\n", sig_file);
         goto verify_file_end;
     }
 
     // Read the PKCS7 block contained in the sig file
     p7 = PEM_read_bio_PKCS7(in, NULL, NULL, NULL);
     if(!p7){
-        opkg_message(conf, OPKG_ERROR,
-                "Can't read signature file (Corrupted ?)\n");
+        opkg_msg(ERROR, "Can't read signature file %s (Corrupted ?).\n",
+               sig_file);
         goto verify_file_end;
     }
 #if defined(HAVE_PATHFINDER)
     if(conf->check_x509_path){
        if(!pkcs7_pathfinder_verify_signers(p7)){
-           opkg_message(conf,  OPKG_ERROR, "pkcs7_pathfinder_verify_signers: "
-                   "Path verification failed\n");
+           opkg_msg(ERROR, "pkcs7_pathfinder_verify_signers: "
+                   "Path verification failed.\n");
            goto verify_file_end;
        }
     }
@@ -429,16 +427,14 @@ opkg_verify_file (opkg_conf_t *conf, char *text_file, char *sig_file)
 
     // Open the Package file to authenticate
     if (!(indata = BIO_new_file(text_file, "rb"))){
-        opkg_message(conf, OPKG_ERROR,
-                "Can't open file %s\n", text_file);
+        opkg_msg(ERROR, "Can't open file %s.\n", text_file);
         goto verify_file_end;
     }
 
     // Let's verify the autenticity !
     if (PKCS7_verify(p7, NULL, store, indata, NULL, PKCS7_BINARY) != 1){
         // Get Off My Lawn!
-        opkg_message(conf, OPKG_ERROR,
-                "Verification failure\n");
+        opkg_msg(ERROR, "Verification failure.\n");
     }else{
         // Victory !
         status = 0;
@@ -477,7 +473,9 @@ static void openssl_init(void){
 
 
 #if defined HAVE_OPENSSL
-static X509_STORE *setup_verify(opkg_conf_t *conf, char *CAfile, char *CApath){
+static X509_STORE *
+setup_verify(char *CAfile, char *CApath)
+{
     X509_STORE *store = NULL;
     X509_LOOKUP *lookup = NULL;
 
@@ -496,8 +494,7 @@ static X509_STORE *setup_verify(opkg_conf_t *conf, char *CAfile, char *CApath){
     if (CAfile) {
         if(!X509_LOOKUP_load_file(lookup,CAfile,X509_FILETYPE_PEM)) {
             // Invalid CA => Bye bye
-            opkg_message(conf, OPKG_ERROR,
-                    "Error loading file %s\n", CAfile);
+            opkg_msg(ERROR, "Error loading file %s.\n", CAfile);
             goto end;
         }
     } else {
@@ -512,8 +509,7 @@ static X509_STORE *setup_verify(opkg_conf_t *conf, char *CAfile, char *CApath){
 
     if (CApath) {
         if(!X509_LOOKUP_add_dir(lookup,CApath,X509_FILETYPE_PEM)) {
-            opkg_message(conf, OPKG_ERROR,
-                    "Error loading directory %s\n", CApath);
+            opkg_msg(ERROR, "Error loading directory %s.\n", CApath);
             goto end;
         }
     } else {
@@ -541,7 +537,9 @@ void opkg_curl_cleanup(void){
     }
 }
 
-static CURL *opkg_curl_init(opkg_conf_t *conf, curl_progress_func cb, void *data){
+static CURL *
+opkg_curl_init(curl_progress_func cb, void *data)
+{
 
     if(curl == NULL){
        curl = curl_easy_init();
@@ -553,7 +551,7 @@ static CURL *opkg_curl_init(opkg_conf_t *conf, curl_progress_func cb, void *data
 
            /* use crypto engine */
            if (curl_easy_setopt(curl, CURLOPT_SSLENGINE, conf->ssl_engine) != CURLE_OK){
-               opkg_message(conf, OPKG_ERROR, "can't set crypto engine: '%s'\n",
+               opkg_msg(ERROR, "Can't set crypto engine '%s'.\n",
                        conf->ssl_engine);
 
                opkg_curl_cleanup();
@@ -561,7 +559,8 @@ static CURL *opkg_curl_init(opkg_conf_t *conf, curl_progress_func cb, void *data
            }
            /* set the crypto engine as default */
            if (curl_easy_setopt(curl, CURLOPT_SSLENGINE_DEFAULT, 1L) != CURLE_OK){
-               opkg_message(conf, OPKG_ERROR, "can't set crypto engine as default\n");
+               opkg_msg(ERROR, "Can't set crypto engine '%s' as default.\n",
+                       conf->ssl_engine);
 
                opkg_curl_cleanup();
                return NULL;
@@ -572,7 +571,7 @@ static CURL *opkg_curl_init(opkg_conf_t *conf, curl_progress_func cb, void *data
        if(conf->ssl_key_passwd){
            if (curl_easy_setopt(curl, CURLOPT_SSLKEYPASSWD, conf->ssl_key_passwd) != CURLE_OK)
            {
-               opkg_message(conf, OPKG_DEBUG, "Failed to set key password\n");
+               opkg_msg(DEBUG, "Failed to set key password.\n");
            }
        }
 
@@ -580,7 +579,7 @@ static CURL *opkg_curl_init(opkg_conf_t *conf, curl_progress_func cb, void *data
        if(conf->ssl_cert_type){
            if (curl_easy_setopt(curl, CURLOPT_SSLCERTTYPE, conf->ssl_cert_type) != CURLE_OK)
            {
-               opkg_message(conf, OPKG_DEBUG, "Failed to set certificate format\n");
+               opkg_msg(DEBUG, "Failed to set certificate format.\n");
            }
        }
        /* SSL cert name isn't mandatory */
@@ -592,13 +591,13 @@ static CURL *opkg_curl_init(opkg_conf_t *conf, curl_progress_func cb, void *data
        if(conf->ssl_key_type){
            if (curl_easy_setopt(curl, CURLOPT_SSLKEYTYPE, conf->ssl_key_type) != CURLE_OK)
            {
-               opkg_message(conf, OPKG_DEBUG, "Failed to set key format\n");
+               opkg_msg(DEBUG, "Failed to set key format.\n");
            }
        }
        if(conf->ssl_key){
            if (curl_easy_setopt(curl, CURLOPT_SSLKEY, conf->ssl_key) != CURLE_OK)
            {
-               opkg_message(conf, OPKG_DEBUG, "Failed to set key\n");
+               opkg_msg(DEBUG, "Failed to set key.\n");
            }
        }
 
@@ -612,7 +611,7 @@ static CURL *opkg_curl_init(opkg_conf_t *conf, curl_progress_func cb, void *data
 #ifdef HAVE_PATHFINDER
            if(conf->check_x509_path){
                if (curl_easy_setopt(curl, CURLOPT_SSL_CTX_FUNCTION, curl_ssl_ctx_function) != CURLE_OK){
-                   opkg_message(conf, OPKG_DEBUG, "Failed to set ssl path verification callback\n");
+                   opkg_msg(DEBUG, "Failed to set ssl path verification callback.\n");
                }else{
                    curl_easy_setopt(curl, CURLOPT_SSL_CTX_DATA, NULL);
                }
index 10347ca..d98a311 100644 (file)
@@ -24,14 +24,14 @@ typedef void (*opkg_download_progress_callback)(int percent, char *url);
 typedef int (*curl_progress_func)(void *data, double t, double d, double ultotal, double ulnow);
 
 
-int opkg_download(opkg_conf_t *conf, const char *src, const char *dest_file_name, curl_progress_func cb, void *data);
-int opkg_download_pkg(opkg_conf_t *conf, pkg_t *pkg, const char *dir);
+int opkg_download(const char *src, const char *dest_file_name, curl_progress_func cb, void *data);
+int opkg_download_pkg(pkg_t *pkg, const char *dir);
 /*
  * Downloads file from url, installs in package database, return package name. 
  */
-int opkg_prepare_url_for_install(opkg_conf_t *conf, const char *url, char **namep);
+int opkg_prepare_url_for_install(const char *url, char **namep);
 
-int opkg_verify_file (opkg_conf_t *conf, char *text_file, char *sig_file);
+int opkg_verify_file (char *text_file, char *sig_file);
 #ifdef HAVE_CURL
 void opkg_curl_cleanup(void);
 #endif
diff --git a/libopkg/opkg_error.h b/libopkg/opkg_error.h
deleted file mode 100644 (file)
index c40e635..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-/* opkg_error.h - the opkg package management system
-
-   Copyright (C) 2008 OpenMoko Inc
-
-   This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2, or (at
-   your option) any later version.
-
-   This program is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   General Public License for more details.
-*/
-
-#ifndef OPKG_ERROR_H
-#define OPKG_ERROR_H
-
-struct errlist {
-    char * errmsg;
-    struct errlist * next;
-} ;
-
-#endif /* OPKG_ERROR_H */
index a01a378..94d6188 100644 (file)
 #include "sprintf_alloc.h"
 #include "file_util.h"
 #include "xsystem.h"
-#include "user.h"
 #include "libbb/libbb.h"
 
 static int
-satisfy_dependencies_for(opkg_conf_t *conf, pkg_t *pkg)
+satisfy_dependencies_for(pkg_t *pkg)
 {
      int i, err;
      pkg_vec_t *depends = pkg_vec_alloc();
@@ -51,24 +50,22 @@ satisfy_dependencies_for(opkg_conf_t *conf, pkg_t *pkg)
      char **tmp, **unresolved = NULL;
      int ndepends;
 
-     ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf, 
-                                                       pkg, depends, 
+     ndepends = pkg_hash_fetch_unsatisfied_dependencies(pkg, depends, 
                                                        &unresolved);
 
      if (unresolved) {
-         opkg_message(conf, OPKG_ERROR,
-                      "%s: Cannot satisfy the following dependencies for %s:\n\t",
-                      conf->force_depends ? "Warning" : "ERROR", pkg->name);
+         opkg_msg(ERROR, "Cannot satisfy the following dependencies for %s:\n",
+                      pkg->name);
          tmp = unresolved;
          while (*unresolved) {
-              opkg_message(conf, OPKG_ERROR, " %s", *unresolved);
+              opkg_msg(ERROR, "\t%s", *unresolved);
               free(*unresolved);
               unresolved++;
          }
          free(tmp);
-         opkg_message(conf, OPKG_ERROR, "\n");
+         opkg_msg(ERROR, "\n");
          if (! conf->force_depends) {
-              opkg_message(conf, OPKG_INFO,
+              opkg_msg(INFO,
                            "This could mean that your package list is out of date or that the packages\n"
                            "mentioned above do not yet exist (try 'opkg update'). To proceed in spite\n"
                            "of this problem try again with the '-force-depends' option.\n");
@@ -98,8 +95,8 @@ satisfy_dependencies_for(opkg_conf_t *conf, pkg_t *pkg)
             it in, so check first. */
          if ((dep->state_status != SS_INSTALLED)
              && (dep->state_status != SS_UNPACKED)) {
-               opkg_message(conf, OPKG_DEBUG2,"Function: %s calling opkg_install_pkg \n",__FUNCTION__);
-              err = opkg_install_pkg(conf, dep,0);
+               opkg_msg(DEBUG2,"Calling opkg_install_pkg.\n");
+              err = opkg_install_pkg(dep, 0);
               /* mark this package as having been automatically installed to
                * satisfy a dependancy */
               dep->auto_installed = 1;
@@ -116,30 +113,28 @@ satisfy_dependencies_for(opkg_conf_t *conf, pkg_t *pkg)
 }
 
 static int
-check_conflicts_for(opkg_conf_t *conf, pkg_t *pkg)
+check_conflicts_for(pkg_t *pkg)
 {
      int i;
      pkg_vec_t *conflicts = NULL;
-     int level;
-     const char *prefix;
+     message_level_t level;
+
      if (conf->force_depends) {
-         level = OPKG_NOTICE;
-         prefix = "Warning";
+         level = NOTICE;
      } else {
-         level = OPKG_ERROR;
-         prefix = "ERROR";
+         level = ERROR;
      }
 
      if (!conf->force_depends)
-         conflicts = (pkg_vec_t *)pkg_hash_fetch_conflicts(&conf->pkg_hash, pkg);
+         conflicts = pkg_hash_fetch_conflicts(pkg);
 
      if (conflicts) {
-         opkg_message(conf, level,
-                      "%s: The following packages conflict with %s:\n\t", prefix, pkg->name);
+         opkg_msg(level, "The following packages conflict with %s:\n",
+                      pkg->name);
          i = 0;
          while (i < conflicts->len)
-              opkg_message(conf, level, " %s", conflicts->pkgs[i++]->name);
-         opkg_message(conf, level, "\n");
+              opkg_msg(level, "\t%s", conflicts->pkgs[i++]->name);
+         opkg_msg(level, "\n");
          pkg_vec_free(conflicts);
          return -1;
      }
@@ -147,12 +142,12 @@ check_conflicts_for(opkg_conf_t *conf, pkg_t *pkg)
 }
 
 static int
-update_file_ownership(opkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
+update_file_ownership(pkg_t *new_pkg, pkg_t *old_pkg)
 {
      str_list_t *new_list, *old_list;
      str_list_elt_t *iter, *niter;
 
-     new_list = pkg_get_installed_files(conf, new_pkg);
+     new_list = pkg_get_installed_files(new_pkg);
      if (new_list == NULL)
             return -1;
 
@@ -160,15 +155,15 @@ update_file_ownership(opkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
              iter; 
              iter = niter, niter = str_list_next(new_list, niter)) {
          char *new_file = (char *)iter->data;
-         pkg_t *owner = file_hash_get_file_owner(conf, new_file);
+         pkg_t *owner = file_hash_get_file_owner(new_file);
          if (!new_file)
-              opkg_message(conf, OPKG_ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name);
+              opkg_msg(ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name);
          if (!owner || (owner == old_pkg))
-              file_hash_set_file_owner(conf, new_file, new_pkg);
+              file_hash_set_file_owner(new_file, new_pkg);
      }
 
      if (old_pkg) {
-         old_list = pkg_get_installed_files(conf, old_pkg);
+         old_list = pkg_get_installed_files(old_pkg);
          if (old_list == NULL) {
                  pkg_free_installed_files(new_pkg);
                  return -1;
@@ -178,7 +173,7 @@ update_file_ownership(opkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
                   iter; 
                   iter = niter, niter = str_list_next(old_list, niter)) {
               char *old_file = (char *)iter->data;
-              pkg_t *owner = file_hash_get_file_owner(conf, old_file);
+              pkg_t *owner = file_hash_get_file_owner(old_file);
               if (owner == old_pkg) {
                    /* obsolete */
                    hash_table_insert(&conf->obs_file_hash, old_file, old_pkg);
@@ -191,41 +186,32 @@ update_file_ownership(opkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
 }
 
 static int
-verify_pkg_installable(opkg_conf_t *conf, pkg_t *pkg)
+verify_pkg_installable(pkg_t *pkg)
 {
-    /* XXX: FEATURE: Anything else needed here? Maybe a check on free space? */
-
-    /* sma 6.20.02:  yup; here's the first bit */
-    /* 
-     * XXX: BUG easy for cworth
-     * 1) please point the call below to the correct current root destination
-     * 2) we need to resolve how to check the required space for a pending pkg, 
-     *    my diddling with the .opk file size below isn't going to cut it.
-     * 3) return a proper error code instead of 1
-     */
-     int comp_size, blocks_available;
-     char *root_dir;
-    
-     if (!conf->force_space && pkg->installed_size != NULL) {
-          root_dir = pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir;
-         blocks_available = get_available_blocks(root_dir);
-
-         comp_size = strtoul(pkg->installed_size, NULL, 0);
-         /* round up a blocks count without doing fancy-but-slow casting jazz */ 
-         comp_size = (int)((comp_size + 1023) / 1024);
-
-         if (comp_size >= blocks_available) {
-              opkg_message(conf, OPKG_ERROR,
-                           "Only have %d available blocks on filesystem %s, pkg %s needs %d\n", 
-                           blocks_available, root_dir, pkg->name, comp_size);
-              return ENOSPC;
-         }
-     }
+       unsigned long kbs_available, pkg_size_kbs;
+       char *root_dir;
+
+       if (conf->force_space || pkg->installed_size == 0)
+               return 0;
+
+       root_dir = pkg->dest ? pkg->dest->root_dir :
+                                               conf->default_dest->root_dir;
+       kbs_available = get_available_kbytes(root_dir);
+
+       pkg_size_kbs = (pkg->installed_size + 1023)/1024;
+
+       if (pkg_size_kbs >= kbs_available) {
+               opkg_msg(ERROR, "Only have %dkb available on filesystem %s, "
+                       "pkg %s needs %d\n",
+                       kbs_available, root_dir, pkg->name, pkg_size_kbs);
+               return -1;
+       }
+
      return 0;
 }
 
 static int
-unpack_pkg_control_files(opkg_conf_t *conf, pkg_t *pkg)
+unpack_pkg_control_files(pkg_t *pkg)
 {
      int err;
      char *conffiles_file_name;
@@ -236,9 +222,8 @@ unpack_pkg_control_files(opkg_conf_t *conf, pkg_t *pkg)
 
      pkg->tmp_unpack_dir = mkdtemp(pkg->tmp_unpack_dir);
      if (pkg->tmp_unpack_dir == NULL) {
-         opkg_message(conf, OPKG_ERROR,
-                      "%s: Failed to create temporary directory '%s': %s\n",
-                      __FUNCTION__, pkg->tmp_unpack_dir, strerror(errno));
+         opkg_perror(ERROR, "Failed to create temporary directory '%s'",
+                      pkg->tmp_unpack_dir);
          return -1;
      }
 
@@ -265,8 +250,7 @@ unpack_pkg_control_files(opkg_conf_t *conf, pkg_t *pkg)
     
      conffiles_file = fopen(conffiles_file_name, "r");
      if (conffiles_file == NULL) {
-         fprintf(stderr, "%s: failed to open %s: %s\n",
-                 __FUNCTION__, conffiles_file_name, strerror(errno));
+         opkg_perror(ERROR, "Failed to open %s", conffiles_file_name);
          free(conffiles_file_name);
          return -1;
      }
@@ -311,7 +295,7 @@ unpack_pkg_control_files(opkg_conf_t *conf, pkg_t *pkg)
  * which are no longer a dependency in the new (upgraded) pkg.
  */
 static int
-pkg_remove_orphan_dependent(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) 
+pkg_remove_orphan_dependent(pkg_t *pkg, pkg_t *old_pkg) 
 {
        int i, j, k, l, found;
        int n_deps;
@@ -357,7 +341,7 @@ pkg_remove_orphan_dependent(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
                        /*
                         * old_pkg has a dependency that pkg does not.
                         */
-                       p = pkg_hash_fetch_installed_by_name (&conf->pkg_hash,
+                       p = pkg_hash_fetch_installed_by_name(
                                        cd0->possibilities[j]->pkg->name);
 
                        if (!p)
@@ -366,13 +350,11 @@ pkg_remove_orphan_dependent(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
                        if (!p->auto_installed)
                                continue;
 
-                       n_deps = pkg_has_installed_dependents(conf, NULL, p,
-                                       &dependents);
+                       n_deps = pkg_has_installed_dependents(p, &dependents);
                        n_deps--; /* don't count old_pkg */
 
                        if (n_deps == 0) {
-                               opkg_message (conf, OPKG_NOTICE,
-                                               "%s was autoinstalled and is "
+                               opkg_msg(NOTICE, "%s was autoinstalled and is "
                                                "now orphaned, removing.\n",
                                                p->name);
 
@@ -380,10 +362,9 @@ pkg_remove_orphan_dependent(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
                                 * which we need to ignore during removal. */
                                p->state_flag |= SF_REPLACE;
 
-                               opkg_remove_pkg(conf, p, 0);
+                               opkg_remove_pkg(p, 0);
                        } else 
-                               opkg_message(conf, OPKG_INFO,
-                                               "%s was autoinstalled and is "
+                               opkg_msg(INFO, "%s was autoinstalled and is "
                                                "still required by %d "
                                                "installed packages.\n",
                                                p->name, n_deps);
@@ -396,7 +377,7 @@ pkg_remove_orphan_dependent(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
 
 /* returns number of installed replacees */
 static int
-pkg_get_installed_replacees(opkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *installed_replacees)
+pkg_get_installed_replacees(pkg_t *pkg, pkg_vec_t *installed_replacees)
 {
      abstract_pkg_t **replaces = pkg->replaces;
      int replaces_count = pkg->replaces_count;
@@ -419,7 +400,7 @@ pkg_get_installed_replacees(opkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *installed_
 }
 
 static int
-pkg_remove_installed_replacees(opkg_conf_t *conf, pkg_vec_t *replacees)
+pkg_remove_installed_replacees(pkg_vec_t *replacees)
 {
      int i;
      int replaces_count = replacees->len;
@@ -427,7 +408,7 @@ pkg_remove_installed_replacees(opkg_conf_t *conf, pkg_vec_t *replacees)
          pkg_t *replacee = replacees->pkgs[i];
          int err;
          replacee->state_flag |= SF_REPLACE; /* flag it so remove won't complain */
-         err = opkg_remove_pkg(conf, replacee,0);
+         err = opkg_remove_pkg(replacee, 0);
          if (err)
               return err;
      }
@@ -436,15 +417,15 @@ pkg_remove_installed_replacees(opkg_conf_t *conf, pkg_vec_t *replacees)
 
 /* to unwind the removal: make sure they are installed */
 static int
-pkg_remove_installed_replacees_unwind(opkg_conf_t *conf, pkg_vec_t *replacees)
+pkg_remove_installed_replacees_unwind(pkg_vec_t *replacees)
 {
      int i, err;
      int replaces_count = replacees->len;
      for (i = 0; i < replaces_count; i++) {
          pkg_t *replacee = replacees->pkgs[i];
          if (replacee->state_status != SS_INSTALLED) {
-               opkg_message(conf, OPKG_DEBUG2,"Function: %s calling opkg_install_pkg \n",__FUNCTION__);
-              err = opkg_install_pkg(conf, replacee,0);
+               opkg_msg(DEBUG2, "Calling opkg_install_pkg.\n");
+              err = opkg_install_pkg(replacee, 0);
               if (err)
                    return err;
          }
@@ -454,7 +435,7 @@ pkg_remove_installed_replacees_unwind(opkg_conf_t *conf, pkg_vec_t *replacees)
 
 /* compares versions of pkg and old_pkg, returns 0 if OK to proceed with installation of pkg, 1 otherwise */
 static int
-opkg_install_check_downgrade(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg, int message)
+opkg_install_check_downgrade(pkg_t *pkg, pkg_t *old_pkg, int message)
 {        
      if (old_pkg) {
           char message_out[15];
@@ -472,26 +453,24 @@ opkg_install_check_downgrade(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg, int
           } 
 
          if (cmp > 0) {
-              opkg_message(conf, OPKG_NOTICE,
+              opkg_msg(NOTICE,
                            "Not downgrading package %s on %s from %s to %s.\n",
                            old_pkg->name, old_pkg->dest->name, old_version, new_version);
               rc = 1;
          } else if (cmp < 0) {
-              opkg_message(conf, OPKG_NOTICE,
-                           "%s%s on %s from %s to %s...\n",
+              opkg_msg(NOTICE, "%s%s on %s from %s to %s...\n",
                            message_out, pkg->name, old_pkg->dest->name, old_version, new_version);
               pkg->dest = old_pkg->dest;
               rc = 0;
          } else /* cmp == 0 */ {
               if (conf->force_reinstall) {
-                   opkg_message(conf, OPKG_NOTICE,
-                                "Reinstalling %s (%s) on %s...\n",
+                   opkg_msg(NOTICE, "Reinstalling %s (%s) on %s...\n",
                                 pkg->name, new_version, old_pkg->dest->name);
                    pkg->dest = old_pkg->dest;
                    rc = 0;
               } else {
-                   opkg_message(conf, OPKG_NOTICE,
-                                "Not installing %s (%s) on %s -- already installed.\n",
+                   opkg_msg(NOTICE, "%s (%s) already install on %s."
+                                  " Not reinstalling.\n",
                                 pkg->name, new_version, old_pkg->dest->name);
                    rc = 1;
               }
@@ -508,8 +487,7 @@ opkg_install_check_downgrade(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg, int
           strncpy( message_out,"Installing ",strlen("Installing ") );
          char *version = pkg_version_str_alloc(pkg);
       
-         opkg_message(conf, OPKG_NOTICE,
-                      "%s%s (%s) to %s...\n", message_out,
+         opkg_msg(NOTICE, "%s%s (%s) to %s...\n", message_out,
                       pkg->name, version, pkg->dest->name);
          free(version);
          return 0;
@@ -518,7 +496,7 @@ opkg_install_check_downgrade(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg, int
 
 
 static int
-prerm_upgrade_old_pkg(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
+prerm_upgrade_old_pkg(pkg_t *pkg, pkg_t *old_pkg)
 {
      /* DPKG_INCOMPATIBILITY:
        dpkg does some things here that we don't do yet. Do we care?
@@ -534,7 +512,7 @@ prerm_upgrade_old_pkg(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
 }
 
 static int
-prerm_upgrade_old_pkg_unwind(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
+prerm_upgrade_old_pkg_unwind(pkg_t *pkg, pkg_t *old_pkg)
 {
      /* DPKG_INCOMPATIBILITY:
        dpkg does some things here that we don't do yet. Do we care?
@@ -544,7 +522,7 @@ prerm_upgrade_old_pkg_unwind(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
 }
 
 static int
-prerm_deconfigure_conflictors(opkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
+prerm_deconfigure_conflictors(pkg_t *pkg, pkg_vec_t *conflictors)
 {
      /* DPKG_INCOMPATIBILITY:
        dpkg does some things here that we don't do yet. Do we care?
@@ -571,7 +549,7 @@ prerm_deconfigure_conflictors(opkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflict
 }
 
 static int
-prerm_deconfigure_conflictors_unwind(opkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
+prerm_deconfigure_conflictors_unwind(pkg_t *pkg, pkg_vec_t *conflictors)
 {
      /* DPKG_INCOMPATIBILITY: dpkg does some things here that we don't
        do yet. Do we care?  (See prerm_deconfigure_conflictors for
@@ -580,7 +558,7 @@ prerm_deconfigure_conflictors_unwind(opkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *c
 }
 
 static int
-preinst_configure(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
+preinst_configure(pkg_t *pkg, pkg_t *old_pkg)
 {
      int err;
      char *preinst_args;
@@ -597,11 +575,10 @@ preinst_configure(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
          preinst_args = xstrdup("install");
      }
 
-     err = pkg_run_script(conf, pkg, "preinst", preinst_args);
+     err = pkg_run_script(pkg, "preinst", preinst_args);
      if (err) {
-         opkg_message(conf, OPKG_ERROR,
-                      "Aborting installation of %s\n", pkg->name);
-         return 1;
+         opkg_msg(ERROR, "Aborting installation of %s.\n", pkg->name);
+         return -1;
      }
 
      free(preinst_args);
@@ -610,7 +587,7 @@ preinst_configure(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
 }
 
 static int
-preinst_configure_unwind(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
+preinst_configure_unwind(pkg_t *pkg, pkg_t *old_pkg)
 {
      /* DPKG_INCOMPATIBILITY:
        dpkg does the following error unwind, should we?
@@ -633,7 +610,7 @@ backup_filename_alloc(const char *file_name)
 
 
 static int
-backup_make_backup(opkg_conf_t *conf, const char *file_name)
+backup_make_backup(const char *file_name)
 {
      int err;
      char *backup;
@@ -641,9 +618,8 @@ backup_make_backup(opkg_conf_t *conf, const char *file_name)
      backup = backup_filename_alloc(file_name);
      err = file_copy(file_name, backup);
      if (err) {
-         opkg_message(conf, OPKG_ERROR,
-                      "%s: Failed to copy %s to %s\n",
-                      __FUNCTION__, file_name, backup);
+         opkg_msg(ERROR, "Failed to copy %s to %s\n",
+                      file_name, backup);
      }
 
      free(backup);
@@ -679,7 +655,7 @@ backup_remove(const char *file_name)
 }
 
 static int
-backup_modified_conffiles(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
+backup_modified_conffiles(pkg_t *pkg, pkg_t *old_pkg)
 {
      int err;
      conffile_list_elt_t *iter;
@@ -693,11 +669,11 @@ backup_modified_conffiles(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
               char *cf_name;
               
               cf = iter->data;
-              cf_name = root_filename_alloc(conf, cf->name);
+              cf_name = root_filename_alloc(cf->name);
 
               /* Don't worry if the conffile is just plain gone */
-              if (file_exists(cf_name) && conffile_has_been_modified(conf, cf)) {
-                   err = backup_make_backup(conf, cf_name);
+              if (file_exists(cf_name) && conffile_has_been_modified(cf)) {
+                   err = backup_make_backup(cf_name);
                    if (err) {
                         return err;
                    }
@@ -710,14 +686,14 @@ backup_modified_conffiles(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
      for (iter = nv_pair_list_first(&pkg->conffiles); iter; iter = nv_pair_list_next(&pkg->conffiles, iter)) {
          char *cf_name;
          cf = (conffile_t *)iter->data;
-         cf_name = root_filename_alloc(conf, cf->name);
+         cf_name = root_filename_alloc(cf->name);
          /* Ignore if this was a conffile in old_pkg as well */
          if (pkg_get_conffile(old_pkg, cf->name)) {
               continue;
          }
 
          if (file_exists(cf_name) && (! backup_exists_for(cf_name))) {
-              err = backup_make_backup(conf, cf_name);
+              err = backup_make_backup(cf_name);
               if (err) {
                    return err;
               }
@@ -729,7 +705,7 @@ backup_modified_conffiles(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
 }
 
 static int
-backup_modified_conffiles_unwind(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
+backup_modified_conffiles_unwind(pkg_t *pkg, pkg_t *old_pkg)
 {
      conffile_list_elt_t *iter;
 
@@ -748,7 +724,7 @@ backup_modified_conffiles_unwind(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
 
 
 static int
-check_data_file_clashes(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
+check_data_file_clashes(pkg_t *pkg, pkg_t *old_pkg)
 {
      /* DPKG_INCOMPATIBILITY:
        opkg takes a slightly different approach than dpkg at this
@@ -768,7 +744,7 @@ check_data_file_clashes(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
 
      int clashes = 0;
 
-     files_list = pkg_get_installed_files(conf, pkg);
+     files_list = pkg_get_installed_files(pkg);
      if (files_list == NULL)
             return -1;
 
@@ -777,12 +753,11 @@ check_data_file_clashes(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
              iter = niter, niter = str_list_next(files_list, iter)) {
          char *root_filename;
          char *filename = (char *) iter->data;
-         root_filename = root_filename_alloc(conf, filename);
+         root_filename = root_filename_alloc(filename);
          if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
               pkg_t *owner;
               pkg_t *obs;
-              /* Pre-existing conffiles are OK */
-              /* @@@@ should have way to check that it is a conffile -Jamey */
+
               if (backup_exists_for(root_filename)) {
                    continue;
               }
@@ -790,11 +765,11 @@ check_data_file_clashes(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
               /* Pre-existing files are OK if force-overwrite was asserted. */ 
               if (conf->force_overwrite) {
                    /* but we need to change who owns this file */
-                   file_hash_set_file_owner(conf, filename, pkg);
+                   file_hash_set_file_owner(filename, pkg);
                    continue;
               }
 
-              owner = file_hash_get_file_owner(conf, filename);
+              owner = file_hash_get_file_owner(filename);
 
               /* Pre-existing files are OK if owned by the pkg being upgraded. */
               if (owner && old_pkg) {
@@ -805,14 +780,17 @@ check_data_file_clashes(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
 
               /* Pre-existing files are OK if owned by a package replaced by new pkg. */
               if (owner) {
-                    opkg_message(conf, OPKG_DEBUG2, "Checking for replaces for %s in package %s\n", filename, owner->name);
+                    opkg_msg(DEBUG2, "Checking replaces for %s in package %s\n",
+                               filename, owner->name);
                    if (pkg_replaces(pkg, owner)) {
                         continue;
                    }
 /* If the file that would be installed is owned by the same package, ( as per a reinstall or similar )
    then it's ok to overwrite. */
                     if (strcmp(owner->name,pkg->name)==0){
-                        opkg_message(conf, OPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
+                        opkg_msg(INFO, "Replacing pre-existing file %s"
+                                       " owned by package %s\n",
+                                       filename, owner->name);
                         continue;
                     }
               }
@@ -820,21 +798,21 @@ check_data_file_clashes(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
               /* Pre-existing files are OK if they are obsolete */
               obs = hash_table_get(&conf->obs_file_hash, filename);
               if (obs) {
-                   opkg_message(conf, OPKG_INFO, "Pre-exiting file %s is obsolete.  obs_pkg=%s\n", filename, obs->name);
+                   opkg_msg(INFO, "Pre-exiting file %s is obsolete."
+                                  " obs_pkg=%s\n",
+                                   filename, obs->name);
                    continue;
               }
 
               /* We have found a clash. */
-              opkg_message(conf, OPKG_ERROR,
-                           "Package %s wants to install file %s\n"
+              opkg_msg(ERROR, "Package %s wants to install file %s\n"
                            "\tBut that file is already provided by package ",
                            pkg->name, filename);
               if (owner) {
-                   opkg_message(conf, OPKG_ERROR,
-                                "%s\n", owner->name);
+                   opkg_msg(ERROR, "%s\n", owner->name);
               } else {
-                   opkg_message(conf, OPKG_ERROR,
-                                "<no package>\nPlease move this file out of the way and try again.\n");
+                   opkg_msg(ERROR, "<no package>\n"
+                       "Please move this file out of the way and try again.\n");
               }
               clashes++;
          }
@@ -849,7 +827,7 @@ check_data_file_clashes(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  * XXX: This function sucks, as does the below comment.
  */
 static int
-check_data_file_clashes_change(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
+check_data_file_clashes_change(pkg_t *pkg, pkg_t *old_pkg)
 {
     /* Basically that's the worst hack I could do to be able to change ownership of
        file list, but, being that we have no way to unwind the mods, due to structure
@@ -864,7 +842,7 @@ check_data_file_clashes_change(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
 
      char *root_filename = NULL;
 
-     files_list = pkg_get_installed_files(conf, pkg);
+     files_list = pkg_get_installed_files(pkg);
      if (files_list == NULL)
             return -1;
 
@@ -876,15 +854,15 @@ check_data_file_clashes_change(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
               free(root_filename);
               root_filename = NULL;
           }
-         root_filename = root_filename_alloc(conf, filename);
+         root_filename = root_filename_alloc(filename);
          if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
               pkg_t *owner;
 
-              owner = file_hash_get_file_owner(conf, filename);
+              owner = file_hash_get_file_owner(filename);
 
               if (conf->force_overwrite) {
                    /* but we need to change who owns this file */
-                   file_hash_set_file_owner(conf, filename, pkg);
+                   file_hash_set_file_owner(filename, pkg);
                    continue;
               }
 
@@ -894,8 +872,10 @@ check_data_file_clashes_change(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
                    if (pkg_replaces(pkg, owner)) {
 /* It's now time to change the owner of that file. 
    It has been "replaced" from the new "Replaces", then I need to inform lists file about that.  */
-                        opkg_message(conf, OPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
-                        file_hash_set_file_owner(conf, filename, pkg);
+                        opkg_msg(INFO, "Replacing pre-existing file %s "
+                                        "owned by package %s\n",
+                                        filename, owner->name);
+                        file_hash_set_file_owner(filename, pkg);
                         continue;
                    }
               }
@@ -912,14 +892,14 @@ check_data_file_clashes_change(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
 }
 
 static int
-check_data_file_clashes_unwind(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
+check_data_file_clashes_unwind(pkg_t *pkg, pkg_t *old_pkg)
 {
      /* Nothing to do since check_data_file_clashes doesn't change state */
      return 0;
 }
 
 static int
-postrm_upgrade_old_pkg(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
+postrm_upgrade_old_pkg(pkg_t *pkg, pkg_t *old_pkg)
 {
      /* DPKG_INCOMPATIBILITY: dpkg does the following here, should we?
        1. If the package is being upgraded, call
@@ -932,7 +912,7 @@ postrm_upgrade_old_pkg(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
 }
 
 static int
-postrm_upgrade_old_pkg_unwind(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
+postrm_upgrade_old_pkg_unwind(pkg_t *pkg, pkg_t *old_pkg)
 {
      /* DPKG_INCOMPATIBILITY:
        dpkg does some things here that we don't do yet. Do we care?
@@ -942,7 +922,7 @@ postrm_upgrade_old_pkg_unwind(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
 }
 
 static int
-remove_obsolesced_files(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
+remove_obsolesced_files(pkg_t *pkg, pkg_t *old_pkg)
 {
      int err;
      str_list_t *old_files;
@@ -951,11 +931,11 @@ remove_obsolesced_files(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
      str_list_elt_t *nf;
      hash_table_t new_files_table;
 
-     old_files = pkg_get_installed_files(conf, old_pkg);
+     old_files = pkg_get_installed_files(old_pkg);
      if (old_files == NULL)
          return -1;
 
-     new_files = pkg_get_installed_files(conf, pkg);
+     new_files = pkg_get_installed_files(pkg);
      if (new_files == NULL) {
           pkg_free_installed_files(old_pkg);
          return -1;
@@ -979,20 +959,18 @@ remove_obsolesced_files(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
          if (file_is_dir(old)) {
               continue;
          }
-         owner = file_hash_get_file_owner(conf, old);
+         owner = file_hash_get_file_owner(old);
          if (owner != old_pkg) {
               /* in case obsolete file no longer belongs to old_pkg */
               continue;
          }
  
          /* old file is obsolete */
-         opkg_message(conf, OPKG_INFO,
-                      "    removing obsolete file %s\n", old);
+         opkg_msg(INFO, "Removing obsolete file %s.\n", old);
          if (!conf->noaction) {
               err = unlink(old);
               if (err) {
-                   opkg_message(conf, OPKG_ERROR, "    Warning: remove %s failed: %s\n", old,
-                                strerror(errno));
+                   opkg_perror(ERROR, "unlinking %s failed", old);
               }
          }
      }
@@ -1005,7 +983,7 @@ remove_obsolesced_files(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
 }
 
 static int
-install_maintainer_scripts(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
+install_maintainer_scripts(pkg_t *pkg, pkg_t *old_pkg)
 {
      int ret;
      char *prefix;
@@ -1019,7 +997,7 @@ install_maintainer_scripts(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
 }
 
 static int
-remove_disappeared(opkg_conf_t *conf, pkg_t *pkg)
+remove_disappeared(pkg_t *pkg)
 {
      /* DPKG_INCOMPATIBILITY:
        This is a fairly sophisticated dpkg operation. Shall we
@@ -1040,7 +1018,7 @@ remove_disappeared(opkg_conf_t *conf, pkg_t *pkg)
 }
 
 static int
-install_data_files(opkg_conf_t *conf, pkg_t *pkg)
+install_data_files(pkg_t *pkg)
 {
      int err;
 
@@ -1049,29 +1027,21 @@ install_data_files(opkg_conf_t *conf, pkg_t *pkg)
        actually do the data file installation now. See comments in
        check_data_file_clashes() for more details. */
     
-     opkg_message(conf, OPKG_INFO,
-                 "    extracting data files to %s\n", pkg->dest->root_dir);
+     opkg_msg(INFO, "Extracting data files to %s.\n", pkg->dest->root_dir);
      err = pkg_extract_data_files_to_dir(pkg, pkg->dest->root_dir);
      if (err) {
          return err;
      }
 
-     /* XXX: BUG or FEATURE : We are actually loosing the Essential flag,
-        so we can't save ourself from removing important packages
-        At this point we (should) have extracted the .control file, so it
-        would be a good idea to reload the data in it, and set the Essential 
-        state in *pkg. From now on the Essential is back in status file and
-        we can protect again.
-        We should operate this way:
-        fopen the file ( pkg->dest->root_dir/pkg->name.control )
-        check for "Essential" in it 
-        set the value in pkg->essential.
-        This new routine could be useful also for every other flag
-        Pigi: 16/03/2004 */
-     set_flags_from_control(conf, pkg) ;
+     /* The "Essential" control field may only be present in the control
+      * file and not in the Packages list. Ensure we capture it regardless.
+      *
+      * XXX: This should be fixed outside of opkg, in the Package list.
+      */
+     set_flags_from_control(pkg) ;
      
-     opkg_message(conf, OPKG_DEBUG, "    Calling pkg_write_filelist from %s\n", __FUNCTION__);
-     err = pkg_write_filelist(conf, pkg);
+     opkg_msg(DEBUG, "Calling pkg_write_filelist.\n");
+     err = pkg_write_filelist(pkg);
      if (err)
          return err;
 
@@ -1090,55 +1060,7 @@ install_data_files(opkg_conf_t *conf, pkg_t *pkg)
 }
 
 static int
-user_prefers_old_conffile(const char *file_name, const char *backup)
-{
-     char *response;
-     const char *short_file_name;
-
-     short_file_name = strrchr(file_name, '/');
-     if (short_file_name) {
-         short_file_name++;
-     } else {
-         short_file_name = file_name;
-     }
-
-     while (1) {
-         response = get_user_response("    Configuration file '%s'\n"
-                                      "    ==> File on system created by you or by a script.\n"
-                                      "    ==> File also in package provided by package maintainer.\n"
-                                      "       What would you like to do about it ?  Your options are:\n"
-                                      "        Y or I  : install the package maintainer's version\n"
-                                      "        N or O  : keep your currently-installed version\n"
-                                      "          D     : show the differences between the versions (if diff is installed)\n"
-                                      "     The default action is to keep your current version.\n"
-                                      "    *** %s (Y/I/N/O/D) [default=N] ? ", file_name, short_file_name);
-
-         if (response == NULL)
-                 return 1;
-
-         if (strcmp(response, "y") == 0
-             || strcmp(response, "i") == 0
-             || strcmp(response, "yes") == 0) {
-              free(response);
-              return 0;
-         }
-
-         if (strcmp(response, "d") == 0) {
-              const char *argv[] = {"diff", "-u", backup, file_name, NULL};
-              xsystem(argv);
-              printf("    [Press ENTER to continue]\n");
-              response = file_read_line_alloc(stdin);
-              free(response);
-              continue;
-         }
-
-         free(response);
-         return 1;
-     }
-}
-
-static int
-resolve_conffiles(opkg_conf_t *conf, pkg_t *pkg)
+resolve_conffiles(pkg_t *pkg)
 {
      conffile_list_elt_t *iter;
      conffile_t *cf;
@@ -1150,7 +1072,7 @@ resolve_conffiles(opkg_conf_t *conf, pkg_t *pkg)
      for (iter = nv_pair_list_first(&pkg->conffiles); iter; iter = nv_pair_list_next(&pkg->conffiles, iter)) {
          char *root_filename;
          cf = (conffile_t *)iter->data;
-         root_filename = root_filename_alloc(conf, cf->name);
+         root_filename = root_filename_alloc(cf->name);
 
          /* Might need to initialize the md5sum for each conffile */
          if (cf->value == NULL) {
@@ -1164,17 +1086,24 @@ resolve_conffiles(opkg_conf_t *conf, pkg_t *pkg)
 
          cf_backup = backup_filename_alloc(root_filename);
 
-
           if (file_exists(cf_backup)) {
               /* Let's compute md5 to test if files are changed */
               md5sum = file_md5sum_alloc(cf_backup);
               if (md5sum && cf->value && strcmp(cf->value,md5sum) != 0 ) {
                   if (conf->force_maintainer) {
-                      opkg_message(conf, OPKG_NOTICE, "Conffile %s using maintainer's setting.\n", cf_backup);
-                  } else if (conf->force_defaults
-                          || user_prefers_old_conffile(root_filename, cf_backup) ) {
+                      opkg_msg(NOTICE, "Conffile %s using maintainer's setting.\n",
+                                     cf_backup);
+                  } else {
+                      char *new_conffile;
+                      sprintf_alloc(&new_conffile, "%s-opkg", root_filename);
+                      opkg_msg(NOTICE, "Existing conffile %s "
+                           "is different from the conffile in the new package."
+                           " The new conffile will be placed at %s.\n",
+                           root_filename, new_conffile);
+                      rename(root_filename, new_conffile);
                       rename(cf_backup, root_filename);
-                  }
+                      free(new_conffile);
+                 }
               }
               unlink(cf_backup);
              if (md5sum)
@@ -1190,24 +1119,25 @@ resolve_conffiles(opkg_conf_t *conf, pkg_t *pkg)
 
 
 int
-opkg_install_by_name(opkg_conf_t *conf, const char *pkg_name)
+opkg_install_by_name(const char *pkg_name)
 {
      int cmp;
      pkg_t *old, *new;
      char *old_version, *new_version;
 
-     old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
+     old = pkg_hash_fetch_installed_by_name(pkg_name);
      if (old)
-        opkg_message(conf, OPKG_DEBUG2, "Old versions from pkg_hash_fetch %s \n",  old->version);
+        opkg_msg(DEBUG2, "Old versions from pkg_hash_fetch %s.\n",
+                       old->version);
     
-     new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
+     new = pkg_hash_fetch_best_installation_candidate_by_name(pkg_name);
      if (new == NULL)
        return -1;
 
-     opkg_message(conf, OPKG_DEBUG2, "Versions from pkg_hash_fetch in %s ", __FUNCTION__);
+     opkg_msg(DEBUG2, "Versions from pkg_hash_fetch:");
      if ( old ) 
-        opkg_message(conf, OPKG_DEBUG2, " old %s ", old->version);
-     opkg_message(conf, OPKG_DEBUG2, " new %s\n", new->version);
+        opkg_msg(DEBUG2, " old %s ", old->version);
+     opkg_msg(DEBUG2, " new %s\n", new->version);
 
      new->state_flag |= SF_USER;
      if (old) {
@@ -1216,26 +1146,25 @@ opkg_install_by_name(opkg_conf_t *conf, const char *pkg_name)
 
          cmp = pkg_compare_versions(old, new);
           if ( (conf->force_downgrade==1) && (cmp > 0) ){     /* We've been asked to allow downgrade  and version is precedent */
-            opkg_message(conf, OPKG_DEBUG, " Forcing downgrade \n");
+            opkg_msg(DEBUG, "Forcing downgrade\n");
              cmp = -1 ;                                       /* then we force opkg to downgrade */ 
                                                               /* We need to use a value < 0 because in the 0 case we are asking to */
                                                               /* reinstall, and some check could fail asking the "force-reinstall" option */
           } 
-         opkg_message(conf, OPKG_DEBUG, 
-                      "Comparing visible versions of pkg %s:"
+         opkg_msg(DEBUG, "Comparing visible versions of pkg %s:"
                       "\n\t%s is installed "
                       "\n\t%s is available "
                       "\n\t%d was comparison result\n",
                       pkg_name, old_version, new_version, cmp);
          if (cmp == 0 && !conf->force_reinstall) {
-              opkg_message(conf, OPKG_NOTICE,
+              opkg_msg(NOTICE,
                            "Package %s (%s) installed in %s is up to date.\n",
                            old->name, old_version, old->dest->name);
               free(old_version);
               free(new_version);
               return 0;
          } else if (cmp > 0) {
-              opkg_message(conf, OPKG_NOTICE,
+              opkg_msg(NOTICE,
                            "Not downgrading package %s on %s from %s to %s.\n",
                            old->name, old->dest->name, old_version, new_version);
               free(old_version);
@@ -1249,15 +1178,15 @@ opkg_install_by_name(opkg_conf_t *conf, const char *pkg_name)
          free(new_version);
      }
 
-     opkg_message(conf, OPKG_DEBUG2,"%s: calling opkg_install_pkg \n",__FUNCTION__);
-     return opkg_install_pkg(conf, new,0);
+     opkg_msg(DEBUG2,"Calling opkg_install_pkg.\n");
+     return opkg_install_pkg(new, 0);
 }
 
 /**
  *  @brief Really install a pkg_t 
  */
 int
-opkg_install_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
+opkg_install_pkg(pkg_t *pkg, int from_upgrade)
 {
      int err = 0;
      int message = 0;
@@ -1274,26 +1203,19 @@ opkg_install_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
      if ( from_upgrade ) 
         message = 1;            /* Coming from an upgrade, and should change the output message */
 
-     if (!pkg) {
-         opkg_message(conf, OPKG_ERROR,
-                      "INTERNAL ERROR: null pkg passed to opkg_install_pkg\n");
-         return -1;
-     }
-
-     opkg_message(conf, OPKG_DEBUG2, "Function: %s calling pkg_arch_supported %s \n", __FUNCTION__, __FUNCTION__);
+     opkg_msg(DEBUG2, "Calling pkg_arch_supported.\n");
 
-     if (!pkg_arch_supported(conf, pkg)) {
-         opkg_message(conf, OPKG_ERROR, "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n",
+     if (!pkg_arch_supported(pkg)) {
+         opkg_msg(ERROR, "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n",
                       pkg->architecture, pkg->name);
          return -1;
      }
      if (pkg->state_status == SS_INSTALLED && conf->force_reinstall == 0 && conf->nodeps == 0) {
-         err = satisfy_dependencies_for(conf, pkg);
+         err = satisfy_dependencies_for(pkg);
          if (err)
                  return -1;
 
-         opkg_message(conf, OPKG_NOTICE,
-                      "Package %s is already installed in %s.\n", 
+         opkg_msg(NOTICE, "Package %s is already installed on %s.\n", 
                       pkg->name, pkg->dest->name);
          return 0;
      }
@@ -1302,9 +1224,9 @@ opkg_install_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
          pkg->dest = conf->default_dest;
      }
 
-     old_pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
+     old_pkg = pkg_hash_fetch_installed_by_name(pkg->name);
 
-     err = opkg_install_check_downgrade(conf, pkg, old_pkg, message);
+     err = opkg_install_check_downgrade(pkg, old_pkg, message);
      if (err)
             return -1;
 
@@ -1313,7 +1235,7 @@ opkg_install_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
          old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependences */
      }
 
-     err = check_conflicts_for(conf, pkg);
+     err = check_conflicts_for(pkg);
      if (err)
             return -1;
     
@@ -1324,15 +1246,15 @@ opkg_install_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
      if (pkg->state_status == SS_INSTALLED && conf->force_reinstall == 0)
             return 0;
     
-     err = verify_pkg_installable(conf, pkg);
+     err = verify_pkg_installable(pkg);
      if (err)
             return -1;
 
      if (pkg->local_filename == NULL) {
-         err = opkg_download_pkg(conf, pkg, conf->tmp_dir);
+         err = opkg_download_pkg(pkg, conf->tmp_dir);
          if (err) {
-              opkg_message(conf, OPKG_ERROR,
-                           "Failed to download %s. Perhaps you need to run 'opkg update'?\n",
+              opkg_msg(ERROR, "Failed to download %s. "
+                              "Perhaps you need to run 'opkg update'?\n",
                            pkg->name);
               return -1;
          }
@@ -1354,14 +1276,15 @@ opkg_install_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
 
        if (file_exists (sig_file_name))
        {
-         if (opkg_verify_file (conf, list_file_name, sig_file_name)){
-           opkg_message(conf, OPKG_ERROR, "Failed to verify the signature of: %s\n",
+         if (opkg_verify_file (list_file_name, sig_file_name)){
+           opkg_msg(ERROR, "Failed to verify the signature of %s.\n",
                            list_file_name);
            return -1;
          }
        }else{
-         opkg_message(conf, OPKG_ERROR, "Signature file is missing. "
-                         "Perhaps you need to run 'opkg update'?\n");
+         opkg_msg(ERROR, "Signature file is missing for %s. "
+                         "Perhaps you need to run 'opkg update'?\n",
+                        pkg->name);
          return -1;
        }
 
@@ -1377,9 +1300,10 @@ opkg_install_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
          file_md5 = file_md5sum_alloc(pkg->local_filename);
          if (file_md5 && strcmp(file_md5, pkg->md5sum))
          {
-              opkg_message(conf, OPKG_ERROR,
-                           "Package %s md5sum mismatch. Either the opkg or the package index are corrupt. Try 'opkg update'.\n",
-                           pkg->name);
+              opkg_msg(ERROR, "Package %s md5sum mismatch. "
+                       "Either the opkg or the package index are corrupt. "
+                       "Try 'opkg update'.\n",
+                       pkg->name);
               free(file_md5);
               return -1;
          }
@@ -1394,9 +1318,10 @@ opkg_install_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
          file_sha256 = file_sha256sum_alloc(pkg->local_filename);
          if (file_sha256 && strcmp(file_sha256, pkg->sha256sum))
          {
-              opkg_message(conf, OPKG_ERROR,
-                           "Package %s sha256sum mismatch. Either the opkg or the package index are corrupt. Try 'opkg update'.\n",
-                           pkg->name);
+              opkg_msg(ERROR, "Package %s sha256sum mismatch. "
+                       "Either the opkg or the package index are corrupt. "
+                       "Try 'opkg update'.\n",
+                       pkg->name);
               free(file_sha256);
               return -1;
          }
@@ -1406,22 +1331,19 @@ opkg_install_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
 #endif
 
      if (pkg->tmp_unpack_dir == NULL) {
-         if (unpack_pkg_control_files(conf, pkg) == -1) {
-              opkg_message(conf, OPKG_ERROR, "Failed to unpack control"
-                             " files from %s.\n", pkg->local_filename);
+         if (unpack_pkg_control_files(pkg) == -1) {
+              opkg_msg(ERROR, "Failed to unpack control files from %s.\n",
+                              pkg->local_filename);
               return -1;
          }
      }
 
-     /* We should update the filelist here, so that upgrades of packages that split will not fail. -Jamey 27-MAR-03 */
-/* Pigi: check if it will pass from here when replacing. It seems to fail */
-/* That's rather strange that files don't change owner. Investigate !!!!!!*/
-     err = update_file_ownership(conf, pkg, old_pkg);
+     err = update_file_ownership(pkg, old_pkg);
      if (err)
             return -1;
 
      if (conf->nodeps == 0) {
-         err = satisfy_dependencies_for(conf, pkg);
+         err = satisfy_dependencies_for(pkg);
          if (err)
                return -1;
           if (pkg->state_status == SS_UNPACKED)
@@ -1430,7 +1352,7 @@ opkg_install_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
      }
 
      replacees = pkg_vec_alloc();
-     pkg_get_installed_replacees(conf, pkg, replacees);
+     pkg_get_installed_replacees(pkg, replacees);
 
      /* this next section we do with SIGINT blocked to prevent inconsistency between opkg database and filesystem */
 
@@ -1442,36 +1364,36 @@ opkg_install_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
          pkg->state_flag |= SF_FILELIST_CHANGED;
 
          if (old_pkg)
-               pkg_remove_orphan_dependent(conf, pkg, old_pkg);
+               pkg_remove_orphan_dependent(pkg, old_pkg);
 
          /* XXX: BUG: we really should treat replacement more like an upgrade
           *      Instead, we're going to remove the replacees 
           */
-         err = pkg_remove_installed_replacees(conf, replacees);
+         err = pkg_remove_installed_replacees(replacees);
          if (err)
                  goto UNWIND_REMOVE_INSTALLED_REPLACEES;
 
-         err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
+         err = prerm_upgrade_old_pkg(pkg, old_pkg);
          if (err)
                  goto UNWIND_PRERM_UPGRADE_OLD_PKG;
 
-         err = prerm_deconfigure_conflictors(conf, pkg, replacees);
+         err = prerm_deconfigure_conflictors(pkg, replacees);
          if (err)
                  goto UNWIND_PRERM_DECONFIGURE_CONFLICTORS;
 
-         err = preinst_configure(conf, pkg, old_pkg);
+         err = preinst_configure(pkg, old_pkg);
          if (err)
                  goto UNWIND_PREINST_CONFIGURE;
 
-         err = backup_modified_conffiles(conf, pkg, old_pkg);
+         err = backup_modified_conffiles(pkg, old_pkg);
          if (err)
                  goto UNWIND_BACKUP_MODIFIED_CONFFILES;
 
-         err = check_data_file_clashes(conf, pkg, old_pkg);
+         err = check_data_file_clashes(pkg, old_pkg);
          if (err)
                  goto UNWIND_CHECK_DATA_FILE_CLASHES;
 
-         err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
+         err = postrm_upgrade_old_pkg(pkg, old_pkg);
          if (err)
                  goto UNWIND_POSTRM_UPGRADE_OLD_PKG;
 
@@ -1483,62 +1405,60 @@ opkg_install_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
               old_pkg->state_want = SW_DEINSTALL;
 
               if (old_pkg->state_flag & SF_NOPRUNE) {
-                   opkg_message(conf, OPKG_INFO,
-                                "  not removing obsolesced files because package marked noprune\n");
+                   opkg_msg(INFO, "Not removing obsolesced files because "
+                                   "package %s marked noprune.\n",
+                                   old_pkg->name);
               } else {
-                   opkg_message(conf, OPKG_INFO,
-                                "  removing obsolesced files\n");
-                   if (remove_obsolesced_files(conf, pkg, old_pkg)) {
-                       opkg_message(conf, OPKG_ERROR, "Failed to determine "
+                   opkg_msg(INFO, "Removing obsolesced files for %s\n",
+                                   old_pkg->name);
+                   if (remove_obsolesced_files(pkg, old_pkg)) {
+                       opkg_msg(ERROR, "Failed to determine "
                                        "obsolete files from previously "
                                        "installed %s\n", old_pkg->name);
                    }
               }
 
                /* removing files from old package, to avoid ghost files */ 
-               remove_data_files_and_list(conf, old_pkg);
-               remove_maintainer_scripts(conf, old_pkg);
+               remove_data_files_and_list(old_pkg);
+               remove_maintainer_scripts(old_pkg);
          }
 
 
-         opkg_message(conf, OPKG_INFO,
-                      "  installing maintainer scripts\n");
-         if (install_maintainer_scripts(conf, pkg, old_pkg)) {
-               opkg_message(conf, OPKG_ERROR, "Failed to extract maintainer"
-                              " scripts for %s. Package debris may remain!\n",
+         opkg_msg(INFO, "Installing maintainer scripts.\n");
+         if (install_maintainer_scripts(pkg, old_pkg)) {
+               opkg_msg(ERROR, "Failed to extract maintainer scripts for %s."
+                              " Package debris may remain!\n",
                               pkg->name);
                goto pkg_is_hosed;
          }
 
          /* the following just returns 0 */
-         remove_disappeared(conf, pkg);
+         remove_disappeared(pkg);
 
-         opkg_message(conf, OPKG_INFO,
-                      "  installing data files\n");
+         opkg_msg(INFO, "Installing data files for %s.\n", pkg->name);
 
-         if (install_data_files(conf, pkg)) {
-               opkg_message(conf, OPKG_ERROR, "Failed to extract data files "
-                              "for %s. Package debris may remain!\n",
+         if (install_data_files(pkg)) {
+               opkg_msg(ERROR, "Failed to extract data files for %s. "
+                               "Package debris may remain!\n",
                               pkg->name);
                goto pkg_is_hosed;
          }
 
-         err = check_data_file_clashes_change(conf, pkg, old_pkg);
+         err = check_data_file_clashes_change(pkg, old_pkg);
          if (err) {
-               opkg_message(conf, OPKG_ERROR,
-                               "check_data_file_clashes_change() failed for "
+               opkg_msg(ERROR, "check_data_file_clashes_change() failed for "
                               "for files belonging to %s.\n",
                               pkg->name);
          }
 
-         opkg_message(conf, OPKG_INFO,
-                      "  resolving conf files\n");
-         resolve_conffiles(conf, pkg);
+         opkg_msg(INFO, "Resolving conf files for %s\n", pkg->name);
+         resolve_conffiles(pkg);
 
          pkg->state_status = SS_UNPACKED;
          old_state_flag = pkg->state_flag;
          pkg->state_flag &= ~SF_PREFER;
-         opkg_message(conf, OPKG_DEBUG, "   pkg=%s old_state_flag=%x state_flag=%x\n", pkg->name, old_state_flag, pkg->state_flag);
+         opkg_msg(DEBUG, "pkg=%s old_state_flag=%x state_flag=%x\n",
+                         pkg->name, old_state_flag, pkg->state_flag);
 
          if (old_pkg && !conf->force_reinstall) {
               old_pkg->state_status = SS_NOT_INSTALLED;
@@ -1550,32 +1470,27 @@ opkg_install_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
          if (ab_pkg)
               ab_pkg->state_status = pkg->state_status;
 
-         opkg_message(conf, OPKG_INFO, "Done.\n");
-
          sigprocmask(SIG_UNBLOCK, &newset, &oldset);
           pkg_vec_free (replacees);
          return 0;
      
 
      UNWIND_POSTRM_UPGRADE_OLD_PKG:
-         postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
+         postrm_upgrade_old_pkg_unwind(pkg, old_pkg);
      UNWIND_CHECK_DATA_FILE_CLASHES:
-         check_data_file_clashes_unwind(conf, pkg, old_pkg);
+         check_data_file_clashes_unwind(pkg, old_pkg);
      UNWIND_BACKUP_MODIFIED_CONFFILES:
-         backup_modified_conffiles_unwind(conf, pkg, old_pkg);
+         backup_modified_conffiles_unwind(pkg, old_pkg);
      UNWIND_PREINST_CONFIGURE:
-         preinst_configure_unwind(conf, pkg, old_pkg);
+         preinst_configure_unwind(pkg, old_pkg);
      UNWIND_PRERM_DECONFIGURE_CONFLICTORS:
-         prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
+         prerm_deconfigure_conflictors_unwind(pkg, replacees);
      UNWIND_PRERM_UPGRADE_OLD_PKG:
-         prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
+         prerm_upgrade_old_pkg_unwind(pkg, old_pkg);
      UNWIND_REMOVE_INSTALLED_REPLACEES:
-         pkg_remove_installed_replacees_unwind(conf, replacees);
+         pkg_remove_installed_replacees_unwind(replacees);
 
 pkg_is_hosed:
-         opkg_message(conf, OPKG_INFO,
-                      "Failed.\n");
-
          sigprocmask(SIG_UNBLOCK, &newset, &oldset);
 
           pkg_vec_free (replacees);
index 13d43d0..eaffff8 100644 (file)
@@ -20,9 +20,8 @@
 
 #include "pkg.h"
 #include "opkg_conf.h"
-#include "opkg_error.h"
 
-int opkg_install_by_name(opkg_conf_t *conf, const char *pkg_name);
-int opkg_install_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrading);
+int opkg_install_by_name(const char *pkg_name);
+int opkg_install_pkg(pkg_t *pkg, int from_upgrading);
 
 #endif
index 33a9c90..a21a1a2 100644 (file)
@@ -1,5 +1,6 @@
 /* opkg_message.c - the opkg package management system
 
+   Copyright (C) 2009 Ubiq Technologies <graham.gower@gmail.com>
    Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
 
    This program is free software; you can redistribute it and/or
 #include "includes.h"
 #include "opkg_conf.h"
 #include "opkg_message.h"
-#include "opkg_error.h"
-#include "opkg_utils.h"
+#include "libbb/libbb.h"
+
+struct errlist {
+       char *errmsg;
+       struct errlist *next;
+};
+
+static struct errlist *error_list_head, *error_list_tail;
+
+static void
+push_error_list(char *msg)
+{
+       struct errlist *e;
+
+       e = xcalloc(1,  sizeof(struct errlist));
+       e->errmsg = xstrdup(msg);
+       e->next = NULL;
+
+       if (error_list_head) {
+               error_list_tail->next = e;
+               error_list_tail = e;
+       } else {
+               error_list_head = error_list_tail = e;
+       }
+}
+
+void
+free_error_list(void)
+{
+       struct errlist *err, *err_tmp;
+
+       err = error_list_head;
+       while (err != NULL) {
+               free(err->errmsg);
+               err_tmp = err;
+               err = err->next;
+               free(err_tmp);
+       }
+}
+
+void
+print_error_list(void)
+{
+       struct errlist *err = error_list_head;
+
+       if (err) {
+               printf("Collected errors:\n");
+               /* Here we print the errors collected and free the list */
+               while (err != NULL) {
+                       printf(" * %s", err->errmsg);
+                       err = err->next;
+               }
+       }
+}
 
 void
-opkg_message (opkg_conf_t * conf, message_level_t level, char *fmt, ...)
+opkg_message (message_level_t level, const char *fmt, ...)
 {
        va_list ap;
 
@@ -30,7 +83,7 @@ opkg_message (opkg_conf_t * conf, message_level_t level, char *fmt, ...)
 
        va_start (ap, fmt);
 
-       if (level == OPKG_ERROR) {
+       if (level == ERROR) {
                char msg[256];
                vsnprintf(msg, 256, fmt, ap);
                push_error_list(msg);
index 2ca58d8..62a6b83 100644 (file)
@@ -1,5 +1,6 @@
 /* opkg_message.h - the opkg package management system
 
+   Copyright (C) 2009 Ubiq Technologies <graham.gower@gmail.com>
    Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
 
    This program is free software; you can redistribute it and/or
 #ifndef _OPKG_MESSAGE_H_
 #define _OPKG_MESSAGE_H_
 
-#include "opkg_conf.h"
+#include <string.h>
+#include <errno.h>
 
 typedef enum {
-     OPKG_ERROR,       /* error conditions */
-     OPKG_NOTICE,      /* normal but significant condition */
-     OPKG_INFO,                /* informational message */
-     OPKG_DEBUG,       /* debug level message */
-     OPKG_DEBUG2,      /* more debug level message */
+       ERROR,  /* error conditions */
+       NOTICE, /* normal but significant condition */
+       INFO,   /* informational message */
+       DEBUG,  /* debug level message */
+       DEBUG2, /* more debug level message */
 } message_level_t;
 
-extern void opkg_message(opkg_conf_t *conf, message_level_t level, char *fmt, ...);
+void free_error_list(void);
+void print_error_list(void);
+void opkg_message(message_level_t level, const char *fmt, ...);
+
+#define opkg_msg(l, fmt, args...) \
+       do { \
+               if (l == NOTICE) \
+                       opkg_message(l, fmt, ##args); \
+               else \
+                       opkg_message(l, "%s: "fmt, __FUNCTION__, ##args); \
+       } while (0)
+
+#define opkg_perror(l, fmt, args...) \
+       opkg_msg(l, fmt": %s.\n", ##args, strerror(errno))
 
 #endif /* _OPKG_MESSAGE_H_ */
index a53dd8e..71c8c11 100644 (file)
@@ -56,7 +56,7 @@ static int pathfinder_verify_callback(X509_STORE_CTX *ctx, void *arg)
     int validated = pathfinder_dbus_verify(certdata_str, policy, 0, 0, &errmsg);
 
     if (!validated)
-        fprintf(stderr, "curlcb_pathfinder: Path verification failed: %s\n", errmsg);
+        opkg_msg(ERROR, "Path verification failed: %s.\n", errmsg);
 
     free(certdata_str);
     free(errmsg);
index a2ef09c..b5045ea 100644 (file)
@@ -21,7 +21,6 @@
 #include <glob.h>
 
 #include "opkg_remove.h"
-#include "opkg_error.h"
 #include "opkg_cmd.h"
 
 #include "file_util.h"
  * Every package implicitly provides itself.
  */
 int
-pkg_has_installed_dependents(opkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents)
+pkg_has_installed_dependents(pkg_t *pkg, abstract_pkg_t *** pdependents)
 {
      int nprovides = pkg->provides_count;
      abstract_pkg_t **provides = pkg->provides;
-     int n_installed_dependents = 0;
+     unsigned int n_installed_dependents = 0;
      int i;
      for (i = 0; i < nprovides; i++) {
          abstract_pkg_t *providee = provides[i];
@@ -82,7 +81,7 @@ pkg_has_installed_dependents(opkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg
 }
 
 static int
-opkg_remove_dependent_pkgs (opkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
+opkg_remove_dependent_pkgs(pkg_t *pkg, abstract_pkg_t **dependents)
 {
     int i;
     int a;
@@ -91,8 +90,8 @@ opkg_remove_dependent_pkgs (opkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **depe
     abstract_pkg_t * ab_pkg;
 
     if((ab_pkg = pkg->parent) == NULL){
-       fprintf(stderr, "%s: unable to get dependent pkgs. pkg %s isn't in hash table\n",
-               __FUNCTION__, pkg->name);
+       opkg_msg(ERROR, "Internal error: pkg %s isn't in hash table\n",
+               pkg->name);
        return 0;
     }
     
@@ -138,7 +137,7 @@ opkg_remove_dependent_pkgs (opkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **depe
     
     int err=0;
     for (i = 0; i < dependent_pkgs->len; i++) {
-        err = opkg_remove_pkg(conf, dependent_pkgs->pkgs[i],0);
+        err = opkg_remove_pkg(dependent_pkgs->pkgs[i],0);
         if (err) {
             pkg_vec_free(dependent_pkgs);
             break;
@@ -149,19 +148,19 @@ opkg_remove_dependent_pkgs (opkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **depe
 }
 
 static void
-print_dependents_warning(opkg_conf_t *conf, abstract_pkg_t *abpkg, pkg_t *pkg, abstract_pkg_t **dependents)
+print_dependents_warning(pkg_t *pkg, abstract_pkg_t **dependents)
 {
     abstract_pkg_t *dep_ab_pkg;
-    opkg_message(conf, OPKG_ERROR, "Package %s is depended upon by packages:\n", pkg->name);
+    opkg_msg(ERROR, "Package %s is depended upon by packages:\n", pkg->name);
     while ((dep_ab_pkg = *dependents++) != NULL) {
         if (dep_ab_pkg->state_status == SS_INSTALLED)
-             opkg_message(conf, OPKG_ERROR, "\t%s\n", dep_ab_pkg->name);
+             opkg_msg(ERROR, "\t%s\n", dep_ab_pkg->name);
     }
-    opkg_message(conf, OPKG_ERROR, "These might cease to work if package %s is removed.\n\n", pkg->name);
-    opkg_message(conf, OPKG_ERROR, "");
-    opkg_message(conf, OPKG_ERROR, "You can force removal of this package with --force-depends.\n");
-    opkg_message(conf, OPKG_ERROR, "You can force removal of this package and its dependents\n");
-    opkg_message(conf, OPKG_ERROR, "with --force-removal-of-dependent-packages\n");
+    opkg_msg(ERROR, "These might cease to work if package %s is removed.\n\n",
+                   pkg->name);
+    opkg_msg(ERROR, "Force removal of this package with --force-depends.\n");
+    opkg_msg(ERROR, "Force removal of this package and its dependents\n");
+    opkg_msg(ERROR, "with --force-removal-of-dependent-packages.\n");
 }
 
 /*
@@ -169,7 +168,7 @@ print_dependents_warning(opkg_conf_t *conf, abstract_pkg_t *abpkg, pkg_t *pkg, a
  * by the removal of pkg.
  */
 static int
-remove_autoinstalled(opkg_conf_t *conf, pkg_t *pkg)
+remove_autoinstalled(pkg_t *pkg)
 {
        int i, j;
        int n_deps;
@@ -187,7 +186,7 @@ remove_autoinstalled(opkg_conf_t *conf, pkg_t *pkg)
                if (cdep->type != DEPEND)
                        continue;
                for (j=0; j<cdep->possibility_count; j++) {
-                       p = pkg_hash_fetch_installed_by_name (&conf->pkg_hash,
+                       p = pkg_hash_fetch_installed_by_name(
                                        cdep->possibilities[j]->pkg->name);
 
                        /* If the package is not installed, this could have
@@ -200,17 +199,14 @@ remove_autoinstalled(opkg_conf_t *conf, pkg_t *pkg)
                        if (!p->auto_installed)
                                continue;
 
-                       n_deps = pkg_has_installed_dependents(conf, NULL, p,
-                                       &dependents);
+                       n_deps = pkg_has_installed_dependents(p, &dependents);
                        if (n_deps == 0) {
-                                opkg_message(conf, OPKG_NOTICE,
-                                              "%s was autoinstalled and is "
-                                              "now orphaned, removing\n",
+                                opkg_msg(NOTICE, "%s was autoinstalled and is "
+                                              "now orphaned, removing.\n",
                                               p->name);
-                                opkg_remove_pkg(conf, p, 0);
+                                opkg_remove_pkg(p, 0);
                        } else
-                               opkg_message(conf, OPKG_INFO,
-                                               "%s was autoinstalled and is "
+                               opkg_msg(INFO, "%s was autoinstalled and is "
                                                "still required by %d "
                                                "installed packages.\n",
                                                p->name, n_deps);
@@ -224,7 +220,7 @@ remove_autoinstalled(opkg_conf_t *conf, pkg_t *pkg)
 }
 
 int
-opkg_remove_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
+opkg_remove_pkg(pkg_t *pkg, int from_upgrade)
 {
      int err;
      abstract_pkg_t *parent_pkg = NULL;
@@ -235,11 +231,12 @@ opkg_remove_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
  */
      if (pkg->essential && !from_upgrade) {
          if (conf->force_removal_of_essential_packages) {
-              fprintf(stderr, "WARNING: Removing essential package %s under your coercion.\n"
+              opkg_msg(NOTICE,
+                      "Removing essential package %s under your coercion.\n"
                       "\tIf your system breaks, you get to keep both pieces\n",
                       pkg->name);
          } else {
-              fprintf(stderr, "ERROR: Refusing to remove essential package %s.\n"
+              opkg_msg(NOTICE, "Refusing to remove essential package %s.\n"
                       "\tRemoving an essential package may lead to an unusable system, but if\n"
                       "\tyou enjoy that kind of pain, you can force opkg to proceed against\n"
                       "\tits will with the option: --force-removal-of-essential-packages\n",
@@ -259,7 +256,7 @@ opkg_remove_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
         && !(pkg->state_flag & SF_REPLACE)) {
          abstract_pkg_t **dependents;
          int has_installed_dependents = 
-              pkg_has_installed_dependents(conf, parent_pkg, pkg, &dependents);
+              pkg_has_installed_dependents(pkg, &dependents);
 
          if (has_installed_dependents) {
               /*
@@ -268,13 +265,13 @@ opkg_remove_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
                */
 
               if (!conf->force_removal_of_dependent_packages) {
-                   print_dependents_warning(conf, parent_pkg, pkg, dependents);
+                   print_dependents_warning(pkg, dependents);
                    free(dependents);
                    return -1;
               }
 
               /* remove packages depending on this package - Karthik */
-              err = opkg_remove_dependent_pkgs (conf, pkg, dependents);
+              err = opkg_remove_dependent_pkgs(pkg, dependents);
               if (err) {
                 free(dependents);
                  return err;
@@ -285,26 +282,26 @@ opkg_remove_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
      }
 
      if (from_upgrade == 0) {
-         opkg_message (conf, OPKG_NOTICE,
-                      "Removing package %s from %s...\n", pkg->name, pkg->dest->name);
+         opkg_msg(NOTICE, "Removing package %s from %s...\n",
+                        pkg->name, pkg->dest->name);
      }
      pkg->state_flag |= SF_FILELIST_CHANGED;
 
      pkg->state_want = SW_DEINSTALL;
      opkg_state_changed++;
 
-     pkg_run_script(conf, pkg, "prerm", "remove");
+     pkg_run_script(pkg, "prerm", "remove");
 
      /* DPKG_INCOMPATIBILITY: dpkg is slightly different here. It
        maintains an empty filelist rather than deleting it. That seems
        like a big pain, and I don't see that that should make a big
        difference, but for anyone who wants tighter compatibility,
        feel free to fix this. */
-     remove_data_files_and_list(conf, pkg);
+     remove_data_files_and_list(pkg);
 
-     pkg_run_script(conf, pkg, "postrm", "remove");
+     pkg_run_script(pkg, "postrm", "remove");
 
-     remove_maintainer_scripts(conf, pkg);
+     remove_maintainer_scripts(pkg);
      pkg->state_status = SS_NOT_INSTALLED;
 
      if (parent_pkg) 
@@ -312,13 +309,13 @@ opkg_remove_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
 
      /* remove autoinstalled packages that are orphaned by the removal of this one */
      if (conf->autoremove)
-       remove_autoinstalled (conf, pkg);
+       remove_autoinstalled(pkg);
 
      return 0;
 }
 
 void
-remove_data_files_and_list(opkg_conf_t *conf, pkg_t *pkg)
+remove_data_files_and_list(pkg_t *pkg)
 {
      str_list_t installed_dirs;
      str_list_t *installed_files;
@@ -329,9 +326,9 @@ remove_data_files_and_list(opkg_conf_t *conf, pkg_t *pkg)
      pkg_t *owner;
      int rootdirlen = 0;
 
-     installed_files = pkg_get_installed_files(conf, pkg);
+     installed_files = pkg_get_installed_files(pkg);
      if (installed_files == NULL) {
-            opkg_message(conf, OPKG_ERROR, "Failed to determine installed "
+            opkg_msg(ERROR, "Failed to determine installed "
                     "files for %s. None removed.\n", pkg->name);
             return;
      }
@@ -352,16 +349,20 @@ remove_data_files_and_list(opkg_conf_t *conf, pkg_t *pkg)
 
          conffile = pkg_get_conffile(pkg, file_name+rootdirlen);
          if (conffile) {
-              if (conffile_has_been_modified(conf, conffile)) {
-                   opkg_message (conf, OPKG_NOTICE,
-                                 "  not deleting modified conffile %s\n", file_name);
+              if (conffile_has_been_modified(conffile)) {
+                   opkg_msg(NOTICE, "Not deleting modified conffile %s.\n",
+                                   file_name);
                    continue;
               }
          }
 
-         opkg_message(conf, OPKG_INFO, "  deleting %s (noaction=%d)\n", file_name, conf->noaction);
-         if (!conf->noaction)
+         if (!conf->noaction) {
+               opkg_msg(INFO, "Deleting %s.\n", file_name, conf->noaction);
               unlink(file_name);
+         } else
+               opkg_msg(INFO, "Not deleting %s. (noaction)\n",
+                               file_name);
+
      }
 
      /* Remove empty directories */
@@ -372,7 +373,7 @@ remove_data_files_and_list(opkg_conf_t *conf, pkg_t *pkg)
                    file_name = (char *)iter->data;
            
                    if (rmdir(file_name) == 0) {
-                        opkg_message(conf, OPKG_INFO, "  deleting %s\n", file_name);
+                        opkg_msg(INFO, "Deleting %s.\n", file_name);
                         removed_a_dir = 1;
                         str_list_remove(&installed_dirs, &iter);
                    }
@@ -381,13 +382,13 @@ remove_data_files_and_list(opkg_conf_t *conf, pkg_t *pkg)
      }
 
      pkg_free_installed_files(pkg);
-     pkg_remove_installed_files_list(conf, pkg);
+     pkg_remove_installed_files_list(pkg);
 
      /* Don't print warning for dirs that are provided by other packages */
      for (iter = str_list_first(&installed_dirs); iter; iter = str_list_next(&installed_dirs, iter)) {
          file_name = (char *)iter->data;
 
-         owner = file_hash_get_file_owner(conf, file_name);
+         owner = file_hash_get_file_owner(file_name);
          if (owner) {
               free(iter->data);
               iter->data = NULL;
@@ -405,7 +406,7 @@ remove_data_files_and_list(opkg_conf_t *conf, pkg_t *pkg)
 }
 
 void
-remove_maintainer_scripts(opkg_conf_t *conf, pkg_t *pkg)
+remove_maintainer_scripts(pkg_t *pkg)
 {
        int i, err;
        char *globpattern;
@@ -423,8 +424,7 @@ remove_maintainer_scripts(opkg_conf_t *conf, pkg_t *pkg)
                return;
 
        for (i = 0; i < globbuf.gl_pathc; i++) {
-               opkg_message(conf, OPKG_INFO, "deleting %s\n",
-                               globbuf.gl_pathv[i]);
+               opkg_msg(INFO, "Deleting %s.\n", globbuf.gl_pathv[i]);
                unlink(globbuf.gl_pathv[i]);
        }
        globfree(&globbuf);
index 650d8bf..f0c45d2 100644 (file)
 #include "pkg.h"
 #include "opkg_conf.h"
 
-int opkg_remove_pkg(opkg_conf_t *conf, pkg_t *pkg,int message);
-int pkg_has_installed_dependents(opkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents);
-void remove_data_files_and_list(opkg_conf_t *conf, pkg_t *pkg);
-void remove_maintainer_scripts(opkg_conf_t *conf, pkg_t *pkg);
+int opkg_remove_pkg(pkg_t *pkg,int message);
+int pkg_has_installed_dependents(pkg_t *pkg, abstract_pkg_t *** pdependents);
+void remove_data_files_and_list(pkg_t *pkg);
+void remove_maintainer_scripts(pkg_t *pkg);
 
 
 #endif
index f0ae875..0d4833a 100644 (file)
 
 #include "includes.h"
 #include "opkg_install.h"
+#include "opkg_upgrade.h"
 #include "opkg_message.h"
 
 int
-opkg_upgrade_pkg(opkg_conf_t *conf, pkg_t *old)
+opkg_upgrade_pkg(pkg_t *old)
 {
      pkg_t *new;
      int cmp;
      char *old_version, *new_version;
 
      if (old->state_flag & SF_HOLD) {
-          opkg_message(conf, OPKG_NOTICE,
-                       "Not upgrading package %s which is marked "
-                       "hold (flags=%#x)\n", old->name, old->state_flag);
+          opkg_msg(NOTICE, "Not upgrading package %s which is marked "
+                       "hold (flags=%#x).\n", old->name, old->state_flag);
           return 0;
      }
 
-     new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name);
+     new = pkg_hash_fetch_best_installation_candidate_by_name(old->name);
      if (new == NULL) {
           old_version = pkg_version_str_alloc(old);
-          opkg_message(conf, OPKG_NOTICE,
-                       "Assuming locally installed package %s (%s) "
+          opkg_msg(NOTICE, "Assuming locally installed package %s (%s) "
                        "is up to date.\n", old->name, old_version);
           free(old_version);
           return 0;
@@ -48,22 +47,19 @@ opkg_upgrade_pkg(opkg_conf_t *conf, pkg_t *old)
      new_version = pkg_version_str_alloc(new);
                
      cmp = pkg_compare_versions(old, new);
-     opkg_message(conf, OPKG_DEBUG,
-                  "comparing visible versions of pkg %s:"
+     opkg_msg(DEBUG, "Comparing visible versions of pkg %s:"
                   "\n\t%s is installed "
                   "\n\t%s is available "
                   "\n\t%d was comparison result\n",
                   old->name, old_version, new_version, cmp);
      if (cmp == 0) {
-          opkg_message(conf, OPKG_INFO,
-                       "Package %s (%s) installed in %s is up to date.\n",
+          opkg_msg(INFO, "Package %s (%s) installed in %s is up to date.\n",
                        old->name, old_version, old->dest->name);
           free(old_version);
           free(new_version);
           return 0;
      } else if (cmp > 0) {
-          opkg_message(conf, OPKG_NOTICE,
-                       "Not downgrading package %s on %s from %s to %s.\n",
+          opkg_msg(NOTICE, "Not downgrading package %s on %s from %s to %s.\n",
                        old->name, old->dest->name, old_version, new_version);
           free(old_version);
           free(new_version);
@@ -76,7 +72,7 @@ opkg_upgrade_pkg(opkg_conf_t *conf, pkg_t *old)
     free(old_version);
     free(new_version);
     new->state_flag |= SF_USER;
-    return opkg_install_pkg(conf, new,1);
+    return opkg_install_pkg(new,1);
 }
 
 
@@ -101,14 +97,14 @@ pkg_hash_check_installed_pkg_helper(const char *pkg_name, void *entry,
 }
 
 struct active_list *
-prepare_upgrade_list(opkg_conf_t *conf)
+prepare_upgrade_list(void)
 {
     struct active_list *head = active_list_head_new();
     struct active_list *all = active_list_head_new();
     struct active_list *node=NULL;
 
     /* ensure all data is valid */
-    pkg_info_preinstall_check (conf);
+    pkg_info_preinstall_check();
 
     hash_table_foreach(&conf->pkg_hash, pkg_hash_check_installed_pkg_helper, all);
     for (node=active_list_next(all,all); node; node = active_list_next(all, node)) {
@@ -116,7 +112,7 @@ prepare_upgrade_list(opkg_conf_t *conf)
         int cmp;
 
         old = list_entry(node, pkg_t, list);
-        new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name);
+        new = pkg_hash_fetch_best_installation_candidate_by_name(old->name);
 
         if (new == NULL)
             continue;
index ac4952d..6545fa8 100644 (file)
@@ -16,7 +16,7 @@
 #define OPKG_UPGRADE_H
 
 #include "active_list.h"
-int opkg_upgrade_pkg(opkg_conf_t *conf, pkg_t *old);
-struct active_list * prepare_upgrade_list (opkg_conf_t *conf);
+int opkg_upgrade_pkg(pkg_t *old);
+struct active_list * prepare_upgrade_list (void);
 
 #endif
index 2bb7c2e..d39690e 100644 (file)
@@ -18,7 +18,7 @@
 #include "includes.h"
 #include <errno.h>
 #include <ctype.h>
-#include <sys/vfs.h>
+#include <sys/statvfs.h>
 
 #include "opkg_utils.h"
 #include "pkg.h"
 
 void print_pkg_status(pkg_t * pkg, FILE * file);
 
-long unsigned int get_available_blocks(char * filesystem)
+unsigned long
+get_available_kbytes(char * filesystem)
 {
-    struct statfs sfs;
+    struct statvfs f;
 
-    if(statfs(filesystem, &sfs)){
-        fprintf(stderr, "bad statfs\n");
+    if (statvfs(filesystem, &f) == -1) {
+        opkg_perror(ERROR, "Failed to statvfs for %s", filesystem);
         return 0;
     }
-    /*    fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
 
-    // Actually ((sfs.f_bavail * sfs.f_bsize) / 1024) 
+    // Actually ((sfs.f_bavail * sfs.f_frsize) / 1024) 
     // and here we try to avoid overflow. 
-    if (sfs.f_bsize >= 1024) 
-        return (sfs.f_bavail * (sfs.f_bsize / 1024));
-    else if (sfs.f_bsize > 0)
-        return sfs.f_bavail / (1024 / sfs.f_bsize);
-    fprintf(stderr, "bad statfs f_bsize == 0\n");
+    if (f.f_frsize >= 1024) 
+        return (f.f_bavail * (f.f_frsize / 1024));
+    else if (f.f_frsize > 0)
+        return f.f_bavail / (1024 / f.f_frsize);
+
+    opkg_msg(ERROR, "Unknown block size for target filesystem.\n");
+
     return 0;
 }
 
@@ -81,52 +83,3 @@ int line_is_blank(const char *line)
      }
      return 1;
 }
-
-static struct errlist *error_list_head, *error_list_tail;
-
-/*
- * XXX: this function should not allocate memory as it may be called to
- *      print an error because we are out of memory.
- */
-void push_error_list(char * msg)
-{
-       struct errlist *e;
-
-       e = xcalloc(1,  sizeof(struct errlist));
-       e->errmsg = xstrdup(msg);
-       e->next = NULL;
-
-       if (error_list_head) {
-               error_list_tail->next = e;
-               error_list_tail = e;
-       } else {
-               error_list_head = error_list_tail = e;
-       }
-}
-
-void free_error_list(void)
-{
-       struct errlist *err, *err_tmp;
-
-       err = error_list_head;
-       while (err != NULL) {
-               free(err->errmsg);
-               err_tmp = err;
-               err = err->next;
-               free(err_tmp);
-       }
-}
-
-void print_error_list (void)
-{
-       struct errlist *err = error_list_head;
-
-       if (err) {
-               printf ("Collected errors:\n");
-               /* Here we print the errors collected and free the list */
-               while (err != NULL) {
-                       printf (" * %s", err->errmsg);
-                       err = err->next;
-               }
-       }
-}
index 7cb0693..ecdd3f5 100644 (file)
 #ifndef OPKG_UTILS_H
 #define OPKG_UTILS_H
 
-#include "pkg.h"
-#include "opkg_error.h"
-
-void push_error_list(char * msg);
-void free_error_list(void);
-void print_error_list(void);
-
-long unsigned int get_available_blocks(char * filesystem);
+unsigned long get_available_kbytes(char * filesystem);
 char *trim_xstrdup(const char *line);
 int line_is_blank(const char *line);
 
index 58c133d..411817b 100644 (file)
@@ -38,8 +38,8 @@
 typedef struct enum_map enum_map_t;
 struct enum_map
 {
-     int value;
-     char *str;
+     unsigned int value;
+     const char *str;
 };
 
 static const enum_map_t pkg_state_want_map[] = {
@@ -98,11 +98,9 @@ pkg_init(pkg_t *pkg)
      
      active_list_init(&pkg->list);
 
-     /* Abhaya: added init for conflicts fields */
      pkg->conflicts = NULL;
      pkg->conflicts_count = 0;
 
-     /* added for replaces.  Jamey 7/23/2002 */
      pkg->replaces = NULL;
      pkg->replaces_count = 0;
     
@@ -117,8 +115,8 @@ pkg_init(pkg_t *pkg)
 #if defined HAVE_SHA256
      pkg->sha256sum = NULL;
 #endif
-     pkg->size = NULL;
-     pkg->installed_size = NULL;
+     pkg->size = 0;
+     pkg->installed_size = 0;
      pkg->priority = NULL;
      pkg->source = NULL;
      conffile_list_init(&pkg->conffiles);
@@ -249,14 +247,6 @@ pkg_deinit(pkg_t *pkg)
        pkg->sha256sum = NULL;
 #endif
 
-       if (pkg->size)
-               free(pkg->size);
-       pkg->size = NULL;
-
-       if (pkg->installed_size)
-               free(pkg->installed_size);
-       pkg->installed_size = NULL;
-
        if (pkg->priority)
                free(pkg->priority);
        pkg->priority = NULL;
@@ -280,7 +270,7 @@ pkg_deinit(pkg_t *pkg)
 }
 
 int
-pkg_init_from_file(opkg_conf_t *conf, pkg_t *pkg, const char *filename)
+pkg_init_from_file(pkg_t *pkg, const char *filename)
 {
        int fd, err = 0;
        FILE *control_file;
@@ -295,14 +285,14 @@ pkg_init_from_file(opkg_conf_t *conf, pkg_t *pkg, const char *filename)
                         basename(filename));
        fd = mkstemp(control_path);
        if (fd == -1) {
-               perror_msg("%s: mkstemp(%s)", __FUNCTION__, control_path);
+               opkg_perror(ERROR, "Failed to make temp file %s", control_path);
                err = -1;
                goto err0;
        }
 
        control_file = fdopen(fd, "r+");
        if (control_file == NULL) {
-               perror_msg("%s: fdopen", __FUNCTION__, control_path);
+               opkg_perror(ERROR, "Failed to fdopen %s", control_path);
                close(fd);
                err = -1;
                goto err1;
@@ -310,14 +300,14 @@ pkg_init_from_file(opkg_conf_t *conf, pkg_t *pkg, const char *filename)
 
        err = pkg_extract_control_file_to_stream(pkg, control_file);
        if (err) {
-               opkg_message(conf, OPKG_ERROR, "Failed to extract control file"
-                               " from %s\n", filename);
+               opkg_msg(ERROR, "Failed to extract control file from %s.\n",
+                               filename);
                goto err2;
        }
 
        rewind(control_file);
 
-       if (pkg_parse_from_stream(pkg, control_file, PFM_ALL))
+       if (pkg_parse_from_stream(pkg, control_file, 0))
                err = -1;
 
 err2:
@@ -331,15 +321,8 @@ err0:
 }
 
 /* Merge any new information in newpkg into oldpkg */
-/* XXX: CLEANUP: This function shouldn't actually modify anything in
-   newpkg, but should leave it usable. This rework is so that
-   pkg_hash_insert doesn't clobber the pkg that you pass into it. */
-/* 
- * uh, i thought that i had originally written this so that it took 
- * two pkgs and returned a new one?  we can do that again... -sma
- */
 int
-pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status)
+pkg_merge(pkg_t *oldpkg, pkg_t *newpkg)
 {
      if (oldpkg == newpkg) {
          return 0;
@@ -362,18 +345,6 @@ pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status)
          oldpkg->maintainer = xstrdup(newpkg->maintainer);
      if(!oldpkg->description)
          oldpkg->description = xstrdup(newpkg->description);
-     if (set_status) {
-         /* merge the state_flags from the new package */
-         oldpkg->state_want = newpkg->state_want;
-         oldpkg->state_status = newpkg->state_status;
-         oldpkg->state_flag = newpkg->state_flag;
-     } else {
-         if (oldpkg->state_want == SW_UNKNOWN)
-              oldpkg->state_want = newpkg->state_want;
-         if (oldpkg->state_status == SS_NOT_INSTALLED)
-              oldpkg->state_status = newpkg->state_status;
-         oldpkg->state_flag |= newpkg->state_flag;
-     }
 
      if (!oldpkg->depends_count && !oldpkg->pre_depends_count && !oldpkg->recommends_count && !oldpkg->suggests_count) {
          oldpkg->depends_count = newpkg->depends_count;
@@ -431,22 +402,24 @@ pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status)
          oldpkg->sha256sum = xstrdup(newpkg->sha256sum);
 #endif
      if (!oldpkg->size)
-         oldpkg->size = xstrdup(newpkg->size);
+         oldpkg->size = newpkg->size;
      if (!oldpkg->installed_size)
-         oldpkg->installed_size = xstrdup(newpkg->installed_size);
+         oldpkg->installed_size = newpkg->installed_size;
      if (!oldpkg->priority)
          oldpkg->priority = xstrdup(newpkg->priority);
      if (!oldpkg->source)
          oldpkg->source = xstrdup(newpkg->source);
+
      if (nv_pair_list_empty(&oldpkg->conffiles)){
          list_splice_init(&newpkg->conffiles.head, &oldpkg->conffiles.head);
-         conffile_list_init(&newpkg->conffiles);
      }
+
      if (!oldpkg->installed_files){
          oldpkg->installed_files = newpkg->installed_files;
          oldpkg->installed_files_ref_cnt = newpkg->installed_files_ref_cnt;
          newpkg->installed_files = NULL;
      }
+
      if (!oldpkg->essential)
          oldpkg->essential = newpkg->essential;
 
@@ -473,7 +446,7 @@ abstract_pkg_new(void)
 }
 
 void
-set_flags_from_control(opkg_conf_t *conf, pkg_t *pkg){
+set_flags_from_control(pkg_t *pkg){
      char *file_name;
      FILE *fp;
 
@@ -481,16 +454,16 @@ set_flags_from_control(opkg_conf_t *conf, pkg_t *pkg){
 
      fp = fopen(file_name, "r");
      if (fp == NULL) {
-            opkg_message(conf, OPKG_ERROR, "%s: fopen(%s): %s\n",
-                            __FUNCTION__, file_name, strerror(errno));
+            opkg_perror(ERROR, "Failed to open %s");
             free(file_name);
             return;
      }
 
      free(file_name);
 
-     if (pkg_parse_from_stream(pkg, fp, PFM_ESSENTIAL)) {