summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libopkg/opkg.c80
-rw-r--r--libopkg/opkg.h21
-rw-r--r--tests/libopkg_test.c19
3 files changed, 120 insertions, 0 deletions
diff --git a/libopkg/opkg.c b/libopkg/opkg.c
index 30bde2e..a749bf9 100644
--- a/libopkg/opkg.c
+++ b/libopkg/opkg.c
@@ -26,6 +26,7 @@
#include "opkg_configure.h"
#include "opkg_download.h"
#include "opkg_remove.h"
+#include "opkg_upgrade.h"
#include "sprintf_alloc.h"
#include "file_util.h"
@@ -124,6 +125,49 @@ curl_progress_cb (struct _curl_cb_data *cb_data,
/*** Public API ***/
+opkg_package_t *
+opkg_package_new ()
+{
+
+ opkg_package_t *p;
+
+ p = malloc (sizeof (opkg_package_t));
+ memset (p, 0, sizeof (opkg_package_t));
+
+ return p;
+}
+
+opkg_package_t *
+opkg_package_new_with_values (const char *name, const char *version,
+ const char *arch, const char *desc, const char *tags, int installed)
+{
+ opkg_package_t *package;
+ package = opkg_package_new ();
+
+#define sstrdup(x) (x) ? strdup (x) : NULL;
+
+ package->name = sstrdup (name);
+ package->version = sstrdup (version);
+ package->architecture = sstrdup (arch);
+ package->description = sstrdup (desc);
+ package->tags = sstrdup (tags);
+ package->installed = (installed != 0);
+
+ return package;
+}
+
+void
+opkg_package_free (opkg_package_t *p)
+{
+ free (p->name);
+ free (p->version);
+ free (p->architecture);
+ free (p->description);
+ free (p->tags);
+
+ free (p);
+}
+
opkg_t *
opkg_new ()
{
@@ -647,3 +691,39 @@ opkg_update_package_lists (opkg_t *opkg, opkg_progress_callback_t progress_callb
return 0;
}
+
+
+int
+opkg_list_packages (opkg_t *opkg, 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);
+ for (i = 0; i < all->len; i++)
+ {
+ pkg_t *pkg;
+ opkg_package_t *package;
+
+ pkg = all->pkgs[i];
+
+ package = opkg_package_new_with_values (
+ pkg->name,
+ pkg->version,
+ pkg->architecture,
+ pkg->description,
+ pkg->tags,
+ (pkg->state_status == SS_INSTALLED));
+
+ callback (opkg, package, user_data);
+ }
+
+ pkg_vec_free (all);
+
+ return 0;
+}
+
diff --git a/libopkg/opkg.h b/libopkg/opkg.h
index b35635a..a6decd5 100644
--- a/libopkg/opkg.h
+++ b/libopkg/opkg.h
@@ -16,7 +16,26 @@
*/
typedef struct _opkg_t opkg_t;
+typedef struct _opkg_package_t opkg_package_t;
+
typedef void (*opkg_progress_callback_t) (opkg_t *opkg, int percentage, void *user_data);
+typedef void (*opkg_package_callback_t) (opkg_t *opkg, opkg_package_t *package, void *user_data);
+
+
+struct _opkg_package_t
+{
+ char *name;
+ char *version;
+ char *architecture;
+ char *repository;
+ char *description;
+ char *tags;
+ int installed;
+};
+
+opkg_package_t* opkg_package_new ();
+opkg_package_t* opkg_package_new_with_values (const char *name, const char *version, const char *arch, const char *desc, const char *tags, int installed);
+void opkg_package_free (opkg_package_t *package);
opkg_t* opkg_new ();
void opkg_free (opkg_t *opkg);
@@ -29,3 +48,5 @@ int opkg_remove_package (opkg_t *opkg, const char *package_name, opkg_progress_c
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_list_packages (opkg_t *opkg, opkg_package_callback_t callback, void *user_data);
diff --git a/tests/libopkg_test.c b/tests/libopkg_test.c
index 79e33ab..ac61738 100644
--- a/tests/libopkg_test.c
+++ b/tests/libopkg_test.c
@@ -9,6 +9,22 @@ progress_callback (opkg_t *opkg, int percent, void *data)
fflush (stdout);
}
+void
+package_list_callback (opkg_t *opkg, opkg_package_t *pkg, void *data)
+{
+ static install_count = 0;
+ static total_count = 0;
+
+ if (pkg->installed)
+ install_count++;
+
+ total_count++;
+
+ printf ("\rPackage count: %d Installed, %d Total Available", install_count, total_count);
+ fflush (stdout);
+
+ opkg_package_free (pkg);
+}
int
main (int argc, char **argv)
@@ -37,5 +53,8 @@ main (int argc, char **argv)
err = opkg_remove_package (opkg, "aspell", progress_callback, "Removing...");
printf ("\nopkg_remove_package returned %d\n", err);
+ opkg_list_packages (opkg, package_list_callback, NULL);
+ printf ("\n");
+
opkg_free (opkg);
}