Skip to content

Commit c574ce3

Browse files
committed
tree schema UPDATE store YANG version in main mod struct
1 parent 4e79679 commit c574ce3

File tree

4 files changed

+34
-10
lines changed

4 files changed

+34
-10
lines changed

src/printer_context.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1740,6 +1740,7 @@ ctxp_module(const struct lys_module *orig_mod, struct lys_module *mod, struct ly
17401740
/* flags */
17411741
mod->implemented = orig_mod->implemented;
17421742
mod->to_compile = orig_mod->to_compile;
1743+
mod->version = orig_mod->version;
17431744
mod->latest_revision = orig_mod->latest_revision;
17441745
}
17451746

src/schema_features.c

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -217,20 +217,31 @@ LIBYANG_API_DEF LY_ERR
217217
lys_feature_value(const struct lys_module *module, const char *feature)
218218
{
219219
const struct lysp_feature *f;
220+
LY_ARRAY_COUNT_TYPE u;
220221

221-
LY_CHECK_ARG_RET(NULL, module, module->parsed, feature, LY_EINVAL);
222+
LY_CHECK_ARG_RET(NULL, module, module->parsed || module->compiled, feature, !strchr(feature, ':'), LY_EINVAL);
222223

223-
/* search for the specified feature */
224-
f = lysp_feature_find(module->parsed, feature, strlen(feature), 0);
225-
LY_CHECK_RET(!f, LY_ENOTFOUND);
224+
if (module->parsed) {
225+
/* search for the specified feature */
226+
f = lysp_feature_find(module->parsed, feature, strlen(feature), 0);
227+
LY_CHECK_RET(!f, LY_ENOTFOUND);
226228

227-
/* feature disabled */
228-
if (!(f->flags & LYS_FENABLED)) {
229-
return LY_ENOT;
229+
/* feature enabled */
230+
if (f->flags & LYS_FENABLED) {
231+
return LY_SUCCESS;
232+
}
233+
} else {
234+
/* find the feature in the compiled enabled features */
235+
LY_ARRAY_FOR(module->compiled->features, u) {
236+
if (!strcmp(module->compiled->features[u], feature)) {
237+
/* feature enabled */
238+
return LY_SUCCESS;
239+
}
240+
}
230241
}
231242

232-
/* feature enabled */
233-
return LY_SUCCESS;
243+
/* feature disabled */
244+
return LY_ENOT;
234245
}
235246

236247
/**

src/tree_schema.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2066,6 +2066,17 @@ lys_parse_in(struct ly_ctx *ctx, struct ly_in *in, LYS_INFORMAT format, const st
20662066
LY_CHECK_GOTO(rc = lysdict_insert(ctx, mod->parsed->revs[0].date, 0, &mod->revision), cleanup);
20672067
}
20682068

2069+
/* set YANG version */
2070+
switch (mod->parsed->version) {
2071+
case LYS_VERSION_UNDEF:
2072+
case LYS_VERSION_1_0:
2073+
mod->version = LYS_VERSION_1_0;
2074+
break;
2075+
case LYS_VERSION_1_1:
2076+
mod->version = LYS_VERSION_1_1;
2077+
break;
2078+
}
2079+
20692080
/* decide the latest revision */
20702081
latest = ly_ctx_get_module_latest(ctx, mod->name);
20712082
if (latest) {

src/tree_schema.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2194,7 +2194,8 @@ struct lys_module {
21942194
ly_bool implemented; /**< flag if the module is implemented, not just imported */
21952195
ly_bool to_compile; /**< flag marking a module that was changed but not (re)compiled, see
21962196
::LY_CTX_EXPLICIT_COMPILE. */
2197-
uint8_t latest_revision; /**< Flag to mark the latest available revision,
2197+
uint8_t version : 2; /**< yang-version (LYS_VERSION values) */
2198+
uint8_t latest_revision : 4; /**< Flag to mark the latest available revision,
21982199
see [latest_revision options](@ref latestrevflags). */
21992200
};
22002201

0 commit comments

Comments
 (0)