]> git.ipfire.org Git - pakfire.git/commitdiff
pakfire: Add a custom namespace for features
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 29 Apr 2021 21:10:25 +0000 (21:10 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 29 Apr 2021 21:10:25 +0000 (21:10 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/pakfire.c

index 5427f787aee709644b8e2a3a3923b4738df5d267..2a394fb1b57d6b13cf505efcfde6d6950c67c557 100644 (file)
@@ -95,6 +95,16 @@ struct _Pakfire {
        } distro;
 };
 
+/*
+       This is a list of all features that are supported by this version of Pakfire
+*/
+static const struct pakfire_feature {
+       const char* name;
+} features[] = {
+       { "Compress-Zstandard" },
+       { NULL },
+};
+
 static const struct pakfire_mountpoint {
        const char* source;
        const char* target;
@@ -328,6 +338,28 @@ static void pool_log(Pool* pool, void* data, int type, const char* s) {
        DEBUG(pakfire, "pool: %s", s);
 }
 
+static Id pakfire_namespace_callback(Pool* pool, void* data, Id ns, Id id) {
+       Pakfire pakfire = (Pakfire)data;
+
+       const char* namespace = pool_id2str(pool, ns);
+       const char* name = pool_dep2str(pool, id);
+
+       DEBUG(pakfire, "Namespace callback called for %s(%s)\n", namespace, name);
+
+       // We only handle the pakfire namesapce
+       if (strcmp(namespace, "pakfire") != 0)
+               return 0;
+
+       // Find all supported features
+       for (const struct pakfire_feature* feature = features; feature->name; feature++) {
+               if (strcmp(feature->name, name) == 0)
+                       return 1;
+       }
+
+       // Not supported
+       return 0;
+}
+
 static int pakfire_populate_pool(Pakfire pakfire) {
        struct pakfire_db* db;
        PakfireRepo repo = NULL;
@@ -352,6 +384,9 @@ static int pakfire_populate_pool(Pakfire pakfire) {
        // Set debug callback
        pool_setdebugcallback(pool, pool_log, pakfire);
 
+       // Install namespace callback
+       pool_setnamespacecallback(pool, pakfire_namespace_callback, pakfire);
+
        // Open database in read-only mode and try to load all installed packages
        r = pakfire_db_open(&db, pakfire, PAKFIRE_DB_READWRITE);
        if (r)