Skip to content

Commit

Permalink
Load: Call client value validation callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
tlsa committed May 30, 2023
1 parent 407589f commit ff891b0
Showing 1 changed file with 53 additions and 1 deletion.
54 changes: 53 additions & 1 deletion src/load.c
Original file line number Diff line number Diff line change
Expand Up @@ -1737,6 +1737,14 @@ static cyaml_err_t cyaml__read_int(
if (err != CYAML_OK) {
return err;
}

if (schema->integer.validation_cb != NULL) {
if (!schema->integer.validation_cb(
ctx->config->validation_ctx,
schema, temp)) {
return CYAML_ERR_INVALID_VALUE;
}
}
}

return cyaml__store_int(ctx, schema, (int64_t)temp, data);
Expand Down Expand Up @@ -1833,6 +1841,14 @@ static cyaml_err_t cyaml__read_uint(
if (err != CYAML_OK) {
return err;
}

if (schema->unsigned_integer.validation_cb != NULL) {
if (!schema->unsigned_integer.validation_cb(
ctx->config->validation_ctx,
schema, temp)) {
return CYAML_ERR_INVALID_VALUE;
}
}
}

return cyaml__store_uint(ctx, schema, temp, data);
Expand Down Expand Up @@ -1966,6 +1982,14 @@ static cyaml_err_t cyaml__read_float(
}
}

if (schema->floating_point.validation_cb != NULL) {
if (!schema->floating_point.validation_cb(
ctx->config->validation_ctx,
schema, temp)) {
return CYAML_ERR_INVALID_VALUE;
}
}

return cyaml__store_float(ctx, schema, temp, data);
}

Expand All @@ -1984,6 +2008,14 @@ static cyaml_err_t cyaml__read_string(
const char *value,
uint8_t *data)
{
if (schema->string.validation_cb != NULL) {
if (!schema->string.validation_cb(
ctx->config->validation_ctx,
schema, value)) {
return CYAML_ERR_INVALID_VALUE;
}
}

return cyaml__store_string(ctx, schema, value, data);
}

Expand Down Expand Up @@ -2650,6 +2682,8 @@ static cyaml_err_t cyaml__map_end(
const yaml_event_t *event)
{
cyaml_err_t err;
const cyaml_state_t *state = ctx->state;
const cyaml_schema_value_t *schema = state->schema;

CYAML_UNUSED(event);

Expand All @@ -2658,6 +2692,14 @@ static cyaml_err_t cyaml__map_end(
return err;
}

if (schema->mapping.validation_cb != NULL) {
if (!schema->mapping.validation_cb(
ctx->config->validation_ctx,
schema, state->data)) {
return CYAML_ERR_INVALID_VALUE;
}
}

cyaml__stack_pop(ctx);
return CYAML_OK;
}
Expand Down Expand Up @@ -2766,7 +2808,8 @@ static cyaml_err_t cyaml__seq_end(
cyaml_ctx_t *ctx,
const yaml_event_t *event)
{
cyaml_state_t *state = ctx->state;
const cyaml_state_t *state = ctx->state;
const cyaml_schema_value_t *schema = state->schema;

CYAML_UNUSED(event);

Expand All @@ -2778,6 +2821,15 @@ static cyaml_err_t cyaml__seq_end(
state->schema->sequence.min);
return CYAML_ERR_SEQUENCE_ENTRIES_MIN;
}

if (schema->sequence.validation_cb != NULL) {
if (!schema->sequence.validation_cb(
ctx->config->validation_ctx,
schema, state->data, state->sequence.count)) {
return CYAML_ERR_INVALID_VALUE;
}
}

cyaml__log(ctx->config, CYAML_LOG_DEBUG, "Load: Sequence count: %u\n",
state->sequence.count);

Expand Down

0 comments on commit ff891b0

Please sign in to comment.