Remove enum opkg_error.
[oweals/opkg-lede.git] / libopkg / opkg.c
index a20023e34341fae40ac9ef706b0fb1f2d5fd6ad2..50f875292b76fa1f4ff79d2480fb72078dc2a2f1 100644 (file)
@@ -34,8 +34,6 @@
 
 #include <libbb/libbb.h>
 
-struct errlist* error_list;
-
 struct _opkg_t
 {
   args_t *args;
@@ -62,18 +60,14 @@ pkg_t_to_opkg_package_t (pkg_t *old)
 
   new = opkg_package_new ();
 
-#define sstrdup(x) (x) ? strdup (x) : NULL;
-
-  new->name = sstrdup (old->name);
+  new->name = xstrdup(old->name);
   new->version = pkg_version_str_alloc (old);
-  new->architecture = sstrdup (old->architecture);
+  new->architecture = xstrdup(old->architecture);
   if (old->src)
-    new->repository = sstrdup (old->src->name);
-  new->description = sstrdup (old->description);
-  new->tags = sstrdup (old->tags);
-  new->url = sstrdup (old->url);
-
-#undef sstrdup
+    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->installed = (old->state_status == SS_INSTALLED);
@@ -168,7 +162,7 @@ opkg_package_new ()
 
   opkg_package_t *p;
 
-  p = calloc (1, sizeof (opkg_package_t));
+  p = xcalloc(1, sizeof (opkg_package_t));
 
   return p;
 }
@@ -193,18 +187,12 @@ opkg_new ()
   opkg_t *opkg;
   int err;
 
-  opkg = calloc (1, sizeof (opkg_t));
+  opkg = xcalloc(1, sizeof (opkg_t));
 
-  opkg->args = calloc (1, sizeof (args_t));
-  err = args_init (opkg->args);
-  if (err)
-  {
-    free (opkg->args);
-    free (opkg);
-    return NULL;
-  }
+  opkg->args = xcalloc(1, sizeof (args_t));
+  args_init (opkg->args);
 
-  opkg->conf = calloc (1, sizeof (opkg_conf_t));
+  opkg->conf = xcalloc(1, sizeof (opkg_conf_t));
   err = opkg_conf_init (opkg->conf, opkg->args);
   if (err)
   {
@@ -223,6 +211,9 @@ opkg_free (opkg_t *opkg)
 {
   opkg_assert (opkg != NULL);
 
+#ifdef HAVE_CURL
+  opkg_curl_cleanup();
+#endif
   opkg_conf_deinit (opkg->conf);
   args_deinit (opkg->args);
   free (opkg->options);
@@ -263,25 +254,25 @@ opkg_re_read_config_files (opkg_t *opkg)
   if (c->offline_root)
   {
     if (a->offline_root) free (a->offline_root);
-    a->offline_root = strdup (c->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 = strdup (c->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 = strdup (c->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 = strdup(c->cache);
+    a->cache = xstrdup(c->cache);
   }
 
   /* throw away old opkg_conf and start again */
@@ -330,7 +321,7 @@ opkg_get_option (opkg_t *opkg, char *option, void **value)
     return;
 
   case OPKG_OPT_TYPE_STRING:
-    *((char **)value) = strdup (options[i].value);
+    *((char **)value) = xstrdup(options[i].value);
     return;
   }
 
@@ -382,7 +373,7 @@ opkg_set_option (opkg_t *opkg, char *option, void *value)
     return;
 
   case OPKG_OPT_TYPE_STRING:
-    *((char **)options[i].value) = strdup (value);
+    *((char **)options[i].value) = xstrdup(value);
     return;
   }
 
@@ -522,18 +513,7 @@ opkg_install_package (opkg_t *opkg, const char *package_name, opkg_progress_call
   if (err)
   {
     opkg_package_free (pdata.package);
-    switch (err)
-    {
-      case OPKG_INSTALL_ERR_NOT_TRUSTED: return OPKG_GPG_ERROR;
-      case OPKG_INSTALL_ERR_DOWNLOAD: return OPKG_DOWNLOAD_FAILED;
-      case OPKG_INSTALL_ERR_DEPENDENCIES:
-      case OPKG_INSTALL_ERR_CONFLICTS: return OPKG_DEPENDENCIES_FAILED;
-      case OPKG_INSTALL_ERR_ALREADY_INSTALLED: return OPKG_PACKAGE_ALREADY_INSTALLED;
-      case OPKG_INSTALL_ERR_SIGNATURE: return OPKG_GPG_ERROR;
-      case OPKG_INSTALL_ERR_MD5: return OPKG_MD5_ERROR;
-      case OPKG_INSTALL_ERR_SHA256: return OPKG_SHA256_ERROR;
-      default: return OPKG_UNKNOWN_ERROR;
-    }
+    return OPKG_UNKNOWN_ERROR;
   }
 
   progress (pdata, 75);
@@ -660,20 +640,8 @@ opkg_upgrade_package (opkg_t *opkg, const char *package_name, opkg_progress_call
   /* opkg_upgrade_pkg returns the error codes of opkg_install_pkg */
   if (err)
   {
-
     opkg_package_free (pdata.package);
-    switch (err)
-    {
-      case OPKG_INSTALL_ERR_NOT_TRUSTED: return OPKG_GPG_ERROR;
-      case OPKG_INSTALL_ERR_DOWNLOAD: return OPKG_DOWNLOAD_FAILED;
-      case OPKG_INSTALL_ERR_DEPENDENCIES:
-      case OPKG_INSTALL_ERR_CONFLICTS: return OPKG_DEPENDENCIES_FAILED;
-      case OPKG_INSTALL_ERR_ALREADY_INSTALLED: return OPKG_PACKAGE_ALREADY_INSTALLED;
-      case OPKG_INSTALL_ERR_SIGNATURE: return OPKG_GPG_ERROR;
-      case OPKG_INSTALL_ERR_MD5: return OPKG_MD5_ERROR;
-      case OPKG_INSTALL_ERR_SHA256: return OPKG_SHA256_ERROR;
-      default: return OPKG_UNKNOWN_ERROR;
-    }
+    return OPKG_UNKNOWN_ERROR;
   }
   progress (pdata, 75);
 
@@ -775,10 +743,8 @@ opkg_update_package_lists (opkg_t *opkg, opkg_progress_callback_t progress_callb
     }
   }
 
-  tmp = strdup ("/tmp/opkg.XXXXXX");
-
-  if (mkdtemp (tmp) == NULL)
-  {
+  sprintf_alloc(&tmp, "%s/update-XXXXXX", opkg->conf->tmp_dir);
+  if (mkdtemp (tmp) == NULL) {
     /* XXX: Error: could not create temporary file name */
     free (lists_dir);
     free (tmp);
@@ -852,7 +818,7 @@ opkg_update_package_lists (opkg_t *opkg, opkg_progress_callback_t progress_callb
     }
     free (url);
 
-#ifdef HAVE_GPGME
+#if defined(HAVE_GPGME) || defined(HAVE_OPENSSL)
     if ( opkg->conf->check_signature ) {
         char *sig_file_name;
         /* download detached signitures to verify the package lists */
@@ -1049,11 +1015,11 @@ int opkg_repository_accessibility_check(opkg_t *opkg)
   {
     if (strstr(((pkg_src_t *)iter->data)->value, "://") && 
                    index(strstr(((pkg_src_t *)iter->data)->value, "://") + 3, '/')) 
-      stmp = strndup(((pkg_src_t *)iter->data)->value, 
+      stmp = xstrndup(((pkg_src_t *)iter->data)->value, 
                      (index(strstr(((pkg_src_t *)iter->data)->value, "://") + 3, '/') - ((pkg_src_t *)iter->data)->value)*sizeof(char));
 
     else
-      stmp = strdup(((pkg_src_t *)iter->data)->value);
+      stmp = xstrdup(((pkg_src_t *)iter->data)->value);
 
     for (iter1 = str_list_first(src); iter1; iter1 = str_list_next(src, iter1))
     {
@@ -1089,7 +1055,6 @@ int opkg_repository_accessibility_check(opkg_t *opkg)
            ret++;
     }
     str_list_elt_deinit(iter1);
-    free(iter1);
   }
   free(src);
   return ret;