Share ASL store-id validation
This commit is contained in:
parent
edc81beb9b
commit
2a0fd994e5
|
|
@ -27,6 +27,12 @@ bool amduat_asl_store_fs_init_root(
|
||||||
const amduat_asl_store_fs_config_t *cfg_in,
|
const amduat_asl_store_fs_config_t *cfg_in,
|
||||||
amduat_asl_store_fs_config_t *cfg_out);
|
amduat_asl_store_fs_config_t *cfg_out);
|
||||||
|
|
||||||
|
bool amduat_asl_store_fs_meta_validate_store_id(const char *store_id);
|
||||||
|
|
||||||
|
bool amduat_asl_store_fs_meta_copy_store_id(
|
||||||
|
char out_id[AMDUAT_ASL_STORE_FS_STORE_ID_MAX + 1],
|
||||||
|
const char *store_id);
|
||||||
|
|
||||||
bool amduat_asl_store_fs_load_config(
|
bool amduat_asl_store_fs_load_config(
|
||||||
const char *root_path,
|
const char *root_path,
|
||||||
amduat_asl_store_fs_config_t *out_cfg);
|
amduat_asl_store_fs_config_t *out_cfg);
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ static bool amduat_asl_store_fs_meta_is_store_id_char(char c) {
|
||||||
return c == '.' || c == '_' || c == '-';
|
return c == '.' || c == '_' || c == '-';
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool amduat_asl_store_fs_meta_validate_store_id(const char *store_id) {
|
bool amduat_asl_store_fs_meta_validate_store_id(const char *store_id) {
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
if (store_id == NULL || store_id[0] == '\0') {
|
if (store_id == NULL || store_id[0] == '\0') {
|
||||||
|
|
@ -56,7 +56,7 @@ static bool amduat_asl_store_fs_meta_validate_store_id(const char *store_id) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool amduat_asl_store_fs_meta_copy_store_id(
|
bool amduat_asl_store_fs_meta_copy_store_id(
|
||||||
char out_id[AMDUAT_ASL_STORE_FS_STORE_ID_MAX + 1],
|
char out_id[AMDUAT_ASL_STORE_FS_STORE_ID_MAX + 1],
|
||||||
const char *store_id) {
|
const char *store_id) {
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,6 @@ enum {
|
||||||
AMDUAT_ASL_CLI_EXIT_CONFIG = 8
|
AMDUAT_ASL_CLI_EXIT_CONFIG = 8
|
||||||
};
|
};
|
||||||
|
|
||||||
enum { AMDUAT_ASL_CLI_STORE_ID_MAX = AMDUAT_ASL_STORE_FS_STORE_ID_MAX };
|
|
||||||
|
|
||||||
static const char *const AMDUAT_ASL_CLI_DEFAULT_ROOT = ".amduat-asl";
|
static const char *const AMDUAT_ASL_CLI_DEFAULT_ROOT = ".amduat-asl";
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
|
@ -97,56 +95,6 @@ static void amduat_asl_cli_print_usage(FILE *stream) {
|
||||||
AMDUAT_ASL_CLI_DEFAULT_ROOT);
|
AMDUAT_ASL_CLI_DEFAULT_ROOT);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool amduat_asl_cli_is_store_id_char(char c) {
|
|
||||||
if (c >= 'a' && c <= 'z') {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (c >= 'A' && c <= 'Z') {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (c >= '0' && c <= '9') {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return c == '.' || c == '_' || c == '-';
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool amduat_asl_cli_validate_store_id(const char *store_id) {
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
if (store_id == NULL || store_id[0] == '\0') {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
for (i = 0; store_id[i] != '\0'; ++i) {
|
|
||||||
if (i >= AMDUAT_ASL_CLI_STORE_ID_MAX) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!amduat_asl_cli_is_store_id_char(store_id[i])) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool amduat_asl_cli_copy_store_id(
|
|
||||||
char out_id[AMDUAT_ASL_CLI_STORE_ID_MAX + 1],
|
|
||||||
const char *store_id) {
|
|
||||||
size_t len;
|
|
||||||
|
|
||||||
if (out_id == NULL || store_id == NULL) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!amduat_asl_cli_validate_store_id(store_id)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
len = strlen(store_id);
|
|
||||||
if (len > AMDUAT_ASL_CLI_STORE_ID_MAX) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
memcpy(out_id, store_id, len);
|
|
||||||
out_id[len] = '\0';
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool amduat_asl_cli_parse_ref_format(
|
static bool amduat_asl_cli_parse_ref_format(
|
||||||
const char *text,
|
const char *text,
|
||||||
amduat_asl_cli_ref_format_t *out_fmt) {
|
amduat_asl_cli_ref_format_t *out_fmt) {
|
||||||
|
|
@ -290,7 +238,8 @@ static int amduat_asl_cli_cmd_init(int argc, char **argv) {
|
||||||
|
|
||||||
memset(&cfg_in, 0, sizeof(cfg_in));
|
memset(&cfg_in, 0, sizeof(cfg_in));
|
||||||
if (opts.store_id != NULL) {
|
if (opts.store_id != NULL) {
|
||||||
if (!amduat_asl_cli_copy_store_id(cfg_in.store_id, opts.store_id)) {
|
if (!amduat_asl_store_fs_meta_copy_store_id(cfg_in.store_id,
|
||||||
|
opts.store_id)) {
|
||||||
fprintf(stderr, "error: invalid store-id\n");
|
fprintf(stderr, "error: invalid store-id\n");
|
||||||
return AMDUAT_ASL_CLI_EXIT_USAGE;
|
return AMDUAT_ASL_CLI_EXIT_USAGE;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue