From d513977a3566b14d9357906615d045d71741537f Mon Sep 17 00:00:00 2001 From: Thorsten Töpper Date: Wed, 18 Feb 2026 21:51:53 +0100 Subject: squash initial implementation --- include/database_interaction.h | 34 ++++++++++++++++++++++++++++++++++ include/directory_scanner.h | 15 +++++++++++++++ include/file_processor.h | 15 +++++++++++++++ include/kv_manager.h | 25 +++++++++++++++++++++++++ include/options.h | 31 +++++++++++++++++++++++++++++++ 5 files changed, 120 insertions(+) create mode 100644 include/database_interaction.h create mode 100644 include/directory_scanner.h create mode 100644 include/kv_manager.h create mode 100644 include/options.h (limited to 'include') diff --git a/include/database_interaction.h b/include/database_interaction.h new file mode 100644 index 0000000..9ae0da7 --- /dev/null +++ b/include/database_interaction.h @@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: Apache-2.0 */ + +/* Copyright 2026 Thorsten Töpper + * + * vim:ts=4:sw=4:expandtab + */ +#ifndef DATABASE_INTERACTION_H +#define DATABASE_INTERACTION_H + +#include "file_processor.h" + +/*=========== FUNCTIONS ===========*/ +bool dbi_open(char *filename); +void dbi_close(); + +char *dbi_select_filename_by_id(int64_t id); +int64_t dbi_select_filename_by_name(const char *name); +int dbi_insert_filename(const char *filename); + +char *dbi_select_path_by_id(int64_t id); +int64_t dbi_select_path_by_pathname(const char *pathname); +int dbi_insert_pathname(const char *path); + +struct df_hashstrings *dbi_select_hashes_by_id(int64_t id); +int64_t dbi_select_hashes_by_strings(const char *blake2, const char *sha256, const char *sha512); +int dbi_insert_hashes(const char *blake2, const char *sha256, const char *sha512); + +int64_t dbi_select_fileinfo_by_hash_path_filename_ids(int64_t hash_id, int64_t path_id, int64_t filename_id); +int64_t dbi_select_fileinfo_by_path_filename_ids(int64_t pname_id, int64_t fname_id); +int dbi_insert_fileinfo(struct df_fileinfo *fi); + +int dbi_update_fileinfo_last_seen(int64_t id); +int dbi_update_fileinfo_complete(struct df_fileinfo *fi, int64_t existing_id); +#endif diff --git a/include/directory_scanner.h b/include/directory_scanner.h new file mode 100644 index 0000000..7b2e7d2 --- /dev/null +++ b/include/directory_scanner.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: Apache-2.0 */ + +/* Copyright 2026 Thorsten Töpper + * + * vim:ts=4:sw=4:expandtab + */ +#ifndef DIRECTORY_SCANNER_H +#define DIRECTORY_SCANNER_H + +/*=========== FUNCTIONS ===========*/ +int process_directory(char *path); +int traverse_directory_tree(const char *starting_point); + +#endif + diff --git a/include/file_processor.h b/include/file_processor.h index 8cfb6de..cdb30bb 100644 --- a/include/file_processor.h +++ b/include/file_processor.h @@ -11,6 +11,8 @@ #define DF_BYTE_SIZE_256 32 #define DF_BYTE_SIZE_512 64 +#define DF_STR_SIZE_256 64 +#define DF_STR_SIZE_512 128 /* Aliases for convenience, currently all algorithms are part of the default * provider. */ @@ -18,6 +20,15 @@ #define DF_OSSL_SHA256 "SHA2-256" #define DF_OSSL_SHA512 "SHA2-512" +/** + * The hashes in human-readable strings + */ +struct df_hashstrings { + char blake2[DF_STR_SIZE_512]; + char sha256[DF_STR_SIZE_256]; + char sha512[DF_STR_SIZE_512]; +}; + /** * information about a file * Contains filepath, stat() results, hash values of multiple algorithms. @@ -27,15 +38,19 @@ struct df_fileinfo { char *path; /**< pointer to the path of the file */ char *name; /**< pointer to the name of the file */ +#if 0 unsigned char blake2[DF_BYTE_SIZE_512]; /**< The BLAKE2-512 hash in binary form */ unsigned char sha256[DF_BYTE_SIZE_256]; /**< The SHA256 hash in binary form. */ unsigned char sha512[DF_BYTE_SIZE_512]; /**< The SHA512 hash in binary form. */ +#endif + struct df_hashstrings hashes; /**< The BLAKE2-512, SHA256 and SHA512 hash of the file */ struct stat statbuf; /**< Result of lstat() call. Symlinks are to be ignored and filtered out earlier. */ }; /*=========== FUNCTIONS ===========*/ int process_file(struct df_fileinfo *info); +int process_gdbm_content(); #endif diff --git a/include/kv_manager.h b/include/kv_manager.h new file mode 100644 index 0000000..068841b --- /dev/null +++ b/include/kv_manager.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: Apache-2.0 */ + +/* Copyright 2026 Thorsten Töpper + * + * vim:ts=4:sw=4:expandtab + */ +#ifndef KV_MANAGER_H +#define KV_MANAGER_H + +/*=========== FUNCTIONS ===========*/ +int kv_open_storage(char *fname); +bool kv_close_storage(); +bool kv_add_bool_type(char *key, bool value, char type); +bool kv_set_bool(char *key, bool value); +bool kv_get_bool(char *key); +char kv_get_type(char *key); +char *kv_get_raw(char *key); +bool kv_entry_exists(char *key); +char *kv_first_key(); +char *kv_next_key(char *key); + +void kv_dump(FILE *out); + +#endif + diff --git a/include/options.h b/include/options.h new file mode 100644 index 0000000..5a7747e --- /dev/null +++ b/include/options.h @@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: Apache-2.0 */ + +/* Copyright 2026 Thorsten Töpper + * + * vim:ts=4:sw=4:expandtab + */ + +#ifndef OPTIONS_H +#define OPTIONS_H + +#include + +/* === DEFINITIONS === */ +/* TODO: if ported to other platforms, those precompiler checks need to be extended */ +#ifndef PATH_SEP +#define PATH_SEP '/' +#endif + + +/* === GLOBAL VARIABLES === */ + +extern bool option_quiet; +extern bool option_show_hidden_entries; + + +int parse_arguments(int argc, char **argv); +void set_option(const char *option_name, char *option_argument); +void usage(char *executable); + +#endif + -- cgit v1.3