opkg: rename opkg_clone to pkg_t_to_opkg_package_t.
[oweals/opkg-lede.git] / libopkg / opkg.c
index 60475f31ffe9ef56c19c01e94a63a7b4269836bd..0dff32b3b62d2d1dfa6425c808ab1b8dcf5e1c61 100644 (file)
@@ -52,8 +52,11 @@ struct _opkg_t
 
 /** Private Functions ***/
 
 
 /** Private Functions ***/
 
+/**
+ * Clone a pkg_t 
+ */ 
 static opkg_package_t*
 static opkg_package_t*
-old_pkg_to_new (pkg_t *old)
+pkg_t_to_opkg_package_t (pkg_t *old)
 {
   opkg_package_t *new;
 
 {
   opkg_package_t *new;
 
@@ -70,6 +73,8 @@ old_pkg_to_new (pkg_t *old)
   new->tags = sstrdup (old->tags);
   new->url = sstrdup (old->url);
 
   new->tags = sstrdup (old->tags);
   new->url = sstrdup (old->url);
 
+#undef sstrdup
+
   new->size = (old->size) ? atoi (old->size) : 0;
   new->installed = (old->state_status == SS_INSTALLED);
 
   new->size = (old->size) ? atoi (old->size) : 0;
   new->installed = (old->state_status == SS_INSTALLED);
 
@@ -382,6 +387,12 @@ 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)
 {
 int
 opkg_install_package (opkg_t *opkg, const char *package_name, opkg_progress_callback_t progress_callback, void *user_data)
 {
@@ -418,7 +429,7 @@ opkg_install_package (opkg_t *opkg, const char *package_name, opkg_progress_call
   new->state_flag |= SF_USER;
 
   pdata.action = OPKG_INSTALL;
   new->state_flag |= SF_USER;
 
   pdata.action = OPKG_INSTALL;
-  pdata.package = old_pkg_to_new (new);
+  pdata.package = pkg_t_to_opkg_package_t (new);
 
   progress (pdata, 0);
 
 
   progress (pdata, 0);
 
@@ -448,7 +459,7 @@ opkg_install_package (opkg_t *opkg, const char *package_name, opkg_progress_call
       continue;
 
     opkg_package_free (pdata.package);
       continue;
 
     opkg_package_free (pdata.package);
-    pdata.package = old_pkg_to_new (pkg);
+    pdata.package = pkg_t_to_opkg_package_t (pkg);
     pdata.action = OPKG_DOWNLOAD;
 
     if (pkg->src == NULL)
     pdata.action = OPKG_DOWNLOAD;
 
     if (pkg->src == NULL)
@@ -500,7 +511,7 @@ opkg_install_package (opkg_t *opkg, const char *package_name, opkg_progress_call
 
   /* 75% of "install" progress is for downloading */
   opkg_package_free (pdata.package);
 
   /* 75% of "install" progress is for downloading */
   opkg_package_free (pdata.package);
-  pdata.package = old_pkg_to_new (new);
+  pdata.package = pkg_t_to_opkg_package_t (new);
   pdata.action = OPKG_INSTALL;
   progress (pdata, 75);
 
   pdata.action = OPKG_INSTALL;
   progress (pdata, 75);
 
@@ -564,7 +575,7 @@ opkg_remove_package (opkg_t *opkg, const char *package_name, opkg_progress_callb
   }
 
   pdata.action = OPKG_REMOVE;
   }
 
   pdata.action = OPKG_REMOVE;
-  pdata.package = old_pkg_to_new (pkg);
+  pdata.package = pkg_t_to_opkg_package_t (pkg);
   progress (pdata, 0);
 
 
   progress (pdata, 0);
 
 
@@ -640,7 +651,7 @@ opkg_upgrade_package (opkg_t *opkg, const char *package_name, opkg_progress_call
   }
 
   pdata.action = OPKG_INSTALL;
   }
 
   pdata.action = OPKG_INSTALL;
-  pdata.package = old_pkg_to_new (pkg);
+  pdata.package = pkg_t_to_opkg_package_t (pkg);
   progress (pdata, 0);
 
   err = opkg_upgrade_pkg (opkg->conf, pkg);
   progress (pdata, 0);
 
   err = opkg_upgrade_pkg (opkg->conf, pkg);
@@ -701,7 +712,7 @@ opkg_upgrade_all (opkg_t *opkg, opkg_progress_callback_t progress_callback, void
   {
     pkg = installed->pkgs[i];
 
   {
     pkg = installed->pkgs[i];
 
-    pdata.package = old_pkg_to_new (pkg);
+    pdata.package = pkg_t_to_opkg_package_t (pkg);
     progress (pdata, 99 * i / installed->len);
     opkg_package_free (pdata.package);
 
     progress (pdata, 99 * i / installed->len);
     opkg_package_free (pdata.package);
 
@@ -916,7 +927,7 @@ opkg_list_packages (opkg_t *opkg, opkg_package_callback_t callback, void *user_d
 
     pkg = all->pkgs[i];
 
 
     pkg = all->pkgs[i];
 
-    package = old_pkg_to_new (pkg);
+    package = pkg_t_to_opkg_package_t (pkg);
     callback (opkg, package, user_data);
     opkg_package_free (package);
   }
     callback (opkg, package, user_data);
     opkg_package_free (package);
   }
@@ -929,8 +940,11 @@ 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)
 {
 int
 opkg_list_upgradable_packages (opkg_t *opkg, opkg_package_callback_t callback, void *user_data)
 {
-    pkg_vec_t *all;
-    int i;
+    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);
 
     opkg_assert (opkg);
     opkg_assert (callback);
@@ -938,23 +952,15 @@ opkg_list_upgradable_packages (opkg_t *opkg, opkg_package_callback_t callback, v
     /* ensure all data is valid */
     pkg_info_preinstall_check (opkg->conf);
 
     /* ensure all data is valid */
     pkg_info_preinstall_check (opkg->conf);
 
-    all = opkg_upgrade_all_list_get (opkg->conf);
-    for (i = 0; i < all->len; i++)
-    {
-        pkg_t *old, *new;
-        opkg_package_t *package;
-
-        old = all->pkgs[i];
-
+    head  =  prepare_upgrade_list(opkg->conf);
+    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, NULL);
         new = pkg_hash_fetch_best_installation_candidate_by_name(opkg->conf, old->name, NULL);
-
-        package = old_pkg_to_new (new);
+        package = pkg_t_to_opkg_package_t (new);
         callback (opkg, package, user_data);
         opkg_package_free (package);
     }
         callback (opkg, package, user_data);
         opkg_package_free (package);
     }
-
-    pkg_vec_free (all);
-
+    active_list_head_delete(head);
     return 0;
 }
 
     return 0;
 }
 
@@ -1005,7 +1011,7 @@ opkg_find_package (opkg_t *opkg, const char *name, const char *ver, const char *
     }
 
     /* match found */
     }
 
     /* match found */
-    package = old_pkg_to_new (pkg);
+    package = pkg_t_to_opkg_package_t (pkg);
     break;
   }
 
     break;
   }