]> git.ipfire.org Git - location/libloc.git/commitdiff
database: Check if this version of libloc supports the database format
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 23 Aug 2022 10:01:19 +0000 (10:01 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 23 Aug 2022 10:01:19 +0000 (10:01 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/database.c

index afd64dc918e037bc9600cf1ca5dcad4ea017640a..ea058b6dcc3c8c8f313e716018743e0a1c11f827 100644 (file)
@@ -166,6 +166,19 @@ static void* __loc_database_read_object(struct loc_database* db, void* buffer,
        return buffer;
 }
 
+static int loc_database_version_supported(struct loc_database* db, uint8_t version) {
+       switch (version) {
+               // Supported versions
+               case LOC_DATABASE_VERSION_1:
+                       return 1;
+
+               default:
+                       ERROR(db->ctx, "Database version %d is not supported\n", version);
+                       errno = ENOTSUP;
+                       return 0;
+       }
+}
+
 static int loc_database_check_magic(struct loc_database* db) {
        struct loc_database_magic magic;
 
@@ -183,6 +196,10 @@ static int loc_database_check_magic(struct loc_database* db) {
        if (memcmp(magic.magic, LOC_DATABASE_MAGIC, sizeof(magic.magic)) == 0) {
                DEBUG(db->ctx, "Magic value matches\n");
 
+               // Do we support this version?
+               if (!loc_database_version_supported(db, magic.version))
+                       return 1;
+
                // Parse version
                db->version = magic.version;