libyang CHANGE bind errors and store them in a context
diff --git a/src/parser_yang.c b/src/parser_yang.c
index b67234b..7abb85d 100644
--- a/src/parser_yang.c
+++ b/src/parser_yang.c
@@ -36,7 +36,7 @@
char *where, char *value, struct lys_node *node)
{
if (*target) {
- LOGVAL(LYE_TOOMANY, (node) ? LY_VLOG_LYS : LY_VLOG_NONE, node, what, where);
+ LOGVAL(module->ctx, LYE_TOOMANY, (node) ? LY_VLOG_LYS : LY_VLOG_NONE, node, what, where);
free(value);
return 1;
} else {
@@ -65,7 +65,7 @@
break;
default:
free(value);
- LOGINT;
+ LOGINT(module->ctx);
ret = EXIT_FAILURE;
break;
}
@@ -79,13 +79,13 @@
int ret = EXIT_SUCCESS;
if (repeat) {
- LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, "yang version", "module");
+ LOGVAL(module->ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, "yang version", "module");
ret = EXIT_FAILURE;
} else {
if (!strcmp(value, "1")) {
if (submodule) {
if (module->version > 1) {
- LOGVAL(LYE_INVER, LY_VLOG_NONE, NULL);
+ LOGVAL(module->ctx, LYE_INVER, LY_VLOG_NONE, NULL);
ret = EXIT_FAILURE;
}
submodule->version = 1;
@@ -95,7 +95,7 @@
} else if (!strcmp(value, "1.1")) {
if (submodule) {
if (module->version != 2) {
- LOGVAL(LYE_INVER, LY_VLOG_NONE, NULL);
+ LOGVAL(module->ctx, LYE_INVER, LY_VLOG_NONE, NULL);
ret = EXIT_FAILURE;
}
submodule->version = 2;
@@ -103,7 +103,7 @@
module->version = 2;
}
} else {
- LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "yang-version");
+ LOGVAL(module->ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, "yang-version");
ret = EXIT_FAILURE;
}
}
@@ -116,7 +116,7 @@
{
int ret = 0;
- if (!imp && lyp_check_identifier(value, LY_IDENT_PREFIX, module, NULL)) {
+ if (!imp && lyp_check_identifier(module->ctx, value, LY_IDENT_PREFIX, module, NULL)) {
free(value);
return EXIT_FAILURE;
}
@@ -138,10 +138,10 @@
int rc;
if (!imp_old->prefix) {
- LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "prefix", "import");
+ LOGVAL(module->ctx, LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "prefix", "import");
goto error;
} else {
- if (lyp_check_identifier(imp_old->prefix, LY_IDENT_PREFIX, module, NULL)) {
+ if (lyp_check_identifier(module->ctx, imp_old->prefix, LY_IDENT_PREFIX, module, NULL)) {
goto error;
}
}
@@ -230,7 +230,7 @@
int ret;
if ((module->version != 2) && ((value[0] == '(') || strchr(value, ' '))) {
- LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "if-feature");
+ LOGVAL(module->ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, "if-feature");
free(value);
return EXIT_FAILURE;
}
@@ -284,7 +284,7 @@
yang_read_presence(struct lys_module *module, struct lys_node_container *cont, char *value)
{
if (cont->presence) {
- LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, cont, "presence", "container");
+ LOGVAL(module->ctx, LYE_TOOMANY, LY_VLOG_LYS, cont, "presence", "container");
free(value);
return EXIT_FAILURE;
} else {
@@ -299,7 +299,7 @@
struct lys_when *retval;
retval = calloc(1, sizeof *retval);
- LY_CHECK_ERR_RETURN(!retval, LOGMEM; free(value), NULL);
+ LY_CHECK_ERR_RETURN(!retval, LOGMEM(module->ctx); free(value), NULL);
retval->cond = transform_schema2json(module, value);
if (!retval->cond) {
goto error;
@@ -307,7 +307,7 @@
switch (type) {
case CONTAINER_KEYWORD:
if (((struct lys_node_container *)node)->when) {
- LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, node, "when", "container");
+ LOGVAL(module->ctx, LYE_TOOMANY, LY_VLOG_LYS, node, "when", "container");
goto error;
}
((struct lys_node_container *)node)->when = retval;
@@ -315,56 +315,56 @@
case ANYDATA_KEYWORD:
case ANYXML_KEYWORD:
if (((struct lys_node_anydata *)node)->when) {
- LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, node, "when", (type == ANYXML_KEYWORD) ? "anyxml" : "anydata");
+ LOGVAL(module->ctx, LYE_TOOMANY, LY_VLOG_LYS, node, "when", (type == ANYXML_KEYWORD) ? "anyxml" : "anydata");
goto error;
}
((struct lys_node_anydata *)node)->when = retval;
break;
case CHOICE_KEYWORD:
if (((struct lys_node_choice *)node)->when) {
- LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, node, "when", "choice");
+ LOGVAL(module->ctx, LYE_TOOMANY, LY_VLOG_LYS, node, "when", "choice");
goto error;
}
((struct lys_node_choice *)node)->when = retval;
break;
case CASE_KEYWORD:
if (((struct lys_node_case *)node)->when) {
- LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, node, "when", "case");
+ LOGVAL(module->ctx, LYE_TOOMANY, LY_VLOG_LYS, node, "when", "case");
goto error;
}
((struct lys_node_case *)node)->when = retval;
break;
case LEAF_KEYWORD:
if (((struct lys_node_leaf *)node)->when) {
- LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, node, "when", "leaf");
+ LOGVAL(module->ctx, LYE_TOOMANY, LY_VLOG_LYS, node, "when", "leaf");
goto error;
}
((struct lys_node_leaf *)node)->when = retval;
break;
case LEAF_LIST_KEYWORD:
if (((struct lys_node_leaflist *)node)->when) {
- LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, node, "when", "leaflist");
+ LOGVAL(module->ctx, LYE_TOOMANY, LY_VLOG_LYS, node, "when", "leaflist");
goto error;
}
((struct lys_node_leaflist *)node)->when = retval;
break;
case LIST_KEYWORD:
if (((struct lys_node_list *)node)->when) {
- LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, node, "when", "list");
+ LOGVAL(module->ctx, LYE_TOOMANY, LY_VLOG_LYS, node, "when", "list");
goto error;
}
((struct lys_node_list *)node)->when = retval;
break;
case USES_KEYWORD:
if (((struct lys_node_uses *)node)->when) {
- LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, node, "when", "uses");
+ LOGVAL(module->ctx, LYE_TOOMANY, LY_VLOG_LYS, node, "when", "uses");
goto error;
}
((struct lys_node_uses *)node)->when = retval;
break;
case AUGMENT_KEYWORD:
if (((struct lys_node_augment *)node)->when) {
- LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, node, "when", "augment");
+ LOGVAL(module->ctx, LYE_TOOMANY, LY_VLOG_LYS, node, "when", "augment");
goto error;
}
((struct lys_node_augment *)node)->when = retval;
@@ -393,7 +393,7 @@
struct lys_node *node, **child;
node = calloc(1, sizeof_struct);
- LY_CHECK_ERR_RETURN(!node, LOGMEM; free(value), NULL);
+ LY_CHECK_ERR_RETURN(!node, LOGMEM(module->ctx); free(value), NULL);
LOGDBG(LY_LDGYANG, "parsing %s statement \"%s\"", strnodetype(nodetype), value);
node->name = lydict_insert_zc(module->ctx, value);
@@ -427,7 +427,7 @@
break;
default:
free(value);
- LOGINT;
+ LOGINT(module->ctx);
ret = EXIT_FAILURE;
break;
}
@@ -456,7 +456,7 @@
break;
default:
free(value);
- LOGINT;
+ LOGINT(module->ctx);
ret = EXIT_FAILURE;
break;
}
@@ -480,7 +480,7 @@
list->keys_str = lydict_insert_zc(module->ctx, exp);
list->keys = calloc(list->keys_size, sizeof *list->keys);
- LY_CHECK_ERR_RETURN(!list->keys, LOGMEM, EXIT_FAILURE);
+ LY_CHECK_ERR_RETURN(!list->keys, LOGMEM(module->ctx), EXIT_FAILURE);
for (node = list->parent; node && node->nodetype != LYS_GROUPING; node = lys_parent(node));
if (!node && unres_schema_add_node(module, unres, list, UNRES_LIST_KEYS, NULL) == -1) {
@@ -506,7 +506,7 @@
}
unique->expr_size++;
unique->expr = calloc(unique->expr_size, sizeof *unique->expr);
- LY_CHECK_ERR_GOTO(!unique->expr, LOGMEM, error);
+ LY_CHECK_ERR_GOTO(!unique->expr, LOGMEM(module->ctx), error);
for (i = 0; i < unique->expr_size; i++) {
vaux = strpbrk(value, " \t\n");
@@ -524,15 +524,15 @@
/* check that the expression does not repeat */
for (j = 0; j < i; j++) {
if (ly_strequal(unique->expr[j], unique->expr[i], 1)) {
- LOGVAL(LYE_INARG, LY_VLOG_LYS, list, unique->expr[i], "unique");
- LOGVAL(LYE_SPEC, LY_VLOG_LYS, list, "The identifier is not unique");
+ LOGVAL(module->ctx, LYE_INARG, LY_VLOG_LYS, list, unique->expr[i], "unique");
+ LOGVAL(module->ctx, LYE_SPEC, LY_VLOG_LYS, list, "The identifier is not unique");
goto error;
}
}
/* try to resolve leaf */
if (unres) {
unique_info = malloc(sizeof *unique_info);
- LY_CHECK_ERR_GOTO(!unique_info, LOGMEM, error);
+ LY_CHECK_ERR_GOTO(!unique_info, LOGMEM(module->ctx), error);
unique_info->list = (struct lys_node *)list;
unique_info->expr = unique->expr[i];
unique_info->trg_type = &unique->trg_type;
@@ -582,11 +582,11 @@
yang_read_leafref_path(struct lys_module *module, struct yang_type *stype, char *value)
{
if (stype->base && (stype->base != LY_TYPE_LEAFREF)) {
- LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "require-instance");
+ LOGVAL(module->ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "require-instance");
goto error;
}
if (stype->type->info.lref.path) {
- LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, "path", "type");
+ LOGVAL(module->ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, "path", "type");
goto error;
}
stype->type->info.lref.path = lydict_insert_zc(module->ctx, value);
@@ -599,14 +599,14 @@
}
int
-yang_read_require_instance(struct yang_type *stype, int req)
+yang_read_require_instance(struct ly_ctx *ctx, struct yang_type *stype, int req)
{
if (stype->base && (stype->base != LY_TYPE_LEAFREF)) {
- LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "require-instance");
+ LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "require-instance");
return EXIT_FAILURE;
}
if (stype->type->info.lref.req) {
- LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, "require-instance", "type");
+ LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, "require-instance", "type");
return EXIT_FAILURE;
}
stype->type->info.lref.req = req;
@@ -617,6 +617,7 @@
int
yang_check_type(struct lys_module *module, struct lys_node *parent, struct yang_type *typ, struct lys_type *type, int tpdftype, struct unres_schema *unres)
{
+ struct ly_ctx *ctx = module->ctx;
int rc, ret = -1;
unsigned int i, j;
int8_t req;
@@ -636,19 +637,19 @@
i = parse_identifier(value);
if (i < 1) {
- LOGVAL(LYE_INCHAR, LY_VLOG_NONE, NULL, value[-i], &value[-i]);
- lydict_remove(module->ctx, value);
+ LOGVAL(ctx, LYE_INCHAR, LY_VLOG_NONE, NULL, value[-i], &value[-i]);
+ lydict_remove(ctx, value);
goto error;
}
/* module name */
name = value;
if (value[i]) {
- module_name = lydict_insert(module->ctx, value, i);
+ module_name = lydict_insert(ctx, value, i);
name += i;
if ((name[0] != ':') || (parse_identifier(name + 1) < 1)) {
- LOGVAL(LYE_INCHAR, LY_VLOG_NONE, NULL, name[0], name);
- lydict_remove(module->ctx, module_name);
- lydict_remove(module->ctx, value);
+ LOGVAL(ctx, LYE_INCHAR, LY_VLOG_NONE, NULL, name[0], name);
+ lydict_remove(ctx, module_name);
+ lydict_remove(ctx, value);
goto error;
}
++name;
@@ -656,21 +657,21 @@
rc = resolve_superior_type(name, module_name, module, parent, &type->der);
if (rc == -1) {
- LOGVAL(LYE_INMOD, LY_VLOG_NONE, NULL, module_name);
- lydict_remove(module->ctx, module_name);
- lydict_remove(module->ctx, value);
+ LOGVAL(ctx, LYE_INMOD, LY_VLOG_NONE, NULL, module_name);
+ lydict_remove(ctx, module_name);
+ lydict_remove(ctx, value);
goto error;
/* the type could not be resolved or it was resolved to an unresolved typedef or leafref */
} else if (rc == EXIT_FAILURE) {
- LOGVAL(LYE_NORESOLV, LY_VLOG_NONE, NULL, "type", name);
- lydict_remove(module->ctx, module_name);
- lydict_remove(module->ctx, value);
+ LOGVAL(ctx, LYE_NORESOLV, LY_VLOG_NONE, NULL, "type", name);
+ lydict_remove(ctx, module_name);
+ lydict_remove(ctx, value);
ret = EXIT_FAILURE;
goto error;
}
- lydict_remove(module->ctx, module_name);
- lydict_remove(module->ctx, value);
+ lydict_remove(ctx, module_name);
+ lydict_remove(ctx, value);
if (type->base == LY_TYPE_ERR) {
/* resolved type in grouping, decrease the grouping's nacm number to indicate that one less
@@ -680,7 +681,7 @@
assert(((struct lys_node_grp *)siter)->unres_count);
((struct lys_node_grp *)siter)->unres_count--;
} else {
- LOGINT;
+ LOGINT(ctx);
goto error;
}
}
@@ -701,21 +702,21 @@
case LY_TYPE_STRING:
if (type->base == LY_TYPE_BINARY) {
if (type->info.str.pat_count) {
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Binary type could not include pattern statement.");
+ LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Binary type could not include pattern statement.");
goto error;
}
type->info.binary.length = type->info.str.length;
- if (type->info.binary.length && lyp_check_length_range(type->info.binary.length->expr, type)) {
- LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, type->info.binary.length->expr, "length");
+ if (type->info.binary.length && lyp_check_length_range(ctx, type->info.binary.length->expr, type)) {
+ LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, type->info.binary.length->expr, "length");
goto error;
}
} else if (type->base == LY_TYPE_STRING) {
- if (type->info.str.length && lyp_check_length_range(type->info.str.length->expr, type)) {
- LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, type->info.str.length->expr, "length");
+ if (type->info.str.length && lyp_check_length_range(ctx, type->info.str.length->expr, type)) {
+ LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, type->info.str.length->expr, "length");
goto error;
}
} else {
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Invalid restriction in type \"%s\".", type->parent->name);
+ LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Invalid restriction in type \"%s\".", type->parent->name);
goto error;
}
break;
@@ -724,12 +725,12 @@
/* mandatory sub-statement(s) check */
if (!type->info.dec64.dig && !type->der->type.der) {
/* decimal64 type directly derived from built-in type requires fraction-digits */
- LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "fraction-digits", "type");
+ LOGVAL(ctx, LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "fraction-digits", "type");
goto error;
}
if (type->info.dec64.dig && type->der->type.der) {
/* type is not directly derived from buit-in type and fraction-digits statement is prohibited */
- LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "fraction-digits");
+ LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "fraction-digits");
goto error;
}
@@ -738,28 +739,28 @@
type->info.dec64.dig = type->der->type.info.dec64.dig;
type->info.dec64.div = type->der->type.info.dec64.div;
}
- if (type->info.dec64.range && lyp_check_length_range(type->info.dec64.range->expr, type)) {
- LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, type->info.dec64.range->expr, "range");
+ if (type->info.dec64.range && lyp_check_length_range(ctx, type->info.dec64.range->expr, type)) {
+ LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, type->info.dec64.range->expr, "range");
goto error;
}
} else if (type->base >= LY_TYPE_INT8 && type->base <=LY_TYPE_UINT64) {
if (type->info.dec64.dig) {
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Numerical type could not include fraction statement.");
+ LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Numerical type could not include fraction statement.");
goto error;
}
type->info.num.range = type->info.dec64.range;
- if (type->info.num.range && lyp_check_length_range(type->info.num.range->expr, type)) {
- LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, type->info.num.range->expr, "range");
+ if (type->info.num.range && lyp_check_length_range(ctx, type->info.num.range->expr, type)) {
+ LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, type->info.num.range->expr, "range");
goto error;
}
} else {
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Invalid restriction in type \"%s\".", type->parent->name);
+ LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Invalid restriction in type \"%s\".", type->parent->name);
goto error;
}
break;
case LY_TYPE_ENUM:
if (type->base != LY_TYPE_ENUM) {
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Invalid restriction in type \"%s\".", type->parent->name);
+ LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Invalid restriction in type \"%s\".", type->parent->name);
goto error;
}
dertype = &type->der->type;
@@ -767,7 +768,7 @@
if (!dertype->der) {
if (!type->info.enums.count) {
/* type is derived directly from buit-in enumeartion type and enum statement is required */
- LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "enum", "type");
+ LOGVAL(ctx, LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "enum", "type");
goto error;
}
} else {
@@ -775,7 +776,7 @@
if (module->version < 2 && type->info.enums.count) {
/* type is not directly derived from built-in enumeration type and enum statement is prohibited
* in YANG 1.0, since YANG 1.1 enum statements can be used to restrict the base enumeration type */
- LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "enum");
+ LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "enum");
goto error;
}
@@ -788,7 +789,7 @@
}
}
if (j == dertype->info.enums.count) {
- LOGVAL(LYE_ENUM_INNAME, LY_VLOG_NONE, NULL, type->info.enums.enm[i].name);
+ LOGVAL(ctx, LYE_ENUM_INNAME, LY_VLOG_NONE, NULL, type->info.enums.enm[i].name);
goto error;
}
@@ -801,7 +802,7 @@
if (type->info.enums.enm[i].value != enms_sc[j].value) {
/* type->info.enums.enm[i].value - assigned value in restricted enum
* enms_sc[j].value - value assigned to the corresponding enum (detected above) in base type */
- LOGVAL(LYE_ENUM_INVAL, LY_VLOG_NONE, NULL, type->info.enums.enm[i].value,
+ LOGVAL(ctx, LYE_ENUM_INVAL, LY_VLOG_NONE, NULL, type->info.enums.enm[i].value,
type->info.enums.enm[i].name, enms_sc[j].value);
goto error;
}
@@ -811,7 +812,7 @@
break;
case LY_TYPE_BITS:
if (type->base != LY_TYPE_BITS) {
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Invalid restriction in type \"%s\".", type->parent->name);
+ LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Invalid restriction in type \"%s\".", type->parent->name);
goto error;
}
dertype = &type->der->type;
@@ -819,7 +820,7 @@
if (!dertype->der) {
if (!type->info.bits.count) {
/* type is derived directly from buit-in bits type and bit statement is required */
- LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "bit", "type");
+ LOGVAL(ctx, LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "bit", "type");
goto error;
}
} else {
@@ -827,7 +828,7 @@
if (module->version < 2 && type->info.bits.count) {
/* type is not directly derived from buit-in bits type and bit statement is prohibited,
* since YANG 1.1 the bit statements can be used to restrict the base bits type */
- LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "bit");
+ LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "bit");
goto error;
}
@@ -839,7 +840,7 @@
}
}
if (j == dertype->info.bits.count) {
- LOGVAL(LYE_BITS_INNAME, LY_VLOG_NONE, NULL, type->info.bits.bit[i].name);
+ LOGVAL(ctx, LYE_BITS_INNAME, LY_VLOG_NONE, NULL, type->info.bits.bit[i].name);
goto error;
}
@@ -853,7 +854,7 @@
if (type->info.bits.bit[i].pos != bits_sc[j].pos) {
/* type->info.bits.bit[i].pos - assigned position in restricted bits
* bits_sc[j].pos - position assigned to the corresponding bit (detected above) in base type */
- LOGVAL(LYE_BITS_INVAL, LY_VLOG_NONE, NULL, type->info.bits.bit[i].pos,
+ LOGVAL(ctx, LYE_BITS_INVAL, LY_VLOG_NONE, NULL, type->info.bits.bit[i].pos,
type->info.bits.bit[i].name, bits_sc[j].pos);
goto error;
}
@@ -877,7 +878,7 @@
case LY_TYPE_LEAFREF:
if (type->base == LY_TYPE_INST) {
if (type->info.lref.path) {
- LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "path");
+ LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "path");
goto error;
}
if ((req = type->info.lref.req)) {
@@ -886,7 +887,7 @@
} else if (type->base == LY_TYPE_LEAFREF) {
/* require-instance only YANG 1.1 */
if (type->info.lref.req && (module->version < 2)) {
- LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "require-instance");
+ LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "require-instance");
goto error;
}
/* flag resolving for later use */
@@ -900,13 +901,13 @@
if (type->info.lref.path) {
if (type->der->type.der) {
- LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "path");
+ LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "path");
goto error;
}
value = type->info.lref.path;
/* store in the JSON format */
type->info.lref.path = transform_schema2json(module, value);
- lydict_remove(module->ctx, value);
+ lydict_remove(ctx, value);
if (!type->info.lref.path) {
goto error;
}
@@ -921,41 +922,41 @@
goto error;
}
} else if (!type->der->type.der) {
- LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "path", "type");
+ LOGVAL(ctx, LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "path", "type");
goto error;
} else {
/* copy leafref definition into the derived type */
- type->info.lref.path = lydict_insert(module->ctx, type->der->type.info.lref.path, 0);
+ type->info.lref.path = lydict_insert(ctx, type->der->type.info.lref.path, 0);
/* and resolve the path at the place we are (if not in grouping/typedef) */
if (!tpdftype && unres_schema_add_node(module, unres, type, UNRES_TYPE_LEAFREF, parent) == -1) {
goto error;
}
}
} else {
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Invalid restriction in type \"%s\".", type->parent->name);
+ LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Invalid restriction in type \"%s\".", type->parent->name);
goto error;
}
break;
case LY_TYPE_IDENT:
if (type->base != LY_TYPE_IDENT) {
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Invalid restriction in type \"%s\".", type->parent->name);
+ LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Invalid restriction in type \"%s\".", type->parent->name);
goto error;
}
if (type->der->type.der) {
if (type->info.ident.ref) {
- LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "base");
+ LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "base");
goto error;
}
} else {
if (!type->info.ident.ref) {
- LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "base", "type");
+ LOGVAL(ctx, LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "base", "type");
goto error;
}
}
break;
case LY_TYPE_UNION:
if (type->base != LY_TYPE_UNION) {
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Invalid restriction in type \"%s\".", type->parent->name);
+ LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Invalid restriction in type \"%s\".", type->parent->name);
goto error;
}
if (!type->info.uni.types) {
@@ -963,7 +964,7 @@
/* this is just a derived type with no additional type specified/required */
break;
}
- LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "type", "(union) type");
+ LOGVAL(ctx, LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "type", "(union) type");
goto error;
}
for (i = 0; i < type->info.uni.count; i++) {
@@ -979,16 +980,16 @@
base = 0;
goto error;
} else {
- lydict_remove(module->ctx, yang->name);
+ lydict_remove(ctx, yang->name);
free(yang);
}
}
if (module->version < 2) {
if (dertype->base == LY_TYPE_EMPTY) {
- LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, "empty", typ->name);
+ LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, "empty", typ->name);
goto error;
} else if (dertype->base == LY_TYPE_LEAFREF) {
- LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, "leafref", typ->name);
+ LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, "leafref", typ->name);
goto error;
}
}
@@ -1002,11 +1003,11 @@
default:
if (base >= LY_TYPE_BINARY && base <= LY_TYPE_UINT64) {
if (type->base != base) {
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Invalid restriction in type \"%s\".", type->parent->name);
+ LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Invalid restriction in type \"%s\".", type->parent->name);
goto error;
}
} else {
- LOGINT;
+ LOGINT(ctx);
goto error;
}
}
@@ -1040,19 +1041,19 @@
}
void *
-yang_read_type(struct lys_module *module, void *parent, char *value, enum yytokentype type)
+yang_read_type(struct ly_ctx *ctx, void *parent, char *value, enum yytokentype type)
{
struct yang_type *typ;
struct lys_deviate *dev;
typ = calloc(1, sizeof *typ);
- LY_CHECK_ERR_RETURN(!typ, LOGMEM, NULL);
+ LY_CHECK_ERR_RETURN(!typ, LOGMEM(ctx), NULL);
typ->flags = LY_YANG_STRUCTURE_FLAG;
switch (type) {
case LEAF_KEYWORD:
if (((struct lys_node_leaf *)parent)->type.der) {
- LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, parent, "type", "leaf");
+ LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_LYS, parent, "type", "leaf");
goto error;
}
((struct lys_node_leaf *)parent)->type.der = (struct lys_tpdf *)typ;
@@ -1061,7 +1062,7 @@
break;
case LEAF_LIST_KEYWORD:
if (((struct lys_node_leaflist *)parent)->type.der) {
- LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, parent, "type", "leaf-list");
+ LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_LYS, parent, "type", "leaf-list");
goto error;
}
((struct lys_node_leaflist *)parent)->type.der = (struct lys_tpdf *)typ;
@@ -1074,7 +1075,7 @@
break;
case TYPEDEF_KEYWORD:
if (((struct lys_tpdf *)parent)->type.der) {
- LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, "type", "typedef");
+ LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, "type", "typedef");
goto error;
}
((struct lys_tpdf *)parent)->type.der = (struct lys_tpdf *)typ;
@@ -1084,11 +1085,11 @@
/* deviation replace type*/
dev = (struct lys_deviate *)parent;
if (dev->type) {
- LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, "type", "deviation");
+ LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, "type", "deviation");
goto error;
}
dev->type = calloc(1, sizeof *dev->type);
- LY_CHECK_ERR_GOTO(!dev->type, LOGMEM, error);
+ LY_CHECK_ERR_GOTO(!dev->type, LOGMEM(ctx), error);
dev->type->der = (struct lys_tpdf *)typ;
typ->type = dev->type;
break;
@@ -1100,7 +1101,7 @@
goto error;
break;
}
- typ->name = lydict_insert_zc(module->ctx, value);
+ typ->name = lydict_insert_zc(ctx, value);
return typ;
error:
@@ -1110,7 +1111,7 @@
}
void *
-yang_read_length(struct lys_module *module, struct yang_type *stype, char *value, int is_ext_instance)
+yang_read_length(struct ly_ctx *ctx, struct yang_type *stype, char *value, int is_ext_instance)
{
struct lys_restr *length;
@@ -1120,19 +1121,19 @@
if (stype->base == 0 || stype->base == LY_TYPE_STRING) {
stype->base = LY_TYPE_STRING;
} else {
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Unexpected length statement.");
+ LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Unexpected length statement.");
goto error;
}
if (stype->type->info.str.length) {
- LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, "length", "type");
+ LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, "length", "type");
goto error;
}
length = calloc(1, sizeof *length);
- LY_CHECK_ERR_GOTO(!length, LOGMEM, error);
+ LY_CHECK_ERR_GOTO(!length, LOGMEM(ctx), error);
stype->type->info.str.length = length;
}
- length->expr = lydict_insert_zc(module->ctx, value);
+ length->expr = lydict_insert_zc(ctx, value);
return length;
error:
@@ -1141,30 +1142,30 @@
}
int
-yang_read_pattern(struct lys_module *module, struct lys_restr *pattern, void **precomp, char *value, char modifier)
+yang_read_pattern(struct ly_ctx *ctx, struct lys_restr *pattern, void **precomp, char *value, char modifier)
{
char *buf;
size_t len;
- if (precomp && lyp_precompile_pattern(value, (pcre**)&precomp[0], (pcre_extra**)&precomp[1])) {
+ if (precomp && lyp_precompile_pattern(ctx, value, (pcre**)&precomp[0], (pcre_extra**)&precomp[1])) {
free(value);
return EXIT_FAILURE;
}
len = strlen(value);
buf = malloc((len + 2) * sizeof *buf); /* modifier byte + value + terminating NULL byte */
- LY_CHECK_ERR_RETURN(!buf, LOGMEM; free(value), EXIT_FAILURE);
+ LY_CHECK_ERR_RETURN(!buf, LOGMEM(ctx); free(value), EXIT_FAILURE);
buf[0] = modifier;
strcpy(&buf[1], value);
free(value);
- pattern->expr = lydict_insert_zc(module->ctx, buf);
+ pattern->expr = lydict_insert_zc(ctx, buf);
return EXIT_SUCCESS;
}
void *
-yang_read_range(struct lys_module *module, struct yang_type *stype, char *value, int is_ext_instance)
+yang_read_range(struct ly_ctx *ctx, struct yang_type *stype, char *value, int is_ext_instance)
{
struct lys_restr * range;
@@ -1172,19 +1173,19 @@
range = (struct lys_restr *)stype;
} else {
if (stype->base != 0 && stype->base != LY_TYPE_DEC64) {
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Unexpected range statement.");
+ LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Unexpected range statement.");
goto error;
}
stype->base = LY_TYPE_DEC64;
if (stype->type->info.dec64.range) {
- LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, "range", "type");
+ LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, "range", "type");
goto error;
}
range = calloc(1, sizeof *range);
- LY_CHECK_ERR_GOTO(!range, LOGMEM, error);
+ LY_CHECK_ERR_GOTO(!range, LOGMEM(ctx), error);
stype->type->info.dec64.range = range;
}
- range->expr = lydict_insert_zc(module->ctx, value);
+ range->expr = lydict_insert_zc(ctx, value);
return range;
error:
@@ -1193,21 +1194,21 @@
}
int
-yang_read_fraction(struct yang_type *typ, uint32_t value)
+yang_read_fraction(struct ly_ctx *ctx, struct yang_type *typ, uint32_t value)
{
if (typ->base == 0 || typ->base == LY_TYPE_DEC64) {
typ->base = LY_TYPE_DEC64;
} else {
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Unexpected fraction-digits statement.");
+ LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Unexpected fraction-digits statement.");
goto error;
}
if (typ->type->info.dec64.dig) {
- LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, "fraction-digits", "type");
+ LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, "fraction-digits", "type");
goto error;
}
/* range check */
if (value < 1 || value > 18) {
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Invalid value \"%d\" of \"%s\".", value, "fraction-digits");
+ LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Invalid value \"%d\" of \"%s\".", value, "fraction-digits");
goto error;
}
typ->type->info.dec64.dig = value;
@@ -1218,23 +1219,23 @@
}
int
-yang_read_enum(struct lys_module *module, struct yang_type *typ, struct lys_type_enum *enm, char *value)
+yang_read_enum(struct ly_ctx *ctx, struct yang_type *typ, struct lys_type_enum *enm, char *value)
{
int i, j;
typ->base = LY_TYPE_ENUM;
if (!value[0]) {
- LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "enum name");
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Enum name must not be empty.");
+ LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, "enum name");
+ LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Enum name must not be empty.");
free(value);
goto error;
}
- enm->name = lydict_insert_zc(module->ctx, value);
+ enm->name = lydict_insert_zc(ctx, value);
/* the assigned name MUST NOT have any leading or trailing whitespace characters */
if (isspace(enm->name[0]) || isspace(enm->name[strlen(enm->name) - 1])) {
- LOGVAL(LYE_ENUM_WS, LY_VLOG_NONE, NULL, enm->name);
+ LOGVAL(ctx, LYE_ENUM_WS, LY_VLOG_NONE, NULL, enm->name);
goto error;
}
@@ -1242,7 +1243,7 @@
/* check the name uniqueness */
for (i = 0; i < j; i++) {
if (ly_strequal(typ->type->info.enums.enm[i].name, enm->name, 1)) {
- LOGVAL(LYE_ENUM_DUPNAME, LY_VLOG_NONE, NULL, enm->name);
+ LOGVAL(ctx, LYE_ENUM_DUPNAME, LY_VLOG_NONE, NULL, enm->name);
goto error;
}
}
@@ -1254,14 +1255,14 @@
}
int
-yang_check_enum(struct yang_type *typ, struct lys_type_enum *enm, int64_t *value, int assign)
+yang_check_enum(struct ly_ctx *ctx, struct yang_type *typ, struct lys_type_enum *enm, int64_t *value, int assign)
{
int i, j;
if (!assign) {
/* assign value automatically */
if (*value > INT32_MAX) {
- LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, "2147483648", "enum/value");
+ LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, "2147483648", "enum/value");
goto error;
}
enm->value = *value;
@@ -1277,7 +1278,7 @@
j = typ->type->info.enums.count-1;
for (i = 0; i < j; i++) {
if (typ->type->info.enums.enm[i].value == typ->type->info.enums.enm[j].value) {
- LOGVAL(LYE_ENUM_DUPVAL, LY_VLOG_NONE, NULL,
+ LOGVAL(ctx, LYE_ENUM_DUPVAL, LY_VLOG_NONE, NULL,
typ->type->info.enums.enm[j].value, typ->type->info.enums.enm[j].name,
typ->type->info.enums.enm[i].name);
goto error;
@@ -1291,13 +1292,13 @@
}
int
-yang_read_bit(struct lys_module *module, struct yang_type *typ, struct lys_type_bit *bit, char *value)
+yang_read_bit(struct ly_ctx *ctx, struct yang_type *typ, struct lys_type_bit *bit, char *value)
{
int i, j;
typ->base = LY_TYPE_BITS;
- bit->name = lydict_insert_zc(module->ctx, value);
- if (lyp_check_identifier(bit->name, LY_IDENT_SIMPLE, NULL, NULL)) {
+ bit->name = lydict_insert_zc(ctx, value);
+ if (lyp_check_identifier(ctx, bit->name, LY_IDENT_SIMPLE, NULL, NULL)) {
goto error;
}
@@ -1305,7 +1306,7 @@
/* check the name uniqueness */
for (i = 0; i < j; i++) {
if (ly_strequal(typ->type->info.bits.bit[i].name, bit->name, 1)) {
- LOGVAL(LYE_BITS_DUPNAME, LY_VLOG_NONE, NULL, bit->name);
+ LOGVAL(ctx, LYE_BITS_DUPNAME, LY_VLOG_NONE, NULL, bit->name);
goto error;
}
}
@@ -1316,14 +1317,14 @@
}
int
-yang_check_bit(struct yang_type *typ, struct lys_type_bit *bit, int64_t *value, int assign)
+yang_check_bit(struct ly_ctx *ctx, struct yang_type *typ, struct lys_type_bit *bit, int64_t *value, int assign)
{
int i,j;
if (!assign) {
/* assign value automatically */
if (*value > UINT32_MAX) {
- LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, "4294967295", "bit/position");
+ LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, "4294967295", "bit/position");
goto error;
}
bit->pos = (uint32_t)*value;
@@ -1335,7 +1336,7 @@
/* check that the value is unique */
for (i = 0; i < j; i++) {
if (typ->type->info.bits.bit[i].pos == bit->pos) {
- LOGVAL(LYE_BITS_DUPVAL, LY_VLOG_NONE, NULL, bit->pos, bit->name, typ->type->info.bits.bit[i].name);
+ LOGVAL(ctx, LYE_BITS_DUPVAL, LY_VLOG_NONE, NULL, bit->pos, bit->name, typ->type->info.bits.bit[i].name);
goto error;
}
}
@@ -1361,32 +1362,32 @@
}
void *
-yang_read_deviate_unsupported(struct lys_deviation *dev)
+yang_read_deviate_unsupported(struct ly_ctx *ctx, struct lys_deviation *dev)
{
if (dev->deviate_size) {
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "\"not-supported\" deviation cannot be combined with any other deviation.");
+ LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "\"not-supported\" deviation cannot be combined with any other deviation.");
return NULL;
}
dev->deviate = calloc(1, sizeof *dev->deviate);
- LY_CHECK_ERR_RETURN(!dev->deviate, LOGMEM, NULL);
+ LY_CHECK_ERR_RETURN(!dev->deviate, LOGMEM(ctx), NULL);
dev->deviate[dev->deviate_size].mod = LY_DEVIATE_NO;
dev->deviate_size = 1;
return dev->deviate;
}
void *
-yang_read_deviate(struct lys_deviation *dev, LYS_DEVIATE_TYPE mod)
+yang_read_deviate(struct ly_ctx *ctx, struct lys_deviation *dev, LYS_DEVIATE_TYPE mod)
{
struct lys_deviate *deviate;
if (dev->deviate_size && dev->deviate[0].mod == LY_DEVIATE_NO) {
- LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "not-supported");
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "\"not-supported\" deviation cannot be combined with any other deviation.");
+ LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "not-supported");
+ LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "\"not-supported\" deviation cannot be combined with any other deviation.");
return NULL;
}
if (!(dev->deviate_size % LY_YANG_ARRAY_SIZE)) {
deviate = realloc(dev->deviate, (LY_YANG_ARRAY_SIZE + dev->deviate_size) * sizeof *deviate);
- LY_CHECK_ERR_RETURN(!deviate, LOGMEM, NULL);
+ LY_CHECK_ERR_RETURN(!deviate, LOGMEM(ctx), NULL);
memset(deviate + dev->deviate_size, 0, LY_YANG_ARRAY_SIZE * sizeof *deviate);
dev->deviate = deviate;
}
@@ -1406,16 +1407,16 @@
} else if (dev_target->nodetype == LYS_LEAF) {
stritem = &((struct lys_node_leaf *)dev_target)->units;
} else {
- LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "units");
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Target node does not allow \"units\" property.");
+ LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "units");
+ LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Target node does not allow \"units\" property.");
goto error;
}
if (deviate->mod == LY_DEVIATE_DEL) {
/* check values */
if (!ly_strequal(*stritem, deviate->units, 1)) {
- LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, deviate->units, "units");
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Value differs from the target being deleted.");
+ LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, deviate->units, "units");
+ LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Value differs from the target being deleted.");
goto error;
}
/* remove current units value of the target */
@@ -1431,14 +1432,14 @@
if (deviate->mod == LY_DEVIATE_ADD) {
/* check that there is no current value */
if (*stritem) {
- LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "units");
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Adding property that already exists.");
+ LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "units");
+ LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Adding property that already exists.");
goto error;
}
} else { /* replace */
if (!*stritem) {
- LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "units");
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Replacing a property that does not exist.");
+ LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "units");
+ LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Replacing a property that does not exist.");
goto error;
}
}
@@ -1458,13 +1459,14 @@
int
yang_read_deviate_unique(struct lys_deviate *deviate, struct lys_node *dev_target)
{
+ struct ly_ctx *ctx = dev_target->module->ctx;
struct lys_node_list *list;
struct lys_unique *unique;
/* check target node type */
if (dev_target->nodetype != LYS_LIST) {
- LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "unique");
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Target node does not allow \"unique\" property.");
+ LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "unique");
+ LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Target node does not allow \"unique\" property.");
goto error;
}
@@ -1472,7 +1474,7 @@
if (deviate->mod == LY_DEVIATE_ADD) {
/* reallocate the unique array of the target */
unique = ly_realloc(list->unique, (deviate->unique_size + list->unique_size) * sizeof *unique);
- LY_CHECK_ERR_GOTO(!unique, LOGMEM, error);
+ LY_CHECK_ERR_GOTO(!unique, LOGMEM(ctx), error);
list->unique = unique;
memset(unique + list->unique_size, 0, deviate->unique_size * sizeof *unique);
}
@@ -1499,13 +1501,13 @@
choice = (struct lys_node_choice *)dev_target;
rc = resolve_choice_default_schema_nodeid(value, choice->child, (const struct lys_node **)&node);
if (rc || !node) {
- LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default");
+ LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, "default");
goto error;
}
if (deviate->mod == LY_DEVIATE_DEL) {
if (!choice->dflt || (choice->dflt != node)) {
- LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default");
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Value differs from the target being deleted.");
+ LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, "default");
+ LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Value differs from the target being deleted.");
goto error;
}
choice->dflt = NULL;
@@ -1519,7 +1521,7 @@
choice->dflt = node;
if (!choice->dflt) {
/* default branch not found */
- LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default");
+ LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, "default");
goto error;
}
}
@@ -1527,8 +1529,8 @@
leaf = (struct lys_node_leaf *)dev_target;
if (deviate->mod == LY_DEVIATE_DEL) {
if (!leaf->dflt || !ly_strequal(leaf->dflt, value, 1)) {
- LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default");
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Value differs from the target being deleted.");
+ LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, "default");
+ LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Value differs from the target being deleted.");
goto error;
}
/* remove value */
@@ -1576,8 +1578,8 @@
}
}
if (i == llist->dflt_size) {
- LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default");
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "The default value to delete not found in the target node.");
+ LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, "default");
+ LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "The default value to delete not found in the target node.");
goto error;
}
} else {
@@ -1586,8 +1588,8 @@
/* we just want to check that the value isn't already in the list */
for (i = 0; i < llist->dflt_size; i++) {
if (ly_strequal(llist->dflt[i], value, 1)) {
- LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default");
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Duplicated default value \"%s\".", value);
+ LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, "default");
+ LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Duplicated default value \"%s\".", value);
goto error;
}
}
@@ -1601,6 +1603,7 @@
}
return EXIT_SUCCESS;
+
error:
return EXIT_FAILURE;
}
@@ -1609,22 +1612,23 @@
yang_read_deviate_default(struct lys_module *module, struct lys_deviate *deviate,
struct lys_node *dev_target, struct ly_set * dflt_check)
{
+ struct ly_ctx *ctx = module->ctx;
int i;
struct lys_node_leaflist *llist;
const char **dflt;
/* check target node type */
if (module->version < 2 && dev_target->nodetype == LYS_LEAFLIST) {
- LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "default");
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Target node does not allow \"default\" property.");
+ LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "default");
+ LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Target node does not allow \"default\" property.");
goto error;
} else if (deviate->dflt_size > 1 && dev_target->nodetype != LYS_LEAFLIST) { /* from YANG 1.1 */
- LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "default");
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Target node does not allow multiple \"default\" properties.");
+ LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "default");
+ LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Target node does not allow multiple \"default\" properties.");
goto error;
} else if (!(dev_target->nodetype & (LYS_LEAF | LYS_LEAFLIST | LYS_CHOICE))) {
- LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "default");
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Target node does not allow \"default\" property.");
+ LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "default");
+ LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Target node does not allow \"default\" property.");
goto error;
}
@@ -1632,16 +1636,16 @@
/* check that there is no current value */
if ((dev_target->nodetype == LYS_LEAF && ((struct lys_node_leaf *)dev_target)->dflt) ||
(dev_target->nodetype == LYS_CHOICE && ((struct lys_node_choice *)dev_target)->dflt)) {
- LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "default");
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Adding property that already exists.");
+ LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "default");
+ LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Adding property that already exists.");
goto error;
}
/* check collision with mandatory/min-elements */
if ((dev_target->flags & LYS_MAND_TRUE) ||
(dev_target->nodetype == LYS_LEAFLIST && ((struct lys_node_leaflist *)dev_target)->min)) {
- LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "default", "deviation");
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL,
+ LOGVAL(ctx, LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "default", "deviation");
+ LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL,
"Adding the \"default\" statement is forbidden on %s statement.",
(dev_target->flags & LYS_MAND_TRUE) ? "nodes with the \"mandatory\"" : "leaflists with non-zero \"min-elements\"");
goto error;
@@ -1650,8 +1654,8 @@
/* check that there was a value before */
if (((dev_target->nodetype & (LYS_LEAF | LYS_LEAFLIST)) && !((struct lys_node_leaf *)dev_target)->dflt) ||
(dev_target->nodetype == LYS_CHOICE && !((struct lys_node_choice *)dev_target)->dflt)) {
- LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "default");
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Replacing a property that does not exist.");
+ LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "default");
+ LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Replacing a property that does not exist.");
goto error;
}
}
@@ -1662,22 +1666,22 @@
if (deviate->mod == LY_DEVIATE_ADD) {
/* reallocate (enlarge) the unique array of the target */
dflt = realloc(llist->dflt, (deviate->dflt_size + llist->dflt_size) * sizeof *dflt);
- LY_CHECK_ERR_GOTO(!dflt, LOGMEM, error);
+ LY_CHECK_ERR_GOTO(!dflt, LOGMEM(ctx), error);
llist->dflt = dflt;
} else if (deviate->mod == LY_DEVIATE_RPL) {
/* reallocate (replace) the unique array of the target */
for (i = 0; i < llist->dflt_size; i++) {
- lydict_remove(llist->module->ctx, llist->dflt[i]);
+ lydict_remove(ctx, llist->dflt[i]);
}
dflt = realloc(llist->dflt, deviate->dflt_size * sizeof *dflt);
- LY_CHECK_ERR_GOTO(!dflt, LOGMEM, error);
+ LY_CHECK_ERR_GOTO(!dflt, LOGMEM(ctx), error);
llist->dflt = dflt;
llist->dflt_size = 0;
}
}
for (i = 0; i < deviate->dflt_size; ++i) {
- if (yang_fill_deviate_default(module->ctx, deviate, dev_target, dflt_check, deviate->dflt[i])) {
+ if (yang_fill_deviate_default(ctx, deviate, dev_target, dflt_check, deviate->dflt[i])) {
goto error;
}
}
@@ -1691,37 +1695,38 @@
int
yang_check_deviate_mandatory(struct lys_deviate *deviate, struct lys_node *dev_target)
{
+ struct ly_ctx *ctx = dev_target->module->ctx;
struct lys_node *parent;
/* check target node type */
if (!(dev_target->nodetype & (LYS_LEAF | LYS_CHOICE | LYS_ANYDATA))) {
- LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "mandatory");
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Target node does not allow \"mandatory\" property.");
+ LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "mandatory");
+ LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Target node does not allow \"mandatory\" property.");
goto error;
}
if (deviate->mod == LY_DEVIATE_ADD) {
/* check that there is no current value */
if (dev_target->flags & LYS_MAND_MASK) {
- LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "mandatory");
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Adding property that already exists.");
+ LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "mandatory");
+ LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Adding property that already exists.");
goto error;
} else {
if (dev_target->nodetype == LYS_LEAF && ((struct lys_node_leaf *)dev_target)->dflt) {
/* RFC 6020, 7.6.4 - default statement must not with mandatory true */
- LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "mandatory", "leaf");
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "The \"mandatory\" statement is forbidden on leaf with \"default\".");
+ LOGVAL(ctx, LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "mandatory", "leaf");
+ LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "The \"mandatory\" statement is forbidden on leaf with \"default\".");
goto error;
} else if (dev_target->nodetype == LYS_CHOICE && ((struct lys_node_choice *)dev_target)->dflt) {
- LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "mandatory", "choice");
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "The \"mandatory\" statement is forbidden on choices with \"default\".");
+ LOGVAL(ctx, LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "mandatory", "choice");
+ LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "The \"mandatory\" statement is forbidden on choices with \"default\".");
goto error;
}
}
} else { /* replace */
if (!(dev_target->flags & LYS_MAND_MASK)) {
- LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "mandatory");
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Replacing a property that does not exist.");
+ LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "mandatory");
+ LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Replacing a property that does not exist.");
goto error;
}
}
@@ -1757,6 +1762,7 @@
int
yang_read_deviate_minmax(struct lys_deviate *deviate, struct lys_node *dev_target, uint32_t value, int type)
{
+ struct ly_ctx *ctx = dev_target->module->ctx;
uint32_t *ui32val, *min, *max;
/* check target node type */
@@ -1767,8 +1773,8 @@
max = &((struct lys_node_list *)dev_target)->max;
min = &((struct lys_node_list *)dev_target)->min;
} else {
- LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, (type) ? "max-elements" : "min-elements");
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Target node does not allow \"%s\" property.", (type) ? "max-elements" : "min-elements");
+ LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, (type) ? "max-elements" : "min-elements");
+ LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Target node does not allow \"%s\" property.", (type) ? "max-elements" : "min-elements");
goto error;
}
@@ -1776,8 +1782,8 @@
if (deviate->mod == LY_DEVIATE_ADD) {
/* check that there is no current value */
if (*ui32val) {
- LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, (type) ? "max-elements" : "min-elements");
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Adding property that already exists.");
+ LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, (type) ? "max-elements" : "min-elements");
+ LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Adding property that already exists.");
goto error;
}
} else if (deviate->mod == LY_DEVIATE_RPL) {
@@ -1792,11 +1798,11 @@
/* check min-elements is smaller than max-elements */
if (*max && *min > *max) {
if (type) {
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Invalid value \"%d\" of \"max-elements\".", value);
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "\"max-elements\" is smaller than \"min-elements\".");
+ LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Invalid value \"%d\" of \"max-elements\".", value);
+ LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "\"max-elements\" is smaller than \"min-elements\".");
} else {
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Invalid value \"%d\" of \"min-elements\".", value);
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "\"min-elements\" is bigger than \"max-elements\".");
+ LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Invalid value \"%d\" of \"min-elements\".", value);
+ LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "\"min-elements\" is bigger than \"max-elements\".");
}
goto error;
}
@@ -1811,6 +1817,7 @@
yang_check_deviate_must(struct lys_module *module, struct unres_schema *unres,
struct lys_deviate *deviate, struct lys_node *dev_target)
{
+ struct ly_ctx *ctx = module->ctx;
int i, j, erase_must = 1;
struct lys_restr **trg_must, *must;
uint8_t *trg_must_size;
@@ -1839,8 +1846,8 @@
trg_must_size = &((struct lys_node_anydata *)dev_target)->must_size;
break;
default:
- LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "must");
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Target node does not allow \"must\" property.");
+ LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "must");
+ LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Target node does not allow \"must\" property.");
goto error;
}
@@ -1850,7 +1857,7 @@
if (deviate->mod == LY_DEVIATE_ADD) {
/* reallocate the must array of the target */
must = ly_realloc(*trg_must, (deviate->must_size + *trg_must_size) * sizeof *must);
- LY_CHECK_ERR_GOTO(!must, LOGMEM, error);
+ LY_CHECK_ERR_GOTO(!must, LOGMEM(ctx), error);
*trg_must = must;
memcpy(&(*trg_must)[*trg_must_size], deviate->must, deviate->must_size * sizeof *must);
free(deviate->must);
@@ -1882,8 +1889,8 @@
}
if (i != -1) {
/* no match found */
- LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, deviate->must[j].expr, "must");
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Value does not match any must from the target.");
+ LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, deviate->must[j].expr, "must");
+ LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Value does not match any must from the target.");
goto error;
}
}
@@ -1899,6 +1906,7 @@
}
return EXIT_SUCCESS;
+
error:
if (deviate->mod == LY_DEVIATE_ADD && erase_must) {
for (i = 0; i < deviate->must_size; ++i) {
@@ -1913,6 +1921,7 @@
yang_deviate_delete_unique(struct lys_module *module, struct lys_deviate *deviate,
struct lys_node_list *list, int index, char * value)
{
+ struct ly_ctx *ctx = module->ctx;
int i, j, k;
/* find unique structures to delete */
@@ -1930,7 +1939,7 @@
if (j == deviate->unique[index].expr_size) {
/* we have a match, free the unique structure ... */
for (j = 0; j < list->unique[i].expr_size; j++) {
- lydict_remove(module->ctx, list->unique[i].expr[j]);
+ lydict_remove(ctx, list->unique[i].expr[j]);
}
free(list->unique[i].expr);
/* ... and maintain the array */
@@ -1956,8 +1965,8 @@
if (i != -1) {
/* no match found */
- LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "unique");
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Value differs from the target being deleted.");
+ LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, "unique");
+ LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Value differs from the target being deleted.");
return EXIT_FAILURE;
}
@@ -1965,7 +1974,7 @@
j = -1;
while ((j = lys_ext_iter(list->ext, list->ext_size, j + 1, LYEXT_SUBSTMT_UNIQUE)) != -1) {
if (list->ext[j]->insubstmt_index == k) {
- lyp_ext_instance_rm(module->ctx, &list->ext, &list->ext_size, j);
+ lyp_ext_instance_rm(ctx, &list->ext, &list->ext_size, j);
--j;
} else if (list->ext[j]->insubstmt_index > k) {
/* decrease the substatement index of the extension because of the changed array of uniques */
@@ -2012,8 +2021,8 @@
deviate->unique = last_unique;
}
-
return EXIT_SUCCESS;
+
error:
if (deviate->mod == LY_DEVIATE_ADD) {
for (i = i + 1; i < deviate->unique_size; ++i) {
@@ -2201,7 +2210,7 @@
parent_type = LYEXT_PAR_EXTINST;
break;
default:
- LOGINT;
+ LOGINT(NULL);
return NULL;
}
@@ -2220,7 +2229,7 @@
return instance;
error:
- LOGMEM;
+ LOGMEM(NULL);
free(instance);
return NULL;
}
@@ -2387,7 +2396,7 @@
}
break;
default:
- LOGINT;
+ LOGINT(module->ctx);
return NULL;
}
} else {
@@ -2422,6 +2431,7 @@
static int
check_status_flag(struct lys_node *node, struct lys_node *parent)
{
+ struct ly_ctx *ctx = node->module->ctx;
char *str;
if (node->nodetype & (LYS_OUTPUT | LYS_INPUT)) {
@@ -2435,7 +2445,7 @@
if (!(node->flags & (LYS_STATUS_MASK))) {
/* status not explicitely specified on the current node -> inherit */
str = lys_path(node, LYS_PATH_FIRST_PREFIX);
- LOGWRN("Missing status in %s subtree (%s), inheriting.",
+ LOGWRN(ctx, "Missing status in %s subtree (%s), inheriting.",
parent->flags & LYS_STATUS_DEPRC ? "deprecated" : "obsolete", str);
free(str);
node->flags |= parent->flags & LYS_STATUS_MASK;
@@ -2444,11 +2454,11 @@
switch (node->flags & LYS_STATUS_MASK) {
case 0:
case LYS_STATUS_CURR:
- LOGVAL(LYE_INSTATUS, LY_VLOG_LYS, parent, "current", strnodetype(node->nodetype), "is child of",
+ LOGVAL(ctx, LYE_INSTATUS, LY_VLOG_LYS, parent, "current", strnodetype(node->nodetype), "is child of",
parent->flags & LYS_STATUS_DEPRC ? "deprecated" : "obsolete", parent->name);
break;
case LYS_STATUS_DEPRC:
- LOGVAL(LYE_INSTATUS, LY_VLOG_LYS, parent, "deprecated", strnodetype(node->nodetype), "is child of",
+ LOGVAL(ctx, LYE_INSTATUS, LY_VLOG_LYS, parent, "deprecated", strnodetype(node->nodetype), "is child of",
"obsolete", parent->name);
break;
}
@@ -2517,6 +2527,7 @@
size = (size_data) ? size_data : strlen(data) + 2;
yylex_init(&scanner);
+ yyset_extra(module->ctx, scanner);
bp = yy_scan_buffer((char *)data, size, scanner);
yy_switch_to_buffer(bp, scanner);
memset(¶m, 0, sizeof param);
@@ -2589,10 +2600,10 @@
int ret;
unres = calloc(1, sizeof *unres);
- LY_CHECK_ERR_GOTO(!unres, LOGMEM, error);
+ LY_CHECK_ERR_GOTO(!unres, LOGMEM(ctx), error);
module = calloc(1, sizeof *module);
- LY_CHECK_ERR_GOTO(!module, LOGMEM, error);
+ LY_CHECK_ERR_GOTO(!module, LOGMEM(ctx), error);
/* initiale module */
module->ctx = ctx;
@@ -2606,7 +2617,7 @@
ret = yang_parse_mem(module, NULL, unres, data, size, &node);
if (ret == -1) {
- if (ly_vecode == LYVE_SUBMODULE) {
+ if (ly_vecode(ctx) == LYVE_SUBMODULE) {
free(module);
module = NULL;
} else {
@@ -2683,16 +2694,16 @@
/* cleanup */
unres_schema_free(module, &unres, 1);
if (!module) {
- if (ly_vecode != LYVE_SUBMODULE) {
- LOGERR(ly_errno, "Module parsing failed.");
+ if (ly_vecode(ctx) != LYVE_SUBMODULE) {
+ LOGERR(ctx, ly_errno, "Module parsing failed.");
}
return NULL;
}
if (module->name) {
- LOGERR(ly_errno, "Module \"%s\" parsing failed.", module->name);
+ LOGERR(ctx, ly_errno, "Module \"%s\" parsing failed.", module->name);
} else {
- LOGERR(ly_errno, "Module parsing failed.");
+ LOGERR(ctx, ly_errno, "Module parsing failed.");
}
lyp_check_circmod_pop(ctx);
@@ -2709,7 +2720,7 @@
struct lys_node *node = NULL;
submodule = calloc(1, sizeof *submodule);
- LY_CHECK_ERR_GOTO(!submodule, LOGMEM, error);
+ LY_CHECK_ERR_GOTO(!submodule, LOGMEM(module->ctx), error);
submodule->ctx = module->ctx;
submodule->type = 1;
@@ -2742,11 +2753,11 @@
/* cleanup */
if (!submodule || !submodule->name) {
free(submodule);
- LOGERR(ly_errno, "Submodule parsing failed.");
+ LOGERR(module->ctx, ly_errno, "Submodule parsing failed.");
return NULL;
}
- LOGERR(ly_errno, "Submodule \"%s\" parsing failed.", submodule->name);
+ LOGERR(module->ctx, ly_errno, "Submodule \"%s\" parsing failed.", submodule->name);
unres_schema_free((struct lys_module *)submodule, &unres, 0);
lyp_check_circmod_pop(module->ctx);
@@ -2789,7 +2800,8 @@
}
char *
-yang_read_string(const char *input, char *output, int size, int offset, int indent) {
+yang_read_string(struct ly_ctx *ctx, const char *input, char *output, int size, int offset, int indent)
+{
int i = 0, out_index = offset, space = 0;
while (i < size) {
@@ -2823,7 +2835,7 @@
++i;
} else {
/* backslash must not be followed by any other character */
- LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, input);
+ LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, input);
return NULL;
}
break;
@@ -2838,7 +2850,7 @@
output[out_index] = '\0';
if (size != out_index) {
output = realloc(output, out_index + 1);
- LY_CHECK_ERR_RETURN(!output, LOGMEM, NULL);
+ LY_CHECK_ERR_RETURN(!output, LOGMEM(ctx), NULL);
}
return output;
}
@@ -3266,7 +3278,7 @@
for (i = 0; i < size; ++i) {
info = malloc(sizeof *info);
- LY_CHECK_ERR_RETURN(!info, LOGMEM, EXIT_FAILURE);
+ LY_CHECK_ERR_RETURN(!info, LOGMEM(module->ctx), EXIT_FAILURE);
info->data.yang = (*ext)[i]->parent;
info->datatype = LYS_IN_YANG;
info->parent = parent;
@@ -3299,13 +3311,13 @@
if (imp_size) {
module->imp = calloc(imp_size, sizeof *module->imp);
module->imp_size = 0;
- LY_CHECK_ERR_GOTO(!module->imp, LOGMEM, error);
+ LY_CHECK_ERR_GOTO(!module->imp, LOGMEM(module->ctx), error);
}
if (inc_size) {
module->inc = calloc(inc_size, sizeof *module->inc);
module->inc_size = 0;
- LY_CHECK_ERR_GOTO(!module->inc, LOGMEM, error);
+ LY_CHECK_ERR_GOTO(!module->inc, LOGMEM(module->ctx), error);
}
for (i = 0; i < imp_size; ++i) {
@@ -3550,7 +3562,7 @@
ptr_tpdf_size16 = &((struct lys_node_notif *)parent)->tpdf_size;
break;
default:
- LOGINT;
+ LOGINT(module->ctx);
return EXIT_FAILURE;
}
}
@@ -3564,7 +3576,7 @@
}
for (i = 0; i < tpdf_size; ++i) {
- if (lyp_check_identifier(tpdf[i].name, LY_IDENT_TYPE, module, parent)) {
+ if (lyp_check_identifier(module->ctx, tpdf[i].name, LY_IDENT_TYPE, module, parent)) {
goto error;
}
@@ -3625,7 +3637,6 @@
}
}
-
return EXIT_SUCCESS;
error:
@@ -3689,6 +3700,7 @@
return EXIT_SUCCESS;
error:
+
return EXIT_FAILURE;
}
@@ -3735,6 +3747,7 @@
}
return EXIT_SUCCESS;
+
error:
return EXIT_FAILURE;
}
@@ -3765,8 +3778,8 @@
if (leaflist->flags & LYS_CONFIG_W) {
for (j = i +1; j < leaflist->dflt_size; ++j) {
if (ly_strequal(leaflist->dflt[i], leaflist->dflt[j], 1)) {
- LOGVAL(LYE_INARG, LY_VLOG_LYS, leaflist, leaflist->dflt[i], "default");
- LOGVAL(LYE_SPEC, LY_VLOG_LYS, leaflist, "Duplicated default value \"%s\".", leaflist->dflt[i]);
+ LOGVAL(module->ctx, LYE_INARG, LY_VLOG_LYS, leaflist, leaflist->dflt[i], "default");
+ LOGVAL(module->ctx, LYE_SPEC, LY_VLOG_LYS, leaflist, "Duplicated default value \"%s\".", leaflist->dflt[i]);
goto error;
}
}
@@ -3801,6 +3814,7 @@
}
return EXIT_SUCCESS;
+
error:
return EXIT_FAILURE;
}
@@ -3829,7 +3843,7 @@
* (but only if we are not in a grouping or augment, then the check is deferred) */
for (node = (struct lys_node *)list; node && !(node->nodetype & (LYS_GROUPING | LYS_AUGMENT | LYS_EXT)); node = node->parent);
if (!node && (list->flags & LYS_CONFIG_W) && !list->keys) {
- LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_LYS, list, "key", "list");
+ LOGVAL(module->ctx, LYE_MISSCHILDSTMT, LY_VLOG_LYS, list, "key", "list");
goto error;
}
@@ -3868,6 +3882,7 @@
}
return EXIT_SUCCESS;
+
error:
return EXIT_FAILURE;
}
@@ -3920,6 +3935,7 @@
}
return EXIT_SUCCESS;
+
error:
return EXIT_FAILURE;
}
@@ -3934,7 +3950,7 @@
for (node = rpc->parent; node; node = lys_parent(node)) {
if ((node->nodetype & (LYS_RPC | LYS_ACTION | LYS_NOTIF))
|| ((node->nodetype == LYS_LIST) && !((struct lys_node_list *)node)->keys)) {
- LOGVAL(LYE_INPAR, LY_VLOG_LYS, rpc->parent, strnodetype(node->nodetype), "action");
+ LOGVAL(module->ctx, LYE_INPAR, LY_VLOG_LYS, rpc->parent, strnodetype(node->nodetype), "action");
goto error;
}
}
@@ -3954,6 +3970,7 @@
*child = NULL;
return EXIT_SUCCESS;
+
error:
return EXIT_FAILURE;
}
@@ -3994,6 +4011,7 @@
}
return EXIT_SUCCESS;
+
error:
return EXIT_FAILURE;
}
@@ -4037,6 +4055,7 @@
}
return EXIT_SUCCESS;
+
error:
return EXIT_FAILURE;
}
@@ -4094,6 +4113,7 @@
}
return EXIT_SUCCESS;
+
error:
for (i = uses->augment_size; i < size; ++i) {
yang_free_augment(module->ctx, &uses->augment[i]);
@@ -4136,6 +4156,7 @@
}
return EXIT_SUCCESS;
+
error:
return EXIT_FAILURE;
}
@@ -4279,13 +4300,14 @@
}
break;
default:
- LOGINT;
+ LOGINT(module->ctx);
goto error;
}
node = sibling;
}
return EXIT_SUCCESS;
+
error:
yang_free_nodes(module->ctx, sibling);
yang_free_nodes(module->ctx, child);
@@ -4359,8 +4381,8 @@
} else if (dev_target->nodetype == LYS_LEAFLIST) {
type = &((struct lys_node_leaflist *)dev_target)->type;
} else {
- LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "type");
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Target node does not allow \"type\" property.");
+ LOGVAL(module->ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "type");
+ LOGVAL(module->ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Target node does not allow \"type\" property.");
goto error;
}
/* remove type and initialize it */
@@ -4380,6 +4402,7 @@
}
return EXIT_SUCCESS;
+
error:
if (deviate->type) {
yang_type_free(module->ctx, deviate->type);
@@ -4405,7 +4428,7 @@
/* resolve target node */
rc = resolve_schema_nodeid(dev->target_name, NULL, module, &set, 0, 1);
if (rc == -1) {
- LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, dev->target_name, "deviation");
+ LOGVAL(module->ctx, LYE_INARG, LY_VLOG_NONE, NULL, dev->target_name, "deviation");
ly_set_free(set);
goto error;
}
@@ -4413,13 +4436,13 @@
ly_set_free(set);
if (dev_target->module == lys_main_module(module)) {
- LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, dev->target_name, "deviation");
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Deviating own module is not allowed.");
+ LOGVAL(module->ctx, LYE_INARG, LY_VLOG_NONE, NULL, dev->target_name, "deviation");
+ LOGVAL(module->ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Deviating own module is not allowed.");
goto error;
}
if (!dflt_check) {
- LOGMEM;
+ LOGMEM(module->ctx);
goto error;
}
@@ -4428,8 +4451,8 @@
if ((dev_target->nodetype == LYS_LEAF) && dev_target->parent && (dev_target->parent->nodetype == LYS_LIST)) {
for (i = 0; i < ((struct lys_node_list *)dev_target->parent)->keys_size; ++i) {
if (((struct lys_node_list *)dev_target->parent)->keys[i] == (struct lys_node_leaf *)dev_target) {
- LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, "not-supported", "deviation");
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "\"not-supported\" deviation cannot remove a list key.");
+ LOGVAL(module->ctx, LYE_INARG, LY_VLOG_NONE, NULL, "not-supported", "deviation");
+ LOGVAL(module->ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "\"not-supported\" deviation cannot remove a list key.");
goto error;
}
}
@@ -4451,7 +4474,7 @@
dev->orig_node = lys_node_dup(dev_target->module, NULL, dev_target, &tmp_unres, 1);
/* just to be safe */
if (tmp_unres.count) {
- LOGINT;
+ LOGINT(module->ctx);
goto error;
}
}
@@ -4490,8 +4513,8 @@
}
}
if (rc == -1) {
- LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default");
- LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL,
+ LOGVAL(module->ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, "default");
+ LOGVAL(module->ctx, LYE_SPEC, LY_VLOG_NONE, NULL,
"The default value \"%s\" of the deviated node \"%s\"no longer matches its type.",
target_name);
goto error;
@@ -4508,13 +4531,14 @@
mod->deviated = 1; /* main module */
parent->module->deviated = 1; /* possible submodule */
if (lys_set_implemented(mod)) {
- LOGERR(ly_errno, "Setting the deviated module \"%s\" implemented failed.", mod->name);
+ LOGERR(module->ctx, ly_errno, "Setting the deviated module \"%s\" implemented failed.", mod->name);
goto error;
}
}
}
return EXIT_SUCCESS;
+
error:
ly_set_free(dflt_check);
return EXIT_FAILURE;
@@ -4595,6 +4619,7 @@
}
return EXIT_SUCCESS;
+
error:
if (erase_identities) {
yang_free_ident_base(module->ident, 0, module->ident_size);
@@ -4637,11 +4662,11 @@
} else {
str = lys_ext_complex_get_substmt(stmt, ext, &info);
if (!str) {
- LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, arg_name, parent_name);
+ LOGVAL(module->ctx, LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, arg_name, parent_name);
goto error;
}
if (info->cardinality < LY_STMT_CARD_SOME && *str) {
- LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, arg_name, parent_name);
+ LOGVAL(module->ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, arg_name, parent_name);
goto error;
}
@@ -4651,15 +4676,15 @@
if (!p[0]) {
/* allocate initial array */
p[0] = calloc(2, sizeof(const char *));
- LY_CHECK_ERR_GOTO(!p[0], LOGMEM, error);
+ LY_CHECK_ERR_GOTO(!p[0], LOGMEM(module->ctx), error);
if (stmt == LY_STMT_BELONGSTO) {
/* allocate another array for the belongs-to's prefixes */
p[1] = calloc(2, sizeof(const char *));
- LY_CHECK_ERR_GOTO(!p[1], LOGMEM, error);
+ LY_CHECK_ERR_GOTO(!p[1], LOGMEM(module->ctx), error);
} else if (stmt == LY_STMT_ARGUMENT) {
/* allocate another array for the yin element */
((uint8_t **)p)[1] = calloc(2, sizeof(uint8_t));
- LY_CHECK_ERR_GOTO(!p[1], LOGMEM, error);
+ LY_CHECK_ERR_GOTO(!p[1], LOGMEM(module->ctx), error);
/* default value of yin element */
((uint8_t *)p[1])[0] = 2;
}
@@ -4677,7 +4702,7 @@
/* enlarge the array(s) */
reallocated = realloc(p[0], (c + 2) * sizeof(const char *));
if (!reallocated) {
- LOGMEM;
+ LOGMEM(module->ctx);
lydict_remove(module->ctx, p[0][c]);
p[0][c] = NULL;
return EXIT_FAILURE;
@@ -4689,7 +4714,7 @@
/* enlarge the second belongs-to's array with prefixes */
reallocated = realloc(p[1], (c + 2) * sizeof(const char *));
if (!reallocated) {
- LOGMEM;
+ LOGMEM(module->ctx);
lydict_remove(module->ctx, p[1][c]);
p[1][c] = NULL;
return EXIT_FAILURE;
@@ -4700,7 +4725,7 @@
/* enlarge the second argument's array with yin element */
reallocated = realloc(p[1], (c + 2) * sizeof(uint8_t));
if (!reallocated) {
- LOGMEM;
+ LOGMEM(module->ctx);
((uint8_t *)p[1])[c] = 0;
return EXIT_FAILURE;
}
@@ -4748,6 +4773,7 @@
yang_getplace_for_extcomplex_struct(struct lys_ext_instance_complex *ext, int *index,
char *parent_name, char *node_name, LY_STMT stmt)
{
+ struct ly_ctx *ctx = ext->module->ctx;
int c;
void **data, ***p = NULL;
void *reallocated;
@@ -4755,11 +4781,11 @@
data = lys_ext_complex_get_substmt(stmt, ext, &info);
if (!data) {
- LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, node_name, parent_name);
+ LOGVAL(ctx, LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, node_name, parent_name);
return NULL;
}
if (info->cardinality < LY_STMT_CARD_SOME && *data) {
- LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node_name, parent_name);
+ LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, node_name, parent_name);
return NULL;
}
@@ -4772,7 +4798,7 @@
if (!data) {
/* allocate initial array */
*p = data = calloc(2, sizeof(void *));
- LY_CHECK_ERR_RETURN(!data, LOGMEM, NULL);
+ LY_CHECK_ERR_RETURN(!data, LOGMEM(ctx), NULL);
} else {
for (c = 0; *data; data++, c++);
}
@@ -4781,7 +4807,7 @@
if (c) {
/* enlarge the array */
reallocated = realloc(*p, (c + 2) * sizeof(void *));
- LY_CHECK_ERR_RETURN(!reallocated, LOGMEM, NULL);
+ LY_CHECK_ERR_RETURN(!reallocated, LOGMEM(ctx), NULL);
*p = reallocated;
data = *p;
data[c + 1] = NULL;
@@ -4804,11 +4830,11 @@
data = lys_ext_complex_get_substmt(stmt, ext, &info);
if (!data) {
- LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, node_name, parent_name);
+ LOGVAL(ext->module->ctx, LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, node_name, parent_name);
return EXIT_FAILURE;
}
if (info->cardinality < LY_STMT_CARD_SOME && (*data & mask)) {
- LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node_name, parent_name);
+ LOGVAL(ext->module->ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, node_name, parent_name);
return EXIT_FAILURE;
}
@@ -4820,18 +4846,19 @@
yang_fill_extcomplex_uint8(struct lys_ext_instance_complex *ext, char *parent_name, char *node_name,
LY_STMT stmt, uint8_t value)
{
+ struct ly_ctx *ctx = ext->module->ctx;
uint8_t *val, **pp = NULL, *reallocated;
struct lyext_substmt *info;
int i = 0;
val = lys_ext_complex_get_substmt(stmt, ext, &info);
if (!val) {
- LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, node_name, parent_name);
+ LOGVAL(ctx, LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, node_name, parent_name);
return EXIT_FAILURE;
}
if (stmt == LY_STMT_DIGITS) {
if (info->cardinality < LY_STMT_CARD_SOME && *val) {
- LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node_name, parent_name);
+ LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, node_name, parent_name);
return EXIT_FAILURE;
}
@@ -4840,7 +4867,7 @@
pp = (uint8_t**)val;
if (!(*pp)) {
*pp = calloc(2, sizeof(uint8_t)); /* allocate initial array */
- LY_CHECK_ERR_RETURN(!*pp, LOGMEM, EXIT_FAILURE);
+ LY_CHECK_ERR_RETURN(!*pp, LOGMEM(ctx), EXIT_FAILURE);
} else {
for (i = 0; (*pp)[i]; i++);
}
@@ -4853,13 +4880,13 @@
if (i) {
/* enlarge the array */
reallocated = realloc(*pp, (i + 2) * sizeof *val);
- LY_CHECK_ERR_RETURN(!reallocated, LOGMEM, EXIT_FAILURE);
+ LY_CHECK_ERR_RETURN(!reallocated, LOGMEM(ctx), EXIT_FAILURE);
*pp = reallocated;
(*pp)[i + 1] = 0;
}
} else {
if (*val) {
- LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node_name, parent_name);
+ LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, node_name, parent_name);
return EXIT_FAILURE;
}
@@ -4868,7 +4895,7 @@
} else if (stmt == LY_STMT_MODIFIER) {
*val = 1;
} else {
- LOGINT;
+ LOGINT(ctx);
return EXIT_FAILURE;
}
}
@@ -4885,13 +4912,13 @@
snode = lys_ext_complex_get_substmt(stmt, ext, &info);
if (!snode) {
- LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, node_name, parent_name);
+ LOGVAL(ext->module->ctx, LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, node_name, parent_name);
return EXIT_FAILURE;
}
if (info->cardinality < LY_STMT_CARD_SOME) {
LY_TREE_FOR(node, siter) {
if (stmt == lys_snode2stmt(siter->nodetype)) {
- LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node_name, parent_name);
+ LOGVAL(ext->module->ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, node_name, parent_name);
return EXIT_FAILURE;
}
}
@@ -4913,14 +4940,14 @@
}
pp = modules = lys_ext_complex_get_substmt(LY_STMT_MODULE, ext, &info);
if (!modules) {
- LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "module", parent_name);
+ LOGVAL(ctx, LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "module", parent_name);
return EXIT_FAILURE;
}
for (i = 0; values[i]; ++i) {
c = 0;
if (info->cardinality < LY_STMT_CARD_SOME && *modules) {
- LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, "module", parent_name);
+ LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, "module", parent_name);
return EXIT_FAILURE;
}
if (info->cardinality >= LY_STMT_CARD_SOME) {
@@ -4931,7 +4958,7 @@
if (!modules) {
/* allocate initial array */
*p = modules = calloc(2, sizeof(struct lys_module *));
- LY_CHECK_ERR_RETURN(!*p, LOGMEM, EXIT_FAILURE);
+ LY_CHECK_ERR_RETURN(!*p, LOGMEM(ctx), EXIT_FAILURE);
} else {
for (c = 0; *modules; modules++, c++);
}
@@ -4940,7 +4967,7 @@
if (c) {
/* enlarge the array */
reallocated = realloc(*p, (c + 2) * sizeof(struct lys_module *));
- LY_CHECK_ERR_RETURN(!reallocated, LOGMEM, EXIT_FAILURE);
+ LY_CHECK_ERR_RETURN(!reallocated, LOGMEM(ctx), EXIT_FAILURE);
*p = (struct lys_module **)reallocated;
modules = *p;
modules[c + 1] = NULL;