return value;
}
-static const struct ec_config_schema *
+const struct ec_config_schema *
ec_config_schema_lookup(const struct ec_config_schema *schema,
- const char *key, enum ec_config_type type)
+ const char *key)
{
size_t i;
for (i = 0; schema[i].type != EC_CONFIG_TYPE_NONE; i++) {
- if (!strcmp(key, schema[i].key) &&
- type == schema[i].type)
+ if (!strcmp(key, schema[i].key))
return &schema[i];
}
key = ec_keyval_iter_get_key(iter);
value = ec_keyval_iter_get_val(iter);
- sch = ec_config_schema_lookup(schema, key, value->type);
- if (sch == NULL) {
+ sch = ec_config_schema_lookup(schema, key);
+ if (sch == NULL || sch->type != value->type) {
errno = EBADMSG;
goto fail;
}
-
if (value->type == EC_CONFIG_TYPE_LIST) {
if (ec_config_list_validate(&value->list,
sch->subschema) < 0)
*/
void ec_config_schema_dump(FILE *out, const struct ec_config_schema *schema);
+/**
+ * Find a schema entry matching the key.
+ *
+ * Browse the schema array and lookup for the given key.
+ *
+ * @param schema
+ * Pointer to the first element of the schema array. The array
+ * must be terminated by a sentinel entry (type == EC_CONFIG_TYPE_NONE).
+ * @return
+ * The schema entry if it matches a key, or NULL if not found.
+ */
+const struct ec_config_schema *
+ec_config_schema_lookup(const struct ec_config_schema *schema,
+ const char *key);
+
/**
* Check if a key name is reserved in a config dict.
*