77 lines
2 KiB
C
77 lines
2 KiB
C
#include "amduatd_store.h"
|
|
|
|
#include "amduat/asl/asl_store_fs_meta.h"
|
|
|
|
#include <string.h>
|
|
|
|
bool amduatd_store_backend_parse(const char *value,
|
|
amduatd_store_backend_t *out_backend) {
|
|
if (value == NULL || out_backend == NULL) {
|
|
return false;
|
|
}
|
|
if (strcmp(value, "fs") == 0) {
|
|
*out_backend = AMDUATD_STORE_BACKEND_FS;
|
|
return true;
|
|
}
|
|
if (strcmp(value, "index") == 0) {
|
|
*out_backend = AMDUATD_STORE_BACKEND_INDEX;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
const char *amduatd_store_backend_name(amduatd_store_backend_t backend) {
|
|
switch (backend) {
|
|
case AMDUATD_STORE_BACKEND_FS:
|
|
return "fs";
|
|
case AMDUATD_STORE_BACKEND_INDEX:
|
|
return "index";
|
|
default:
|
|
return "unknown";
|
|
}
|
|
}
|
|
|
|
bool amduatd_store_init(amduat_asl_store_t *store,
|
|
amduat_asl_store_fs_config_t *cfg,
|
|
amduatd_store_ctx_t *ctx,
|
|
const char *root_path,
|
|
amduatd_store_backend_t backend) {
|
|
if (store == NULL || cfg == NULL || ctx == NULL || root_path == NULL) {
|
|
return false;
|
|
}
|
|
|
|
memset(store, 0, sizeof(*store));
|
|
memset(ctx, 0, sizeof(*ctx));
|
|
memset(cfg, 0, sizeof(*cfg));
|
|
|
|
if (!amduat_asl_store_fs_load_config(root_path, cfg)) {
|
|
return false;
|
|
}
|
|
|
|
if (backend == AMDUATD_STORE_BACKEND_FS) {
|
|
if (!amduat_asl_store_fs_init(&ctx->fs, cfg->config, root_path)) {
|
|
return false;
|
|
}
|
|
amduat_asl_store_init(store,
|
|
cfg->config,
|
|
amduat_asl_store_fs_ops(),
|
|
&ctx->fs);
|
|
return true;
|
|
}
|
|
|
|
if (backend == AMDUATD_STORE_BACKEND_INDEX) {
|
|
if (!amduat_asl_store_index_fs_init(&ctx->index_fs,
|
|
cfg->config,
|
|
root_path)) {
|
|
return false;
|
|
}
|
|
amduat_asl_store_init(store,
|
|
cfg->config,
|
|
amduat_asl_store_index_fs_ops(),
|
|
&ctx->index_fs);
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|