new: first database functions
This commit is contained in:
@ -1,8 +1,9 @@
|
||||
#pragma once
|
||||
#include "database.h"
|
||||
#include "types.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef void (*lm_ctx_pool_callback_t)(lm_ctx_t *ctx, lm_pool_t *pool, bool status, void *data);
|
||||
typedef bool (*lm_ctx_pool_callback_t)(lm_ctx_t *ctx, lm_pool_t *pool, bool status, void *data);
|
||||
|
||||
void lm_ctx_init(lm_ctx_t *ctx);
|
||||
bool lm_ctx_set_data(lm_ctx_t *ctx, char *dir);
|
||||
@ -22,3 +23,6 @@ void lm_ctx_pool_get_list(
|
||||
|
||||
lm_pkg_t *lm_ctx_package_install(lm_ctx_t *ctx, char *name, char *version);
|
||||
lm_pkg_t *lm_ctx_package_get(lm_ctx_t *ctx, char *name, char *version);
|
||||
bool lm_ctx_package_verify(lm_ctx_t *ctx, char *name, char *version);
|
||||
|
||||
lm_database_t *lm_ctx_database_new(lm_ctx_t *ctx);
|
||||
|
36
include/database.h
Normal file
36
include/database.h
Normal file
@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
#include "package.h"
|
||||
#include <sqlite3.h>
|
||||
|
||||
typedef enum lm_query_index {
|
||||
QUERY_CREATE_TABLE = 0,
|
||||
QUERY_INSERT_PACKAGE = 1,
|
||||
} lm_query_index_t;
|
||||
|
||||
extern char *queries[];
|
||||
|
||||
typedef struct lm_database {
|
||||
lm_pkg_t *pkg;
|
||||
char *path;
|
||||
sqlite3 *sql;
|
||||
} lm_database_t;
|
||||
|
||||
typedef bool (*lm_database_files_eachfunc_t)(lm_pkg_t *pkg, char *path, char *hash, void *data);
|
||||
typedef bool (*lm_database_keeps_eachfunc_t)(lm_pkg_t *pkg, char *path, void *data);
|
||||
|
||||
lm_database_t *lm_database_new(char *path);
|
||||
void lm_database_free(lm_database_t *db);
|
||||
|
||||
bool lm_database_add(lm_database_t *db, lm_pkg_t *pkg);
|
||||
bool lm_database_del(lm_database_t *db, lm_pkg_t *pkg);
|
||||
bool lm_database_find(lm_database_t *db, lm_pkg_t *pkg);
|
||||
|
||||
bool lm_database_files_del(lm_database_t *db, lm_pkg_t *pkg);
|
||||
bool lm_database_files_add(lm_database_t *db, lm_pkg_t *pkg, char *path, char *hash);
|
||||
bool lm_database_files_get(lm_database_t *db, lm_pkg_t *pkg, char *path, char *hash);
|
||||
bool lm_database_files_foreach(lm_database_t *db, lm_pkg_t *pkg, lm_database_files_eachfunc_t func);
|
||||
|
||||
bool lm_database_keeps_del(lm_database_t *db, lm_pkg_t *pkg);
|
||||
bool lm_database_keeps_add(lm_database_t *db, lm_pkg_t *pkg, char *path);
|
||||
bool lm_database_keeps_contains(lm_database_t *db, lm_pkg_t *pkg, char *path);
|
||||
bool lm_database_keeps_foreach(lm_database_t *db, lm_pkg_t *pkg, lm_database_keeps_eachfunc_t func);
|
@ -59,13 +59,28 @@ typedef enum lm_error {
|
||||
LM_ERR_CtxDataFailMkdir = 54,
|
||||
LM_ERR_ArcRealpathFail = 55,
|
||||
LM_ERR_PoolTestNotPong = 56,
|
||||
LM_ERR_PackagePathsEmpty = 57,
|
||||
LM_ERR_PkgPathsEmpty = 57,
|
||||
LM_ERR_SendOpenFail = 58,
|
||||
LM_ERR_RecvDelFail = 59,
|
||||
LM_ERR_RecvOpenFail = 60,
|
||||
LM_ERR_RecvBadCode = 61,
|
||||
LM_ERR_RecvWriteFail = 62,
|
||||
LM_ERR_PkgNotFound = 63
|
||||
LM_ERR_PkgNotFound = 63,
|
||||
LM_ERR_DbCantAccess = 64,
|
||||
LM_ERR_DbSqlOpenFail = 65,
|
||||
LM_ERR_DbSqlCreateFail = 66,
|
||||
LM_ERR_DbSqlPrepareFail = 67,
|
||||
LM_ERR_DbSqlInsertFail = 68,
|
||||
LM_ERR_PkgGPGFail = 69,
|
||||
LM_ERR_PkgGPGSigFail = 70,
|
||||
LM_ERR_PkgGPGArchiveFail = 71,
|
||||
LM_ERR_PkgSigNoMatch = 72,
|
||||
LM_ERR_PkgSigNoResult = 73,
|
||||
LM_ERR_PoolPathsEmpty = 74,
|
||||
LM_ERR_PoolNotAvailable = 75,
|
||||
LM_ERR_PoolUrlEmpty = 76,
|
||||
LM_ERR_PoolBadDir = 77,
|
||||
LM_ERR_PoolBadPaths = 78,
|
||||
} lm_error_t;
|
||||
|
||||
typedef struct lm_error_desc {
|
||||
|
@ -9,12 +9,19 @@
|
||||
|
||||
lm_pkg_t *lm_package_new();
|
||||
void lm_package_free(lm_pkg_t *pkg);
|
||||
bool lm_package_verify(lm_pkg_t *pkg);
|
||||
|
||||
bool lm_package_data_load(lm_pkg_t *pkg, char *file);
|
||||
void lm_package_data_free(lm_pkg_t *pkg);
|
||||
|
||||
bool lm_package_depend_add(lm_pkg_t *pkg, char *depend);
|
||||
size_t lm_package_depend_count(lm_pkg_t *pkg);
|
||||
size_t lm_package_depend_strlen(lm_pkg_t *pkg);
|
||||
bool lm_package_depend_tostr(lm_pkg_t *pkg, char *buffer);
|
||||
|
||||
size_t lm_package_keep_count(lm_pkg_t *pkg);
|
||||
bool lm_package_keep_add(lm_pkg_t *pkg, char *path);
|
||||
bool lm_package_keep_contains(lm_pkg_t *pkg, char *path);
|
||||
|
||||
bool lm_package_path_set_signature(lm_pkg_t *pkg, char *signature_path);
|
||||
bool lm_package_path_set_archive(lm_pkg_t *pkg, char *archive_path);
|
||||
|
@ -24,9 +24,7 @@ lm_pkg_t *lm_pool_package_find(lm_pool_t *pool, char *name, char *version);
|
||||
bool lm_pool_package_add(lm_pool_t *pool, lm_pkg_t *pkg);
|
||||
bool lm_pool_package_get(lm_pool_t *pool, lm_pkg_t *pkg);
|
||||
|
||||
bool lm_pool_path_set_info(lm_pool_t *pool, char *info_path);
|
||||
bool lm_pool_path_set_list(lm_pool_t *pool, char *list_path);
|
||||
bool lm_pool_path_set_packages(lm_pool_t *pool, char *packaes_path);
|
||||
bool lm_pool_path_set_dir(lm_pool_t *pool, char *dir);
|
||||
bool lm_pool_path_is_empty(lm_pool_t *pool);
|
||||
void lm_pool_path_free(lm_pool_t *pool);
|
||||
|
||||
@ -36,6 +34,7 @@ void lm_pool_info_free(lm_pool_t *pool);
|
||||
|
||||
bool lm_pool_list_load(lm_pool_t *pool);
|
||||
bool lm_pool_list_get(lm_pool_t *pool);
|
||||
void lm_pool_list_free(lm_pool_t *pool);
|
||||
|
||||
void lm_pool_serve(lm_pool_t *pool, lm_mptp_t *packet, int sock, struct sockaddr *addr);
|
||||
void lm_pool_serve_thread(void *arg);
|
||||
|
@ -5,6 +5,11 @@
|
||||
#include <stddef.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
typedef struct lm_pkg_file {
|
||||
char *path;
|
||||
char *hash;
|
||||
} lm_pkg_file_t;
|
||||
|
||||
typedef struct lm_pkg_path {
|
||||
char *archive;
|
||||
char *signature;
|
||||
@ -16,6 +21,7 @@ typedef struct lm_pkg {
|
||||
char *name;
|
||||
char *desc;
|
||||
char **depends;
|
||||
char **keeps;
|
||||
char *version;
|
||||
size_t size;
|
||||
} lm_pkg_t;
|
||||
@ -27,9 +33,10 @@ typedef struct lm_pool_info {
|
||||
} lm_pool_info_t;
|
||||
|
||||
typedef struct lm_pool_path {
|
||||
char *packages;
|
||||
char *list;
|
||||
char *info;
|
||||
char *info_file;
|
||||
char *list_file;
|
||||
char *list_dir;
|
||||
char *dir;
|
||||
} lm_pool_path_t;
|
||||
|
||||
typedef struct lm_pool {
|
||||
|
Reference in New Issue
Block a user