2024-07-02 01:44:07 +00:00
|
|
|
#pragma once
|
2024-07-31 18:16:19 +00:00
|
|
|
#include "database.h"
|
2024-07-02 01:44:07 +00:00
|
|
|
#include "package.h"
|
2024-07-31 18:16:19 +00:00
|
|
|
|
2024-07-02 01:44:07 +00:00
|
|
|
#include <sqlite3.h>
|
2024-07-31 18:16:19 +00:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <sys/types.h>
|
2024-07-02 01:44:07 +00:00
|
|
|
|
2024-07-03 00:40:52 +00:00
|
|
|
#define HASH_LEN 32
|
|
|
|
|
2024-07-08 02:47:13 +00:00
|
|
|
enum lm_query_index {
|
2024-07-31 18:16:19 +00:00
|
|
|
QUERY_CREATE_ENTRY_TABLE = 0,
|
|
|
|
QUERY_INSERT_ENTRY_SINGLE = 1,
|
|
|
|
QUERY_SELECT_ENTRY_SINGLE_1 = 2,
|
|
|
|
QUERY_SELECT_ENTRY_SINGLE_2 = 3,
|
|
|
|
QUERY_DELETE_ENTRY_SINGLE = 4,
|
|
|
|
QUERY_SELECT_ENTRY_ALL = 5,
|
2024-08-03 20:04:27 +00:00
|
|
|
|
|
|
|
QUERY_CREATE_FILE_TABLE = 6,
|
|
|
|
QUERY_INSERT_FILE_SINGLE = 7,
|
|
|
|
QUERY_DELETE_FILE_ALL = 8,
|
|
|
|
QUERY_DELETE_FILE_SINGLE = 9,
|
|
|
|
QUERY_SELECT_FILE_ALL = 10,
|
|
|
|
QUERY_SELECT_FILE_SINGLE = 11,
|
|
|
|
QUERY_UPDATE_FILE_1 = 12,
|
|
|
|
QUERY_UPDATE_FILE_2 = 13,
|
2024-07-08 02:47:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum lm_columns {
|
2024-07-31 18:16:19 +00:00
|
|
|
FILES_COLUMN_PATH = 1,
|
|
|
|
FILES_COLUMN_HASH = 2,
|
|
|
|
FILES_COLUMN_KEEP = 3,
|
|
|
|
FILES_COLUMN_ENTRY = 4,
|
2024-07-08 02:47:13 +00:00
|
|
|
|
2024-07-31 18:16:19 +00:00
|
|
|
ENTRIES_COLUMN_NAME = 1,
|
|
|
|
ENTRIES_COLUMN_VERSION = 2,
|
|
|
|
ENTRIES_COLUMN_DESC = 3,
|
|
|
|
ENTRIES_COLUMN_SIZE = 4,
|
|
|
|
ENTRIES_COLUMN_DEPENDS = 5,
|
2024-07-08 02:47:13 +00:00
|
|
|
};
|
2024-07-02 01:44:07 +00:00
|
|
|
|
|
|
|
extern char *queries[];
|
|
|
|
|
2024-07-31 18:16:19 +00:00
|
|
|
typedef lm_pkg_data_t lm_entry_t;
|
|
|
|
|
2024-07-02 01:44:07 +00:00
|
|
|
typedef struct lm_database {
|
2024-07-31 18:16:19 +00:00
|
|
|
sqlite3 *entries_db;
|
|
|
|
sqlite3_stmt *entries_st;
|
2024-07-06 00:48:23 +00:00
|
|
|
|
|
|
|
sqlite3 *files_db;
|
|
|
|
sqlite3_stmt *files_st;
|
2024-07-02 01:44:07 +00:00
|
|
|
|
2024-07-31 18:16:19 +00:00
|
|
|
char *dir;
|
2024-07-06 00:48:23 +00:00
|
|
|
} lm_database_t;
|
2024-07-02 01:44:07 +00:00
|
|
|
|
2024-07-31 18:16:19 +00:00
|
|
|
void lm_entry_init(lm_entry_t *entry);
|
|
|
|
void lm_entry_free(lm_entry_t *entry);
|
|
|
|
|
2024-07-02 01:44:07 +00:00
|
|
|
lm_database_t *lm_database_new(char *path);
|
|
|
|
void lm_database_free(lm_database_t *db);
|
2024-07-08 02:47:13 +00:00
|
|
|
bool lm_database_step_all(sqlite3_stmt *st);
|
2024-07-02 01:44:07 +00:00
|
|
|
|
2024-07-31 18:16:19 +00:00
|
|
|
bool lm_database_entry_find(
|
|
|
|
lm_database_t *db, lm_entry_t *out, char *name, char *version); // finds a entry by its name, entry stored in *pkg
|
|
|
|
bool lm_database_entry_next(lm_database_t *db, lm_entry_t *entry); // gets the next entry in the database
|
|
|
|
bool lm_database_entry_add(lm_database_t *db, lm_entry_t *entry); // adds a entry to the database
|
|
|
|
bool lm_database_entry_del(lm_database_t *db, lm_entry_t *entry); // delete a entry from the database
|
|
|
|
void lm_database_entry_next_free(
|
|
|
|
lm_database_t *db, lm_entry_t *entry); // frees resources used for lm_database_entry_next
|
2024-07-06 00:48:23 +00:00
|
|
|
|
2024-07-31 18:16:19 +00:00
|
|
|
ssize_t lm_database_files_count(
|
|
|
|
lm_database_t *db, lm_entry_t *entry); // returns the count of files associated with a entry
|
2024-07-08 02:47:13 +00:00
|
|
|
bool lm_database_files_contains(
|
2024-07-31 18:16:19 +00:00
|
|
|
lm_database_t *db, lm_entry_t *entry, char *path); // check if a entry contains the given file
|
2024-07-06 00:48:23 +00:00
|
|
|
bool lm_database_files_matches(
|
|
|
|
lm_database_t *db, char *path, char *hash); // checks if the given file matches with the given hash
|
|
|
|
bool lm_database_files_iskeep(lm_database_t *db, char *path); // checks if the given file is marked as keep
|
|
|
|
bool lm_database_files_next(
|
2024-07-31 18:16:19 +00:00
|
|
|
lm_database_t *db, lm_entry_t *entry, char **path, char **hash, bool *keep); // gets the next file of the entry
|
2024-07-06 00:48:23 +00:00
|
|
|
bool lm_database_files_add(
|
2024-07-31 18:16:19 +00:00
|
|
|
lm_database_t *db, lm_entry_t *entry, char *path, char *hash); // adds a file to the files database
|
|
|
|
bool lm_database_files_del(lm_database_t *db, lm_entry_t *entry); // dels all files of belonging to a entry
|
2024-08-03 20:04:27 +00:00
|
|
|
bool lm_database_files_del_single(lm_database_t *db, char *path);
|
2024-07-31 18:16:19 +00:00
|
|
|
void lm_database_files_next_free(lm_database_t *db, lm_entry_t *entry, char **path, char **hash,
|
2024-07-08 02:47:13 +00:00
|
|
|
bool *keep); // frees resources used for lm_database_files_next
|
2024-07-04 22:44:42 +00:00
|
|
|
|
2024-07-31 18:16:19 +00:00
|
|
|
bool lm_database_changes_update(lm_database_t *db, lm_entry_t *entry, char *file);
|
|
|
|
char *lm_database_changes_get(lm_database_t *db, lm_entry_t *entry);
|
|
|
|
bool lm_database_changes_del(lm_database_t *db, lm_entry_t *entry);
|