opkg: remove opkg.h in preperation for new API
[project/opkg-lede.git] / libopkg / opkg_cmd.c
index 27765f3ac7efde012f11f8b9a1703db717df78f4..02e67556e1b856a7caeb87bc09af755f6daedfea 100644 (file)
    General Public License for more details.
 */
 
-#include <string.h>
 
-#include "opkg.h"
-#include <libgen.h>
-#include <glob.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <signal.h>
-#include <stdio.h>
+#include "includes.h"
 #include <dirent.h>
+#include <glob.h>
 
 #include "opkg_conf.h"
 #include "opkg_cmd.h"
@@ -38,6 +31,8 @@
 #include "file_util.h"
 #include "str_util.h"
 #include "libbb/libbb.h"
+#include "opkg_utils.h"
+#include "opkg_defines.h"
 
 #include <fnmatch.h>
 
 #include "opkg_configure.h"
 #include "opkg_message.h"
 
-#ifdef OPKG_LIB
 #include "libopkg.h"
 static void *p_userdata = NULL;
-#endif
 
 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);
@@ -145,7 +138,6 @@ opkg_cmd_t *opkg_cmd_find(const char *name)
      return NULL;
 }
 
-#ifdef OPKG_LIB
 int opkg_cmd_exec(opkg_cmd_t *cmd, opkg_conf_t *conf, int argc, const char **argv, void *userdata)
 {
        int result;
@@ -175,12 +167,6 @@ int opkg_cmd_exec(opkg_cmd_t *cmd, opkg_conf_t *conf, int argc, const char **arg
        p_userdata = NULL;
        return result;
 }
-#else
-int opkg_cmd_exec(opkg_cmd_t *cmd, opkg_conf_t *conf, int argc, const char **argv)
-{
-     return (cmd->fun)(conf, argc, argv);
-}
-#endif
 
 static int opkg_update_cmd(opkg_conf_t *conf, int argc, char **argv)
 {
@@ -266,6 +252,7 @@ static int opkg_update_cmd(opkg_conf_t *conf, int argc, char **argv)
          }
          free(url);
 
+#ifdef HAVE_GPGME
          /* download detached signitures to verify the package lists */
          /* get the url for the sig file */
          if (src->extra_data)  /* debian style? */
@@ -285,7 +272,7 @@ static int opkg_update_cmd(opkg_conf_t *conf, int argc, char **argv)
                opkg_message (conf, OPKG_NOTICE, "Signature check failed\n");
          } else {
            int err;
-           err = opkg_verify_file (list_file_name, tmp_file_name);
+           err = opkg_verify_file (conf, list_file_name, tmp_file_name);
            if (err == 0)
                opkg_message (conf, OPKG_NOTICE, "Signature check passed\n");
            else
@@ -293,41 +280,17 @@ static int opkg_update_cmd(opkg_conf_t *conf, int argc, char **argv)
          }
          unlink (tmp_file_name);
          free (tmp_file_name);
-
          free (url);
+#else
+         opkg_message (conf, OPKG_NOTICE, "Signiture check for %s skipped "
+              "because GPG support was not enabled in this build\n", src->name);
+#endif
          free(list_file_name);
      }
      rmdir (tmp);
      free (tmp);
      free(lists_dir);
 
-#ifdef CONFIG_CLEAR_SW_INSTALL_FLAG
-#warning here
-     /* clear SW_INSTALL on any package where state is SS_NOT_INSTALLED.
-      * this is a hack to work around poor bookkeeping in old opkg upgrade code 
-      * -Jamey 3/1/03
-      */
-     {
-         int i;
-         int changed = 0;
-         pkg_vec_t *available = pkg_vec_alloc();
-         pkg_hash_fetch_available(&conf->pkg_hash, available);
-         opkg_message(conf, OPKG_DEBUG, "Clearing SW_INSTALL for SS_NOT_INSTALLED packages.\n");
-         for (i = 0; i < available->len; i++) {
-              pkg_t *pkg = available->pkgs[i];
-              if (pkg->state_want == SW_INSTALL && pkg->state_status == SS_NOT_INSTALLED) {
-                   opkg_message(conf, OPKG_DEBUG, "Clearing SW_INSTALL on package %s.\n", pkg->name);
-                   pkg->state_want = SW_UNKNOWN;
-                   changed = 1;
-              }
-         }
-         pkg_vec_free(available);
-         if (changed) {
-              write_status_files_if_changed(conf);
-         }
-     }
-#endif
-
      return failures;
 }
 
@@ -673,9 +636,6 @@ static int opkg_list_cmd(opkg_conf_t *conf, int argc, char **argv)
          if (newline) {
               *newline = '\0';
          }
-#ifndef OPKG_LIB
-         printf("%s - %s\n", pkg->name, desc_short);
-#else
          if (opkg_cb_list) {
                version_str = pkg_version_str_alloc(pkg);
                opkg_cb_list(pkg->name,desc_short,
@@ -684,7 +644,6 @@ static int opkg_list_cmd(opkg_conf_t *conf, int argc, char **argv)
                                         p_userdata);
                free(version_str);
          }
-#endif
      }
      pkg_vec_free(available);
 
@@ -722,9 +681,6 @@ static int opkg_list_installed_cmd(opkg_conf_t *conf, int argc, char **argv)
          if (newline) {
               *newline = '\0';
          }
-#ifndef OPKG_LIB
-         printf("%s - %s\n", pkg->name, desc_short);
-#else
          if (opkg_cb_list) {
                version_str = pkg_version_str_alloc(pkg);
                opkg_cb_list(pkg->name,desc_short,
@@ -733,7 +689,6 @@ static int opkg_list_installed_cmd(opkg_conf_t *conf, int argc, char **argv)
                                         p_userdata);
                free(version_str);
          }
-#endif
      }
 
      return 0;
@@ -767,14 +722,6 @@ static int opkg_info_status_cmd(opkg_conf_t *conf, int argc, char **argv, int in
          if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
               continue;
          }
-#ifndef OPKG_LIB
-         if (n_fields) {
-              for (j = 0; j < n_fields; j++)
-                   pkg_print_field(pkg, stdout, pkg_fields[j]);
-         } else {
-              pkg_print_info(pkg, stdout);
-         }
-#else
 
          buff = pkg_formatted_info(pkg);
           if ( buff ) {
@@ -788,7 +735,6 @@ static int opkg_info_status_cmd(opkg_conf_t *conf, int argc, char **argv, int in
 */
                free(buff);
           }
-#endif
          if (conf->verbosity > 1) {
               conffile_list_elt_t *iter;
               for (iter = pkg->conffiles.head; iter; iter = iter->next) {
@@ -799,10 +745,6 @@ static int opkg_info_status_cmd(opkg_conf_t *conf, int argc, char **argv, int in
               }
          }
      }
-#ifndef OPKG_LIB
-     if (buff)
-         free(buff);
-#endif
      pkg_vec_free(available);
 
      return 0;
@@ -1077,13 +1019,6 @@ static int opkg_files_cmd(opkg_conf_t *conf, int argc, char **argv)
      installed_files = pkg_get_installed_files(pkg);
      pkg_version = pkg_version_str_alloc(pkg);
 
-#ifndef OPKG_LIB
-     printf("Package %s (%s) is installed on %s and has the following files:\n",
-           pkg->name, pkg_version, pkg->dest->name);
-     for (iter = installed_files->head; iter; iter = iter->next) {
-         puts(iter->data);
-     }
-#else
      if (buff) {
      try_again:
          used_len = snprintf(buff, buff_len, "Package %s (%s) is installed on %s and has the following files:\n",
@@ -1109,7 +1044,6 @@ static int opkg_files_cmd(opkg_conf_t *conf, int argc, char **argv)
                                         p_userdata);
          free(buff);
      }
-#endif
 
      free(pkg_version);
      pkg_free_installed_files(pkg);
@@ -1403,14 +1337,10 @@ static int opkg_search_cmd(opkg_conf_t *conf, int argc, char **argv)
          for (iter = installed_files->head; iter; iter = iter->next) {
               installed_file = iter->data;
               if (fnmatch(argv[0], installed_file, 0)==0)  {
-#ifndef OPKG_LIB
-                   printf("%s: %s\n", pkg->name, installed_file);
-#else
                        if (opkg_cb_list) opkg_cb_list(pkg->name, 
                                                       installed_file, 
                                                       pkg_version_str_alloc(pkg), 
                                                       pkg->state_status, p_userdata);
-#endif                    
               }                
          }