Skip to content

Commit 43acca4

Browse files
committed
tree schema UPDATE new internal ietf-netconf rpc-error nodes
Printer support added.
1 parent 79fb578 commit 43acca4

File tree

4 files changed

+159
-5
lines changed

4 files changed

+159
-5
lines changed

src/printer_tree.c

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ struct trt_fp_read {
590590
.module_name = tro_read_module_name, \
591591
.node = troc_read_node, \
592592
.if_sibling_exists = troc_read_if_sibling_exists, \
593-
.if_parent_exists = tro_read_if_sibling_exists \
593+
.if_parent_exists = tro_read_if_parent_exists \
594594
}
595595

596596
/**
@@ -601,7 +601,7 @@ struct trt_fp_read {
601601
.module_name = tro_read_module_name, \
602602
.node = trop_read_node, \
603603
.if_sibling_exists = trop_read_if_sibling_exists, \
604-
.if_parent_exists = tro_read_if_sibling_exists \
604+
.if_parent_exists = tro_read_if_parent_exists \
605605
}
606606

607607
/**********************************************************************
@@ -781,6 +781,7 @@ typedef const char *(*trt_get_charptr_func)(const struct lysp_node *pn);
781781
*/
782782
struct tro_getters {
783783
uint16_t (*nodetype)(const void *); /**< Get nodetype. */
784+
uint16_t (*lysp_flags)(const void *); /**< Get flags from lysp_node. */
784785
const void *(*next)(const void *); /**< Get sibling. */
785786
const void *(*parent)(const void *); /**< Get parent. */
786787
const void *(*child)(const void *); /**< Get child. */
@@ -1947,6 +1948,16 @@ trop_nodetype(const void *node)
19471948
return ((const struct lysp_node *)node)->nodetype;
19481949
}
19491950

1951+
/**
1952+
* @brief Get lysp_node flags.
1953+
* @param[in] node is any lysp_node.
1954+
*/
1955+
static uint16_t
1956+
trop_flags(const void *node)
1957+
{
1958+
return ((const struct lysp_node *)node)->flags;
1959+
}
1960+
19501961
/**
19511962
* @brief Get sibling.
19521963
* @param[in] node is any lysp_node.
@@ -2026,6 +2037,7 @@ trop_init_getters(void)
20262037
{
20272038
return (struct tro_getters) {
20282039
.nodetype = trop_nodetype,
2040+
.lysp_flags = trop_flags,
20292041
.next = trop_next,
20302042
.parent = trop_parent,
20312043
.child = trop_child,
@@ -2046,6 +2058,23 @@ troc_nodetype(const void *node)
20462058
return ((const struct lysc_node *)node)->nodetype;
20472059
}
20482060

2061+
/**
2062+
* @brief Get lysp_node flags.
2063+
* @param[in] node is any lysc_node.
2064+
*/
2065+
static uint16_t
2066+
troc_lysp_flags(const void *node)
2067+
{
2068+
const struct lysc_node *cn;
2069+
2070+
cn = (const struct lysc_node *)node;
2071+
if (TRP_TREE_CTX_LYSP_NODE_PRESENT(cn)) {
2072+
return TRP_TREE_CTX_GET_LYSP_NODE(cn)->flags;
2073+
} else {
2074+
return 0;
2075+
}
2076+
}
2077+
20492078
/**
20502079
* @brief Get sibling.
20512080
* @param[in] node is any lysc_node.
@@ -2125,6 +2154,7 @@ troc_init_getters(void)
21252154
{
21262155
return (struct tro_getters) {
21272156
.nodetype = troc_nodetype,
2157+
.lysp_flags = troc_lysp_flags,
21282158
.next = troc_next,
21292159
.parent = troc_parent,
21302160
.child = troc_child,
@@ -2272,6 +2302,8 @@ tro_next_sibling(const void *node, const struct trt_tree_ctx *tc)
22722302
plugin_ctx = tc->plugin_ctx;
22732303
if (sibl && tro_set_node_overr(tc->lysc_tree, sibl, 1, &plugin_ctx) && plugin_ctx.filtered) {
22742304
return tro_next_sibling(sibl, tc);
2305+
} else if (sibl && (get.lysp_flags(node) & LYS_INTERNAL)) {
2306+
return tro_next_sibling(sibl, tc);
22752307
}
22762308

22772309
return sibl;
@@ -2328,6 +2360,8 @@ tro_next_child(const void *node, const struct trt_tree_ctx *tc)
23282360
plugin_ctx = tc->plugin_ctx;
23292361
if (child && tro_set_node_overr(tc->lysc_tree, child, 1, &plugin_ctx) && plugin_ctx.filtered) {
23302362
return tro_next_sibling(child, tc);
2363+
} else if (child && (get.lysp_flags(node) & LYS_INTERNAL)) {
2364+
return tro_next_sibling(child, tc);
23312365
}
23322366

23332367
return child;
@@ -2605,7 +2639,7 @@ tro_read_module_name(const struct trt_tree_ctx *tc)
26052639
}
26062640

26072641
static ly_bool
2608-
tro_read_if_sibling_exists(const struct trt_tree_ctx *tc)
2642+
tro_read_if_parent_exists(const struct trt_tree_ctx *tc)
26092643
{
26102644
const void *parent;
26112645

@@ -3118,7 +3152,11 @@ trop_modi_first_sibling(struct trt_parent_cache ca, struct trt_tree_ctx *tc)
31183152
default:
31193153
assert(0);
31203154
}
3121-
node = trop_read_node(ca, tc);
3155+
if (tc->pn && (trop_flags(tc->pn) & LYS_INTERNAL)) {
3156+
node = trop_modi_next_sibling(ca, tc);
3157+
} else {
3158+
node = trop_read_node(ca, tc);
3159+
}
31223160
}
31233161

31243162
if (tc->plugin_ctx.filtered) {
@@ -3440,7 +3478,11 @@ troc_modi_first_sibling(struct trt_parent_cache ca, struct trt_tree_ctx *tc)
34403478
default:
34413479
assert(0);
34423480
}
3443-
node = troc_read_node(ca, tc);
3481+
if (tc->cn && (troc_lysp_flags(tc->cn) & LYS_INTERNAL)) {
3482+
node = troc_modi_next_sibling(ca, tc);
3483+
} else {
3484+
node = troc_read_node(ca, tc);
3485+
}
34443486
}
34453487

34463488
if (tc->plugin_ctx.filtered) {

src/printer_yang.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2269,6 +2269,10 @@ yang_print_parsed_body(struct lys_ypr_ctx *pctx, const struct lysp_module *modp)
22692269
YPR_EXTRA_LINE(modp->groupings, pctx);
22702270

22712271
LY_LIST_FOR(modp->data, data) {
2272+
if (data->flags & LYS_INTERNAL) {
2273+
continue;
2274+
}
2275+
22722276
YPR_EXTRA_LINE_PRINT(pctx);
22732277
yprp_node(pctx, data);
22742278
}

src/printer_yin.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,6 +1367,10 @@ yin_print_parsed_body(struct lys_ypr_ctx *pctx, const struct lysp_module *modp)
13671367
}
13681368

13691369
LY_LIST_FOR(modp->data, data) {
1370+
if (data->flags & LYS_INTERNAL) {
1371+
continue;
1372+
}
1373+
13701374
yprp_node(pctx, data);
13711375
}
13721376

src/tree_schema.c

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,6 +1653,9 @@ lysp_add_internal_ietf_netconf(struct lysp_ctx *pctx, struct lysp_module *mod)
16531653
{
16541654
struct lysp_ext_instance *extp, *prev_exts = mod->exts;
16551655
struct lysp_stmt *stmt;
1656+
struct lysp_node_leaf *leaf;
1657+
struct lysp_node_container *cont;
1658+
struct lysp_type_enum *enm;
16561659
struct lysp_import *imp;
16571660
uint32_t idx;
16581661

@@ -1806,6 +1809,107 @@ lysp_add_internal_ietf_netconf(struct lysp_ctx *pctx, struct lysp_module *mod)
18061809
pctx->ext_inst.objs[idx] = mod->exts;
18071810
}
18081811

1812+
/*
1813+
* 4) rpc-error
1814+
*/
1815+
LY_LIST_NEW_RET(mod->mod->ctx, &mod->data, cont, next, LY_EMEM);
1816+
cont->nodetype = LYS_CONTAINER;
1817+
LY_CHECK_RET(lydict_insert(mod->mod->ctx, "rpc-error", 0, &cont->name));
1818+
LY_CHECK_RET(lydict_insert(mod->mod->ctx, "presence", 0, &cont->presence));
1819+
cont->flags = LYS_INTERNAL;
1820+
1821+
LY_LIST_NEW_RET(mod->mod->ctx, &cont->child, leaf, next, LY_EMEM);
1822+
leaf->nodetype = LYS_LEAF;
1823+
LY_CHECK_RET(lydict_insert(mod->mod->ctx, "error-type", 0, &leaf->name));
1824+
leaf->flags = LYS_INTERNAL;
1825+
LY_CHECK_RET(lydict_insert(mod->mod->ctx, "enumeration", 0, &leaf->type.name));
1826+
leaf->type.pmod = mod;
1827+
leaf->type.flags = LYS_SET_ENUM;
1828+
LY_ARRAY_NEW_RET(mod->mod->ctx, leaf->type.enums, enm, LY_EMEM);
1829+
LY_CHECK_RET(lydict_insert(mod->mod->ctx, "transport", 0, &enm->name));
1830+
LY_ARRAY_NEW_RET(mod->mod->ctx, leaf->type.enums, enm, LY_EMEM);
1831+
LY_CHECK_RET(lydict_insert(mod->mod->ctx, "rpc", 0, &enm->name));
1832+
LY_ARRAY_NEW_RET(mod->mod->ctx, leaf->type.enums, enm, LY_EMEM);
1833+
LY_CHECK_RET(lydict_insert(mod->mod->ctx, "protocol", 0, &enm->name));
1834+
LY_ARRAY_NEW_RET(mod->mod->ctx, leaf->type.enums, enm, LY_EMEM);
1835+
LY_CHECK_RET(lydict_insert(mod->mod->ctx, "application", 0, &enm->name));
1836+
1837+
LY_LIST_NEW_RET(mod->mod->ctx, &cont->child, leaf, next, LY_EMEM);
1838+
leaf->nodetype = LYS_LEAF;
1839+
LY_CHECK_RET(lydict_insert(mod->mod->ctx, "error-tag", 0, &leaf->name));
1840+
leaf->flags = LYS_INTERNAL;
1841+
LY_CHECK_RET(lydict_insert(mod->mod->ctx, "enumeration", 0, &leaf->type.name));
1842+
leaf->type.pmod = mod;
1843+
leaf->type.flags = LYS_SET_ENUM;
1844+
LY_ARRAY_NEW_RET(mod->mod->ctx, leaf->type.enums, enm, LY_EMEM);
1845+
LY_CHECK_RET(lydict_insert(mod->mod->ctx, "in-use", 0, &enm->name));
1846+
LY_ARRAY_NEW_RET(mod->mod->ctx, leaf->type.enums, enm, LY_EMEM);
1847+
LY_CHECK_RET(lydict_insert(mod->mod->ctx, "invalid-value", 0, &enm->name));
1848+
LY_ARRAY_NEW_RET(mod->mod->ctx, leaf->type.enums, enm, LY_EMEM);
1849+
LY_CHECK_RET(lydict_insert(mod->mod->ctx, "too-big", 0, &enm->name));
1850+
LY_ARRAY_NEW_RET(mod->mod->ctx, leaf->type.enums, enm, LY_EMEM);
1851+
LY_CHECK_RET(lydict_insert(mod->mod->ctx, "missing-attribute", 0, &enm->name));
1852+
LY_ARRAY_NEW_RET(mod->mod->ctx, leaf->type.enums, enm, LY_EMEM);
1853+
LY_CHECK_RET(lydict_insert(mod->mod->ctx, "bad-attribute", 0, &enm->name));
1854+
LY_ARRAY_NEW_RET(mod->mod->ctx, leaf->type.enums, enm, LY_EMEM);
1855+
LY_CHECK_RET(lydict_insert(mod->mod->ctx, "unknown-attribute", 0, &enm->name));
1856+
LY_ARRAY_NEW_RET(mod->mod->ctx, leaf->type.enums, enm, LY_EMEM);
1857+
LY_CHECK_RET(lydict_insert(mod->mod->ctx, "missing-element", 0, &enm->name));
1858+
LY_ARRAY_NEW_RET(mod->mod->ctx, leaf->type.enums, enm, LY_EMEM);
1859+
LY_CHECK_RET(lydict_insert(mod->mod->ctx, "bad-element", 0, &enm->name));
1860+
LY_ARRAY_NEW_RET(mod->mod->ctx, leaf->type.enums, enm, LY_EMEM);
1861+
LY_CHECK_RET(lydict_insert(mod->mod->ctx, "unknown-element", 0, &enm->name));
1862+
LY_ARRAY_NEW_RET(mod->mod->ctx, leaf->type.enums, enm, LY_EMEM);
1863+
LY_CHECK_RET(lydict_insert(mod->mod->ctx, "unknown-namespace", 0, &enm->name));
1864+
LY_ARRAY_NEW_RET(mod->mod->ctx, leaf->type.enums, enm, LY_EMEM);
1865+
LY_CHECK_RET(lydict_insert(mod->mod->ctx, "access-denied", 0, &enm->name));
1866+
LY_ARRAY_NEW_RET(mod->mod->ctx, leaf->type.enums, enm, LY_EMEM);
1867+
LY_CHECK_RET(lydict_insert(mod->mod->ctx, "lock-denied", 0, &enm->name));
1868+
LY_ARRAY_NEW_RET(mod->mod->ctx, leaf->type.enums, enm, LY_EMEM);
1869+
LY_CHECK_RET(lydict_insert(mod->mod->ctx, "resource-denied", 0, &enm->name));
1870+
LY_ARRAY_NEW_RET(mod->mod->ctx, leaf->type.enums, enm, LY_EMEM);
1871+
LY_CHECK_RET(lydict_insert(mod->mod->ctx, "rollback-failed", 0, &enm->name));
1872+
LY_ARRAY_NEW_RET(mod->mod->ctx, leaf->type.enums, enm, LY_EMEM);
1873+
LY_CHECK_RET(lydict_insert(mod->mod->ctx, "data-exists", 0, &enm->name));
1874+
LY_ARRAY_NEW_RET(mod->mod->ctx, leaf->type.enums, enm, LY_EMEM);
1875+
LY_CHECK_RET(lydict_insert(mod->mod->ctx, "data-missing", 0, &enm->name));
1876+
LY_ARRAY_NEW_RET(mod->mod->ctx, leaf->type.enums, enm, LY_EMEM);
1877+
LY_CHECK_RET(lydict_insert(mod->mod->ctx, "operation-not-supported", 0, &enm->name));
1878+
LY_ARRAY_NEW_RET(mod->mod->ctx, leaf->type.enums, enm, LY_EMEM);
1879+
LY_CHECK_RET(lydict_insert(mod->mod->ctx, "operation-failed", 0, &enm->name));
1880+
LY_ARRAY_NEW_RET(mod->mod->ctx, leaf->type.enums, enm, LY_EMEM);
1881+
LY_CHECK_RET(lydict_insert(mod->mod->ctx, "partial-operation", 0, &enm->name));
1882+
LY_ARRAY_NEW_RET(mod->mod->ctx, leaf->type.enums, enm, LY_EMEM);
1883+
LY_CHECK_RET(lydict_insert(mod->mod->ctx, "malformed-message", 0, &enm->name));
1884+
1885+
LY_LIST_NEW_RET(mod->mod->ctx, &cont->child, leaf, next, LY_EMEM);
1886+
leaf->nodetype = LYS_LEAF;
1887+
LY_CHECK_RET(lydict_insert(mod->mod->ctx, "error-severity", 0, &leaf->name));
1888+
leaf->flags = LYS_INTERNAL;
1889+
LY_CHECK_RET(lydict_insert(mod->mod->ctx, "enumeration", 0, &leaf->type.name));
1890+
leaf->type.pmod = mod;
1891+
leaf->type.flags = LYS_SET_ENUM;
1892+
LY_ARRAY_NEW_RET(mod->mod->ctx, leaf->type.enums, enm, LY_EMEM);
1893+
LY_CHECK_RET(lydict_insert(mod->mod->ctx, "error", 0, &enm->name));
1894+
LY_ARRAY_NEW_RET(mod->mod->ctx, leaf->type.enums, enm, LY_EMEM);
1895+
LY_CHECK_RET(lydict_insert(mod->mod->ctx, "warning", 0, &enm->name));
1896+
1897+
LY_LIST_NEW_RET(mod->mod->ctx, &cont->child, leaf, next, LY_EMEM);
1898+
leaf->nodetype = LYS_LEAF;
1899+
LY_CHECK_RET(lydict_insert(mod->mod->ctx, "error-app-tag", 0, &leaf->name));
1900+
leaf->flags = LYS_INTERNAL;
1901+
LY_CHECK_RET(lydict_insert(mod->mod->ctx, "string", 0, &leaf->type.name));
1902+
leaf->type.pmod = mod;
1903+
1904+
LY_LIST_NEW_RET(mod->mod->ctx, &cont->child, leaf, next, LY_EMEM);
1905+
leaf->nodetype = LYS_LEAF;
1906+
LY_CHECK_RET(lydict_insert(mod->mod->ctx, "error-path", 0, &leaf->name));
1907+
leaf->flags = LYS_INTERNAL;
1908+
LY_CHECK_RET(lydict_insert(mod->mod->ctx, "yang_:xpath1.0", 0, &leaf->type.name));
1909+
leaf->type.pmod = mod;
1910+
1911+
/* the rest are opaque nodes, error-message (because of 'xml:lang' attribute) and error-info (because can be any nodes) */
1912+
18091913
/* create new imports for the used prefixes */
18101914
LY_ARRAY_NEW_RET(mod->mod->ctx, mod->imports, imp, LY_EMEM);
18111915
LY_CHECK_RET(lydict_insert(mod->mod->ctx, "ietf-yang-metadata", 0, &imp->name));

0 commit comments

Comments
 (0)