__FILE__, __LINE__, __PRETTY_FUNCTION__, # expr); abort (); }
#define progress(d, p) d.percentage = p; if (progress_callback) progress_callback (opkg, &d, user_data);
-#define OLD_PKG_TO_NEW(pkg) opkg_package_new_with_values (pkg->name, pkg->version, pkg->architecture, pkg->description, pkg->tags, pkg->url, (pkg->size ? atoi (pkg->size) : 0), (pkg->state_status == SS_INSTALLED));
+#define SSTRCMP(x,y) (x && y) ? strcmp (x, y) : 0
/** Private Functions ***/
+static opkg_package_t*
+old_pkg_to_new (pkg_t *old)
+{
+ opkg_package_t *new;
+
+ new = opkg_package_new ();
+
+#define sstrdup(x) (x) ? strdup (x) : NULL;
+
+ new->name = sstrdup (old->name);
+ new->version = pkg_version_str_alloc (old);
+ new->architecture = sstrdup (old->architecture);
+ new->repository = sstrdup (old->src->name);
+ new->description = sstrdup (old->description);
+ new->tags = sstrdup (old->tags);
+ new->url = sstrdup (old->url);
+
+ new->size = (old->size) ? atoi (old->size) : 0;
+ new->installed = (old->state_status == SS_INSTALLED);
+
+ return new;
+}
static int
opkg_configure_packages(opkg_conf_t *conf, char *pkg_name)
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, const char *url, int size, 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->url = sstrdup (url);
-
- package->size = size;
- package->installed = (installed != 0);
-
- return package;
-}
-
void
opkg_package_free (opkg_package_t *p)
{
return 1;
}
pdata.action = OPKG_INSTALL;
- pdata.package = OLD_PKG_TO_NEW (new);
+ pdata.package = old_pkg_to_new (new);
progress (pdata, 0);
}
pdata.action = OPKG_REMOVE;
- pdata.package = OLD_PKG_TO_NEW (pkg);
+ pdata.package = old_pkg_to_new (pkg);
progress (pdata, 0);
}
pdata.action = OPKG_INSTALL;
- pdata.package = OLD_PKG_TO_NEW (pkg);
+ pdata.package = old_pkg_to_new (pkg);
progress (pdata, 0);
opkg_upgrade_pkg (opkg->conf, pkg);
{
pkg = installed->pkgs[i];
- pdata.package = OLD_PKG_TO_NEW (pkg);
+ pdata.package = old_pkg_to_new (pkg);
progress (pdata, 99 * i / installed->len);
opkg_package_free (pdata.package);
pkg = all->pkgs[i];
- package = OLD_PKG_TO_NEW (pkg);
+ package = old_pkg_to_new (pkg);
callback (opkg, package, user_data);
}
if (cmp < 0)
{
- package = OLD_PKG_TO_NEW (new);
+ package = old_pkg_to_new (new);
callback (opkg, package, user_data);
}
}
return 0;
}
+opkg_package_t*
+opkg_find_package (opkg_t *opkg, 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);
+ for (i = 0; i < all->len; i++)
+ {
+ pkg_t *pkg;
+ char *pkgv;
+
+ pkg = all->pkgs[i];
+
+ /* check name */
+ if (sstrcmp (pkg->name, name))
+ continue;
+
+ /* check version */
+ pkgv = pkg_version_str_alloc (pkg);
+ if (sstrcmp (pkgv, ver))
+ {
+ free (pkgv);
+ continue;
+ }
+ free (pkgv);
+
+ /* check architecture */
+ if (arch)
+ {
+ if (sstrcmp (pkg->architecture, arch))
+ continue;
+ }
+
+ /* check repository */
+ if (repo)
+ {
+ if (sstrcmp (pkg->src->name, repo))
+ continue;
+ }
+
+ /* match found */
+ package = old_pkg_to_new (pkg);
+ break;
+ }
+
+ pkg_vec_free (all);
+
+ return package;
+}
#include <stdlib.h>
#include <stdio.h>
+opkg_package_t *find_pkg = NULL;
+
void
progress_callback (opkg_t *opkg, const opkg_progress_data_t *progress, void *data)
{
printf ("\rPackage count: %d Installed, %d Total Available", install_count, total_count);
fflush (stdout);
- opkg_package_free (pkg);
+ if (!find_pkg)
+ {
+ /* store the first package to print out later */
+ find_pkg = pkg;
+ }
+ else
+ opkg_package_free (pkg);
}
void
printf ("%s - %s\n", pkg->name, pkg->version);
}
+void
+print_package (opkg_package_t *pkg)
+{
+ printf (
+ "Name: %s\n"
+ "Version: %s\n"
+ "Repository: %s\n"
+ "Architecture: %s\n"
+ "Description: %s\n"
+ "Tags: %s\n"
+ "URL: %s\n"
+ "Size: %d\n"
+ "Installed: %s\n",
+ pkg->name,
+ pkg->version,
+ pkg->repository,
+ pkg->architecture,
+ pkg->description,
+ pkg->tags,
+ pkg->url,
+ pkg->size,
+ (pkg->installed ? "True" : "False")
+ );
+}
+
int
main (int argc, char **argv)
{
opkg_t *opkg;
+ opkg_package_t *pkg;
int err;
opkg = opkg_new ();
err = opkg_update_package_lists (opkg, progress_callback, "Updating...");
printf ("\nopkg_update_package_lists returned %d\n", err);
+ opkg_list_packages (opkg, package_list_callback, NULL);
+ printf ("\n");
+
+ if (find_pkg)
+ {
+ printf ("Finding package \"%s\"\n", find_pkg->name);
+ pkg = opkg_find_package (opkg, find_pkg->name, find_pkg->version, find_pkg->architecture, find_pkg->repository);
+ if (pkg)
+ {
+ print_package (pkg);
+ opkg_package_free (find_pkg);
+ opkg_package_free (pkg);
+ }
+ else
+ printf ("Package \"%s\" not found!\n", find_pkg->name);
+ }
+ else
+ printf ("No package available to test find_package.\n");
+
err = opkg_install_package (opkg, "aspell", progress_callback, "Installing...");
printf ("\nopkg_install_package returned %d\n", err);
err = opkg_upgrade_all (opkg, progress_callback, "Upgrading all...");
printf ("\nopkg_upgrade_all returned %d\n", err);
- opkg_list_packages (opkg, package_list_callback, NULL);
- printf ("\n");
-
opkg_free (opkg);
+
+ return 0;
}