]> git.ipfire.org Git - people/ms/libloc.git/commitdiff
database: Save time when the database was created
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 12 Dec 2017 13:29:10 +0000 (13:29 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 12 Dec 2017 13:29:10 +0000 (13:29 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/database.c
src/database.h
src/libloc.sym
src/loc/format.h

index a263d0270dba16d422ea28e85d52fa49f800847f..f51931a604df96227a622f10a0597801c1dd5346 100644 (file)
@@ -22,6 +22,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/types.h>
 #include <stdlib.h>
 #include <string.h>
 #include <sys/types.h>
+#include <time.h>
 #include <unistd.h>
 
 #include <loc/libloc.h>
 #include <unistd.h>
 
 #include <loc/libloc.h>
@@ -38,6 +39,7 @@ struct loc_database {
 
        FILE* file;
        unsigned int version;
 
        FILE* file;
        unsigned int version;
+       time_t created_at;
        off_t vendor;
        off_t description;
 
        off_t vendor;
        off_t description;
 
@@ -57,6 +59,9 @@ LOC_EXPORT int loc_database_new(struct loc_ctx* ctx, struct loc_database** datab
        db->ctx = loc_ref(ctx);
        db->refcount = 1;
 
        db->ctx = loc_ref(ctx);
        db->refcount = 1;
 
+       // Save creation time
+       db->created_at = time(NULL);
+
        DEBUG(db->ctx, "Database allocated at %p\n", db);
 
        // Create string pool
        DEBUG(db->ctx, "Database allocated at %p\n", db);
 
        // Create string pool
@@ -114,6 +119,10 @@ LOC_EXPORT struct loc_database* loc_database_unref(struct loc_database* db) {
        return NULL;
 }
 
        return NULL;
 }
 
+LOC_EXPORT time_t loc_database_created_at(struct loc_database* db) {
+       return db->created_at;
+}
+
 LOC_EXPORT const char* loc_database_get_vendor(struct loc_database* db) {
        return loc_stringpool_get(db->pool, db->vendor);
 }
 LOC_EXPORT const char* loc_database_get_vendor(struct loc_database* db) {
        return loc_stringpool_get(db->pool, db->vendor);
 }
@@ -274,6 +283,7 @@ static int loc_database_read_header_v0(struct loc_database* db) {
        }
 
        // Copy over data
        }
 
        // Copy over data
+       db->created_at  = be64toh(header.created_at);
        db->vendor      = ntohl(header.vendor);
        db->description = ntohl(header.description);
 
        db->vendor      = ntohl(header.vendor);
        db->description = ntohl(header.description);
 
@@ -396,6 +406,7 @@ LOC_EXPORT int loc_database_write(struct loc_database* db, FILE* f) {
 
        // Make the header
        struct loc_database_header_v0 header;
 
        // Make the header
        struct loc_database_header_v0 header;
+       header.created_at  = htobe64(db->created_at);
        header.vendor      = htonl(db->vendor);
        header.description = htonl(db->description);
 
        header.vendor      = htonl(db->vendor);
        header.description = htonl(db->description);
 
index 41142abc519e786cd18d8cc2ea365bdd9d7df382..407abcb3debe54540906b0643cef8dab022a7f2a 100644 (file)
@@ -30,6 +30,7 @@ int loc_database_open(struct loc_ctx* ctx, struct loc_database** database, FILE*
 struct loc_database* loc_database_ref(struct loc_database* db);
 struct loc_database* loc_database_unref(struct loc_database* db);
 
 struct loc_database* loc_database_ref(struct loc_database* db);
 struct loc_database* loc_database_unref(struct loc_database* db);
 
+time_t loc_database_created_at(struct loc_database* db);
 const char* loc_database_get_vendor(struct loc_database* db);
 int loc_database_set_vendor(struct loc_database* db, const char* vendor);
 const char* loc_database_get_description(struct loc_database* db);
 const char* loc_database_get_vendor(struct loc_database* db);
 int loc_database_set_vendor(struct loc_database* db, const char* vendor);
 const char* loc_database_get_description(struct loc_database* db);
index 175c3fa4d85c00f676829055f673ce831902d0a9..3469290b51d0b4c50dbab943ba0843a220efe23d 100644 (file)
@@ -11,6 +11,7 @@ global:
        # Database
        loc_database_add_as;
        loc_database_count_as;
        # Database
        loc_database_add_as;
        loc_database_count_as;
+       loc_database_created_at;
        loc_database_get_description;
        loc_database_get_vendor;
        loc_database_new;
        loc_database_get_description;
        loc_database_get_vendor;
        loc_database_new;
index e6f6dbac7d14b0d8b913fd10c2550fe4c2cadc98..4a4962816e61cf34dbfff29df658066a908b7269 100644 (file)
@@ -32,6 +32,9 @@ struct loc_database_magic {
 };
 
 struct loc_database_header_v0 {
 };
 
 struct loc_database_header_v0 {
+       // UNIX timestamp when the database was created
+       uint64_t created_at;
+
        // Vendor who created the database
        uint32_t vendor;
 
        // Vendor who created the database
        uint32_t vendor;