From b5f1f7346e31307c26a3fbd2c357b25cb59361a5 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Tue, 2 Apr 2019 12:27:33 +0200 Subject: [PATCH] Structural C-code change: Merged yang_spec and yang_node types into yang_stmt --- CHANGELOG.md | 3 + apps/backend/backend_client.c | 12 +- apps/backend/backend_commit.c | 6 +- apps/backend/backend_main.c | 8 +- apps/backend/backend_plugin.c | 2 +- apps/backend/backend_plugin.h | 2 +- apps/backend/backend_startup.c | 2 +- apps/backend/backend_startup.h | 2 +- apps/cli/cli_common.c | 6 +- apps/cli/cli_generate.c | 20 +- apps/cli/cli_generate.h | 2 +- apps/cli/cli_main.c | 6 +- apps/cli/cli_show.c | 20 +- apps/netconf/netconf_main.c | 8 +- apps/netconf/netconf_rpc.c | 10 +- apps/restconf/restconf_lib.c | 2 +- apps/restconf/restconf_main.c | 4 +- apps/restconf/restconf_methods.c | 36 +-- example/main/example_backend.c | 4 +- lib/clixon/clixon_data.h | 8 +- lib/clixon/clixon_json.h | 4 +- lib/clixon/clixon_netconf_lib.h | 2 +- lib/clixon/clixon_options.h | 2 +- lib/clixon/clixon_proto.h | 2 +- lib/clixon/clixon_xml.h | 8 +- lib/clixon/clixon_xml_map.h | 12 +- lib/clixon/clixon_xml_sort.h | 2 +- lib/clixon/clixon_yang.h | 84 +++---- lib/clixon/clixon_yang_module.h | 2 +- lib/src/clixon_data.c | 16 +- lib/src/clixon_datastore_read.c | 10 +- lib/src/clixon_datastore_read.h | 2 +- lib/src/clixon_datastore_write.c | 20 +- lib/src/clixon_json.c | 6 +- lib/src/clixon_netconf_lib.c | 4 +- lib/src/clixon_options.c | 4 +- lib/src/clixon_proto.c | 2 +- lib/src/clixon_proto_client.c | 2 +- lib/src/clixon_stream.c | 4 +- lib/src/clixon_xml.c | 8 +- lib/src/clixon_xml_changelog.c | 2 +- lib/src/clixon_xml_map.c | 112 ++++----- lib/src/clixon_xml_parse.h | 2 +- lib/src/clixon_xml_sort.c | 24 +- lib/src/clixon_yang.c | 389 +++++++++++++++--------------- lib/src/clixon_yang_cardinality.c | 4 +- lib/src/clixon_yang_module.c | 36 +-- lib/src/clixon_yang_parse.h | 8 +- lib/src/clixon_yang_parse.y | 8 +- lib/src/clixon_yang_type.c | 38 +-- util/clixon_util_datastore.c | 2 +- util/clixon_util_yang.c | 4 +- 52 files changed, 492 insertions(+), 496 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd925207..0c27f1fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,9 @@ ### API changes on existing features (you may need to change your code) +* Structural C-code change: Merged yang_spec and yang_node types into yang_stmt + * Change all yn_* and yp_ to ys_* + * Change all references to yang_node/yang_spec to yang_stmt * Structural change: removed datastore plugin and directory, and merged into regulat clixon lib code. * The CLICON_XMLDB_PLUGIN config option is obsolete, you should remove it from your config file * The datastore directory is removed, code is moved to lib/src/clixon_datastore*.c diff --git a/apps/backend/backend_client.c b/apps/backend/backend_client.c index 16855189..9658e4ac 100644 --- a/apps/backend/backend_client.c +++ b/apps/backend/backend_client.c @@ -163,7 +163,7 @@ backend_client_rm(clicon_handle h, */ static int client_get_streams(clicon_handle h, - yang_spec *yspec, + yang_stmt *yspec, char *xpath, char *module, char *top, @@ -175,11 +175,11 @@ client_get_streams(clicon_handle h, cxobj *x = NULL; cbuf *cb = NULL; - if ((ystream = yang_find((yang_node*)yspec, Y_MODULE, module)) == NULL){ + if ((ystream = yang_find(yspec, Y_MODULE, module)) == NULL){ clicon_err(OE_YANG, 0, "%s yang module not found", module); goto done; } - if ((yns = yang_find((yang_node*)ystream, Y_NAMESPACE, NULL)) == NULL){ + if ((yns = yang_find(ystream, Y_NAMESPACE, NULL)) == NULL){ clicon_err(OE_YANG, 0, "%s yang namespace not found", module); goto done; } @@ -224,7 +224,7 @@ client_statedata(clicon_handle h, cxobj **xvec = NULL; size_t xlen; int i; - yang_spec *yspec; + yang_stmt *yspec; if ((yspec = clicon_dbspec_yang(h)) == NULL){ clicon_err(OE_YANG, ENOENT, "No yang spec"); @@ -379,7 +379,7 @@ from_client_edit_config(clicon_handle h, enum operation_type operation = OP_MERGE; int piddb; int non_config = 0; - yang_spec *yspec; + yang_stmt *yspec; cbuf *cbx = NULL; /* Assist cbuf */ int ret; char *username; @@ -1061,7 +1061,7 @@ from_client_msg(clicon_handle h, cbuf *cbret = NULL; /* return message */ int ret; char *username; - yang_spec *yspec; + yang_stmt *yspec; yang_stmt *ye; yang_stmt *ymod; cxobj *xnacm = NULL; diff --git a/apps/backend/backend_commit.c b/apps/backend/backend_commit.c index deffd9fd..561b9956 100644 --- a/apps/backend/backend_commit.c +++ b/apps/backend/backend_commit.c @@ -87,7 +87,7 @@ * @retval 1 Validation OK */ static int -generic_validate(yang_spec *yspec, +generic_validate(yang_stmt *yspec, transaction_data_t *td, cbuf *cbret) { @@ -168,7 +168,7 @@ startup_common(clicon_handle h, cbuf *cbret) { int retval = -1; - yang_spec *yspec; + yang_stmt *yspec; int ret; modstate_diff_t *msd = NULL; cxobj *xt = NULL; @@ -341,7 +341,7 @@ from_validate_common(clicon_handle h, cbuf *cbret) { int retval = -1; - yang_spec *yspec; + yang_stmt *yspec; int i; cxobj *xn; int ret; diff --git a/apps/backend/backend_main.c b/apps/backend/backend_main.c index cb2ec8d9..1cac8931 100644 --- a/apps/backend/backend_main.c +++ b/apps/backend/backend_main.c @@ -85,7 +85,7 @@ static int backend_terminate(clicon_handle h) { - yang_spec *yspec; + yang_stmt *yspec; char *pidfile = clicon_backend_pidfile(h); int sockfamily = clicon_sock_family(h); char *sockpath = clicon_sock(h); @@ -174,7 +174,7 @@ nacm_load_external(clicon_handle h) { int retval = -1; char *filename; /* NACM config file */ - yang_spec *yspec = NULL; + yang_stmt *yspec = NULL; cxobj *xt = NULL; struct stat st; FILE *f = NULL; @@ -325,8 +325,8 @@ main(int argc, int sockfamily; char *nacm_mode; int logdst = CLICON_LOG_SYSLOG|CLICON_LOG_STDERR; - yang_spec *yspec = NULL; - yang_spec *yspecfg = NULL; /* For config XXX clixon bug */ + yang_stmt *yspec = NULL; + yang_stmt *yspecfg = NULL; /* For config XXX clixon bug */ char *str; int ss = -1; /* server socket */ cbuf *cbret = NULL; /* startup cbuf if invalid */ diff --git a/apps/backend/backend_plugin.c b/apps/backend/backend_plugin.c index 6fd3b2da..19b98c7e 100644 --- a/apps/backend/backend_plugin.c +++ b/apps/backend/backend_plugin.c @@ -121,7 +121,7 @@ clixon_plugin_reset(clicon_handle h, */ int clixon_plugin_statedata(clicon_handle h, - yang_spec *yspec, + yang_stmt *yspec, char *xpath, cxobj **xret) { diff --git a/apps/backend/backend_plugin.h b/apps/backend/backend_plugin.h index 638b3287..6b4643e3 100644 --- a/apps/backend/backend_plugin.h +++ b/apps/backend/backend_plugin.h @@ -71,7 +71,7 @@ int backend_plugin_initiate(clicon_handle h); int clixon_plugin_reset(clicon_handle h, char *db); -int clixon_plugin_statedata(clicon_handle h, yang_spec *yspec, char *xpath, cxobj **xtop); +int clixon_plugin_statedata(clicon_handle h, yang_stmt *yspec, char *xpath, cxobj **xtop); transaction_data_t * transaction_new(void); int transaction_free(transaction_data_t *); diff --git a/apps/backend/backend_startup.c b/apps/backend/backend_startup.c index 17ead1cc..c59f1736 100644 --- a/apps/backend/backend_startup.c +++ b/apps/backend/backend_startup.c @@ -327,7 +327,7 @@ startup_failsafe(clicon_handle h) */ int startup_module_state(clicon_handle h, - yang_spec *yspec) + yang_stmt *yspec) { int retval = -1; cxobj *x = NULL; diff --git a/apps/backend/backend_startup.h b/apps/backend/backend_startup.h index 01fc8fea..7eed20a6 100644 --- a/apps/backend/backend_startup.h +++ b/apps/backend/backend_startup.h @@ -44,6 +44,6 @@ int startup_db_reset(clicon_handle h, char *db); int startup_mode_startup(clicon_handle h, char *db, cbuf *cbret); int startup_extraxml(clicon_handle h, char *file, cbuf *cbret); int startup_failsafe(clicon_handle h); -int startup_module_state(clicon_handle h, yang_spec *yspec); +int startup_module_state(clicon_handle h, yang_stmt *yspec); #endif /* _BACKEND_STARTUP_H_ */ diff --git a/apps/cli/cli_common.c b/apps/cli/cli_common.c index 8a52207e..c75921cf 100644 --- a/apps/cli/cli_common.c +++ b/apps/cli/cli_common.c @@ -213,9 +213,9 @@ cli_dbxml(clicon_handle h, int len; cg_var *arg; cbuf *cb = NULL; - yang_spec *yspec; + yang_stmt *yspec; cxobj *xbot = NULL; /* xpath, NULL if datastore */ - yang_node *y = NULL; /* yang spec of xpath */ + yang_stmt *y = NULL; /* yang spec of xpath */ cxobj *xtop = NULL; /* xpath root */ cxobj *xa; /* attribute */ cxobj *xb; /* body */ @@ -243,7 +243,7 @@ cli_dbxml(clicon_handle h, xml_type_set(xa, CX_ATTR); if (xml_value_set(xa, xml_operation2str(op)) < 0) goto done; - if (y->yn_keyword != Y_LIST && y->yn_keyword != Y_LEAF_LIST){ + if (y->ys_keyword != Y_LIST && y->ys_keyword != Y_LEAF_LIST){ len = cvec_len(cvv); if (len > 1){ cval = cvec_i(cvv, len-1); diff --git a/apps/cli/cli_generate.c b/apps/cli/cli_generate.c index 178e0748..61eb90f9 100644 --- a/apps/cli/cli_generate.c +++ b/apps/cli/cli_generate.c @@ -190,7 +190,7 @@ yang2cli_var_identityref(yang_stmt *ys, cprintf(cb, ">"); if (helptext) cprintf(cb, "(\"%s\")", helptext); - if ((ybaseref = yang_find((yang_node*)ytype, Y_BASE, NULL)) != NULL && + if ((ybaseref = yang_find(ytype, Y_BASE, NULL)) != NULL && (ybaseid = yang_find_identity(ys, ybaseref->ys_argument)) != NULL){ if (cvec_len(ybaseid->ys_cvec) > 0){ cprintf(cb, "|<%s:%s choice:", ys->ys_argument, cvtypestr); @@ -329,7 +329,7 @@ yang2cli_var_sub(clicon_handle h, cprintf(cb, " choice:"); i = 0; yi = NULL; - while ((yi = yn_each((yang_node*)ytype, yi)) != NULL){ + while ((yi = yn_each(ytype, yi)) != NULL){ if (yi->ys_keyword != Y_ENUM && yi->ys_keyword != Y_BIT) continue; if (i) @@ -443,7 +443,7 @@ yang2cli_var_union(clicon_handle h, * not resolved types (unless they are built-in, but the resolve call is * made in the union_one call. */ - while ((ytsub = yn_each((yang_node*)ytype, ytsub)) != NULL){ + while ((ytsub = yn_each(ytype, ytsub)) != NULL){ if (ytsub->ys_keyword != Y_TYPE) continue; if (i++) @@ -563,7 +563,7 @@ yang2cli_leaf(clicon_handle h, char *s; /* description */ - if ((yd = yang_find((yang_node*)ys, Y_DESCRIPTION, NULL)) != NULL){ + if ((yd = yang_find(ys, Y_DESCRIPTION, NULL)) != NULL){ if ((helptext = strdup(yd->ys_argument)) == NULL){ clicon_err(OE_UNIX, errno, "strdup"); goto done; @@ -618,7 +618,7 @@ yang2cli_container(clicon_handle h, char *s; cprintf(cb, "%*s%s", level*3, "", ys->ys_argument); - if ((yd = yang_find((yang_node*)ys, Y_DESCRIPTION, NULL)) != NULL){ + if ((yd = yang_find(ys, Y_DESCRIPTION, NULL)) != NULL){ if ((helptext = strdup(yd->ys_argument)) == NULL){ clicon_err(OE_UNIX, errno, "strdup"); goto done; @@ -668,7 +668,7 @@ yang2cli_list(clicon_handle h, char *s; cprintf(cb, "%*s%s", level*3, "", ys->ys_argument); - if ((yd = yang_find((yang_node*)ys, Y_DESCRIPTION, NULL)) != NULL){ + if ((yd = yang_find(ys, Y_DESCRIPTION, NULL)) != NULL){ if ((helptext = strdup(yd->ys_argument)) == NULL){ clicon_err(OE_UNIX, errno, "strdup"); goto done; @@ -683,7 +683,7 @@ yang2cli_list(clicon_handle h, /* Iterate over individual keys */ while ((cvi = cvec_each(cvk, cvi)) != NULL) { keyname = cv_string_get(cvi); - if ((yleaf = yang_find((yang_node*)ys, Y_LEAF, keyname)) == NULL){ + if ((yleaf = yang_find(ys, Y_LEAF, keyname)) == NULL){ clicon_err(OE_XML, 0, "List statement \"%s\" has no key leaf \"%s\"", ys->ys_argument, keyname); goto done; @@ -836,7 +836,7 @@ yang2cli_stmt(clicon_handle h, */ int yang2cli(clicon_handle h, - yang_spec *yspec, + yang_stmt *yspec, parse_tree *ptnew, enum genmodel_type gt) { @@ -851,8 +851,8 @@ yang2cli(clicon_handle h, goto done; } /* Traverse YANG, loop through all modules and generate CLI */ - for (i=0; iyp_len; i++) - if ((ymod = yspec->yp_stmt[i]) != NULL){ + for (i=0; iys_len; i++) + if ((ymod = yspec->ys_stmt[i]) != NULL){ if (yang2cli_stmt(h, ymod, gt, 0, cb) < 0) goto done; } diff --git a/apps/cli/cli_generate.h b/apps/cli/cli_generate.h index d049d600..2571fe91 100644 --- a/apps/cli/cli_generate.h +++ b/apps/cli/cli_generate.h @@ -39,7 +39,7 @@ /* * Prototypes */ -int yang2cli(clicon_handle h, yang_spec *yspec, parse_tree *ptnew, +int yang2cli(clicon_handle h, yang_stmt *yspec, parse_tree *ptnew, enum genmodel_type gt); #endif /* _CLI_GENERATE_H_ */ diff --git a/apps/cli/cli_main.c b/apps/cli/cli_main.c index d08449ab..7b4c5205 100644 --- a/apps/cli/cli_main.c +++ b/apps/cli/cli_main.c @@ -162,7 +162,7 @@ cli_history_save(clicon_handle h) static int cli_terminate(clicon_handle h) { - yang_spec *yspec; + yang_stmt *yspec; cxobj *x; clicon_rpc_close_session(h); @@ -279,8 +279,8 @@ main(int argc, char **argv) int help = 0; int logdst = CLICON_LOG_STDERR; char *restarg = NULL; /* what remains after options */ - yang_spec *yspec; - yang_spec *yspecfg = NULL; /* For config XXX clixon bug */ + yang_stmt *yspec; + yang_stmt *yspecfg = NULL; /* For config XXX clixon bug */ struct passwd *pw; char *str; diff --git a/apps/cli/cli_show.c b/apps/cli/cli_show.c index c5449638..ee7e7511 100644 --- a/apps/cli/cli_show.c +++ b/apps/cli/cli_show.c @@ -112,10 +112,10 @@ expand_dbvar(void *h, int j; int k; cg_var *cv; - yang_spec *yspec; + yang_stmt *yspec; cxobj *xtop = NULL; /* xpath root */ cxobj *xbot = NULL; /* xpath, NULL if datastore */ - yang_node *y = NULL; /* yang spec of xpath */ + yang_stmt *y = NULL; /* yang spec of xpath */ yang_stmt *ytype; yang_stmt *ypath; cxobj *xcur; @@ -183,9 +183,9 @@ expand_dbvar(void *h, * Here the whole syntax tree is loaded, and it would be better to offload * such operations to the datastore by a generic xpath function. */ - if ((ytype = yang_find((yang_node*)y, Y_TYPE, NULL)) != NULL) + if ((ytype = yang_find(y, Y_TYPE, NULL)) != NULL) if (strcmp(ytype->ys_argument, "leafref")==0){ - if ((ypath = yang_find((yang_node*)ytype, Y_PATH, NULL)) == NULL){ + if ((ypath = yang_find(ytype, Y_PATH, NULL)) == NULL){ clicon_err(OE_DB, 0, "Leafref %s requires path statement", ytype->ys_argument); goto done; } @@ -394,17 +394,17 @@ show_yang(clicon_handle h, cvec *cvv, cvec *argv) { - yang_node *yn; + yang_stmt *yn; char *str = NULL; - yang_spec *yspec; + yang_stmt *yspec; yspec = clicon_dbspec_yang(h); if (cvec_len(argv) > 0){ str = cv_string_get(cvec_i(argv, 0)); - yn = (yang_node*)yang_find((yang_node*)yspec, 0, str); + yn = yang_find(yspec, 0, str); } else - yn = (yang_node*)yspec; + yn = yspec; yang_print(stdout, yn); return 0; } @@ -443,7 +443,7 @@ cli_show_config(clicon_handle h, cxobj *xc; cxobj *xerr; enum genmodel_type gt; - yang_spec *yspec; + yang_stmt *yspec; if (cvec_len(argv) != 3 && cvec_len(argv) != 4){ clicon_err(OE_PLUGIN, 0, "Got %d arguments. Expected: ,,[,]", cvec_len(argv)); @@ -622,7 +622,7 @@ cli_show_auto(clicon_handle h, cvec *argv) { int retval = 1; - yang_spec *yspec; + yang_stmt *yspec; char *api_path_fmt; /* xml key format */ // char *api_path = NULL; /* xml key */ char *db; diff --git a/apps/netconf/netconf_main.c b/apps/netconf/netconf_main.c index e338d687..f85bba32 100644 --- a/apps/netconf/netconf_main.c +++ b/apps/netconf/netconf_main.c @@ -92,7 +92,7 @@ netconf_input_packet(clicon_handle h, cxobj *xret = NULL; /* Return (out) */ cxobj *xrpc; cxobj *xc; - yang_spec *yspec; + yang_stmt *yspec; int ret; cxobj *xa; cxobj *xa2; @@ -290,7 +290,7 @@ send_hello(clicon_handle h, static int netconf_terminate(clicon_handle h) { - yang_spec *yspec; + yang_stmt *yspec; cxobj *x; clixon_plugin_exit(h); @@ -357,8 +357,8 @@ main(int argc, int logdst = CLICON_LOG_STDERR; struct passwd *pw; struct timeval tv = {0,}; /* timeout */ - yang_spec *yspec = NULL; - yang_spec *yspecfg = NULL; /* For config XXX clixon bug */ + yang_stmt *yspec = NULL; + yang_stmt *yspecfg = NULL; /* For config XXX clixon bug */ char *str; /* Create handle */ diff --git a/apps/netconf/netconf_rpc.c b/apps/netconf/netconf_rpc.c index 9d96a2b7..5974a4c3 100644 --- a/apps/netconf/netconf_rpc.c +++ b/apps/netconf/netconf_rpc.c @@ -427,7 +427,7 @@ netconf_notification_cb(int s, cxobj *xn = NULL; /* event xml */ cxobj *xt = NULL; /* top xml */ clicon_handle h = (clicon_handle)arg; - yang_spec *yspec = NULL; + yang_stmt *yspec = NULL; clicon_debug(1, "%s", __FUNCTION__); /* get msg (this is the reason this function is called) */ @@ -541,7 +541,7 @@ netconf_application_rpc(clicon_handle h, cxobj **xret) { int retval = -1; - yang_spec *yspec = NULL; /* application yspec */ + yang_stmt *yspec = NULL; /* application yspec */ yang_stmt *yrpc = NULL; yang_stmt *ymod = NULL; yang_stmt *yinput; @@ -579,11 +579,11 @@ netconf_application_rpc(clicon_handle h, "", xml_name(xn)); goto ok; } - yrpc = yang_find((yang_node*)ymod, Y_RPC, xml_name(xn)); + yrpc = yang_find(ymod, Y_RPC, xml_name(xn)); /* Check if found */ if (yrpc != NULL){ /* 1. Check xn arguments with input statement. */ - if ((yinput = yang_find((yang_node*)yrpc, Y_INPUT, NULL)) != NULL){ + if ((yinput = yang_find(yrpc, Y_INPUT, NULL)) != NULL){ xml_spec_set(xn, yinput); /* needed for xml_spec_populate */ if (xml_apply(xn, CX_ELMNT, xml_spec_populate, yspec) < 0) goto done; @@ -616,7 +616,7 @@ netconf_application_rpc(clicon_handle h, * (2) Uncertain how validation errors should be logged/handled */ if (0) - if ((youtput = yang_find((yang_node*)yrpc, Y_OUTPUT, NULL)) != NULL){ + if ((youtput = yang_find(yrpc, Y_OUTPUT, NULL)) != NULL){ xoutput=xpath_first(*xret, "/"); xml_spec_set(xoutput, youtput); /* needed for xml_spec_populate */ if (xml_apply(xoutput, CX_ELMNT, xml_spec_populate, yspec) < 0) diff --git a/apps/restconf/restconf_lib.c b/apps/restconf/restconf_lib.c index 63459f5c..8bcb7c38 100644 --- a/apps/restconf/restconf_lib.c +++ b/apps/restconf/restconf_lib.c @@ -478,7 +478,7 @@ api_return_err(clicon_handle h, int restconf_terminate(clicon_handle h) { - yang_spec *yspec; + yang_stmt *yspec; cxobj *x; int fs; /* fgcx socket */ diff --git a/apps/restconf/restconf_main.c b/apps/restconf/restconf_main.c index c08edee9..6d8e8082 100644 --- a/apps/restconf/restconf_main.c +++ b/apps/restconf/restconf_main.c @@ -521,8 +521,8 @@ main(int argc, clicon_handle h; char *dir; int logdst = CLICON_LOG_SYSLOG; - yang_spec *yspec = NULL; - yang_spec *yspecfg = NULL; /* For config XXX clixon bug */ + yang_stmt *yspec = NULL; + yang_stmt *yspecfg = NULL; /* For config XXX clixon bug */ char *stream_path; int finish; char *str; diff --git a/apps/restconf/restconf_methods.c b/apps/restconf/restconf_methods.c index eeaca5b5..f517bac8 100644 --- a/apps/restconf/restconf_methods.c +++ b/apps/restconf/restconf_methods.c @@ -188,7 +188,7 @@ api_data_get2(clicon_handle h, cbuf *cbpath = NULL; char *path; cbuf *cbx = NULL; - yang_spec *yspec; + yang_stmt *yspec; cxobj *xret = NULL; cxobj *xerr = NULL; /* malloced */ cxobj *xe = NULL; @@ -443,8 +443,8 @@ api_data_post(clicon_handle h, cxobj *xtop = NULL; /* xpath root */ cxobj *xbot = NULL; cxobj *x; - yang_node *y = NULL; - yang_spec *yspec; + yang_stmt *y = NULL; + yang_stmt *yspec; cxobj *xa; cxobj *xret = NULL; cxobj *xretcom = NULL; /* return from commit */ @@ -710,8 +710,8 @@ api_data_put(clicon_handle h, cxobj *xbot = NULL; cxobj *xparent; cxobj *x; - yang_node *y = NULL; - yang_spec *yspec; + yang_stmt *y = NULL; + yang_stmt *yspec; cxobj *xa; char *api_path; cxobj *xret = NULL; @@ -847,7 +847,7 @@ api_data_put(clicon_handle h, goto ok; } /* If list or leaf-list, api-path keys must match data keys */ - if (y && (y->yn_keyword == Y_LIST ||y->yn_keyword == Y_LEAF_LIST)){ + if (y && (y->ys_keyword == Y_LIST ||y->ys_keyword == Y_LEAF_LIST)){ if (match_list_keys((yang_stmt*)y, x, xbot) < 0){ if (netconf_operation_failed_xml(&xerr, "protocol", "api-path keys do not match data keys") < 0) goto done; @@ -988,8 +988,8 @@ api_data_delete(clicon_handle h, cxobj *xbot = NULL; cxobj *xa; cbuf *cbx = NULL; - yang_node *y = NULL; - yang_spec *yspec; + yang_stmt *y = NULL; + yang_stmt *yspec; enum operation_type op = OP_DELETE; cxobj *xret = NULL; cxobj *xretcom = NULL; /* return from commmit */ @@ -1128,7 +1128,7 @@ api_operations_get(clicon_handle h, int use_xml) { int retval = -1; - yang_spec *yspec; + yang_stmt *yspec; yang_stmt *ymod; /* yang module */ yang_stmt *yc; char *namespace; @@ -1146,10 +1146,10 @@ api_operations_get(clicon_handle h, cprintf(cbx, "{\"operations\": {"); ymod = NULL; i = 0; - while ((ymod = yn_each((yang_node*)yspec, ymod)) != NULL) { + while ((ymod = yn_each(yspec, ymod)) != NULL) { namespace = yang_find_mynamespace(ymod); yc = NULL; - while ((yc = yn_each((yang_node*)ymod, yc)) != NULL) { + while ((yc = yn_each(ymod, yc)) != NULL) { if (yc->ys_keyword != Y_RPC) continue; if (use_xml) @@ -1207,7 +1207,7 @@ static int api_operations_post_input(clicon_handle h, FCGX_Request *r, char *data, - yang_spec *yspec, + yang_stmt *yspec, yang_stmt *yrpc, cxobj *xrpc, int pretty, @@ -1342,7 +1342,7 @@ static int api_operations_post_output(clicon_handle h, FCGX_Request *r, cxobj *xret, - yang_spec *yspec, + yang_stmt *yspec, yang_stmt *youtput, char *namespace, int pretty, @@ -1511,14 +1511,14 @@ api_operations_post(clicon_handle h, int retval = -1; int i; char *oppath = path; - yang_spec *yspec; + yang_stmt *yspec; yang_stmt *youtput = NULL; yang_stmt *yrpc = NULL; cxobj *xret = NULL; cxobj *xerr = NULL; /* malloced must be freed */ cxobj *xtop = NULL; /* xpath root */ cxobj *xbot = NULL; - yang_node *y = NULL; + yang_stmt *y = NULL; cxobj *xoutput = NULL; cxobj *xa; cxobj *xe; @@ -1561,7 +1561,7 @@ api_operations_post(clicon_handle h, */ if (nodeid_split(oppath+1, &prefix, &id) < 0) /* +1 skip / */ goto done; - if ((ys = yang_find((yang_node*)yspec, Y_MODULE, prefix)) == NULL){ + if ((ys = yang_find(yspec, Y_MODULE, prefix)) == NULL){ if (netconf_operation_failed_xml(&xerr, "protocol", "yang module not found") < 0) goto done; if ((xe = xpath_first(xerr, "rpc-error")) == NULL){ @@ -1572,7 +1572,7 @@ api_operations_post(clicon_handle h, goto done; goto ok; } - if ((yrpc = yang_find((yang_node*)ys, Y_RPC, id)) == NULL){ + if ((yrpc = yang_find(ys, Y_RPC, id)) == NULL){ if (netconf_missing_element_xml(&xerr, "application", id, "RPC not defined") < 0) goto done; if ((xe = xpath_first(xerr, "rpc-error")) == NULL){ @@ -1704,7 +1704,7 @@ api_operations_post(clicon_handle h, clicon_debug(1, "%s 8. Receive reply:%s", __FUNCTION__, cbuf_get(ccc)); } #endif - youtput = yang_find((yang_node*)yrpc, Y_OUTPUT, NULL); + youtput = yang_find(yrpc, Y_OUTPUT, NULL); if ((ret = api_operations_post_output(h, r, xret, yspec, youtput, namespace, pretty, use_xml, &xoutput)) < 0) goto done; diff --git a/example/main/example_backend.c b/example/main/example_backend.c index 377b87da..8abfb297 100644 --- a/example/main/example_backend.c +++ b/example/main/example_backend.c @@ -285,7 +285,7 @@ upgrade_2016(clicon_handle h, cbuf *cbret) { int retval = -1; - yang_spec *yspec; + yang_stmt *yspec; yang_stmt *ym; cxobj **vec = NULL; cxobj *xc; @@ -384,7 +384,7 @@ upgrade_2018(clicon_handle h, cbuf *cbret) { int retval = -1; - yang_spec *yspec; + yang_stmt *yspec; yang_stmt *ym; cxobj **vec = NULL; cxobj *xc; diff --git a/lib/clixon/clixon_data.h b/lib/clixon/clixon_data.h index 81c40fd1..6f4872b6 100644 --- a/lib/clixon/clixon_data.h +++ b/lib/clixon/clixon_data.h @@ -58,14 +58,14 @@ typedef struct { /* * Prototypes */ -yang_spec * clicon_dbspec_yang(clicon_handle h); -int clicon_dbspec_yang_set(clicon_handle h, struct yang_spec *ys); +yang_stmt * clicon_dbspec_yang(clicon_handle h); +int clicon_dbspec_yang_set(clicon_handle h, yang_stmt *ys); cxobj * clicon_nacm_ext(clicon_handle h); int clicon_nacm_ext_set(clicon_handle h, cxobj *xn); -yang_spec * clicon_config_yang(clicon_handle h); -int clicon_config_yang_set(clicon_handle h, struct yang_spec *ys); +yang_stmt * clicon_config_yang(clicon_handle h); +int clicon_config_yang_set(clicon_handle h, yang_stmt *ys); cxobj *clicon_conf_xml(clicon_handle h); int clicon_conf_xml_set(clicon_handle h, cxobj *x); diff --git a/lib/clixon/clixon_json.h b/lib/clixon/clixon_json.h index 0a4af828..70280284 100644 --- a/lib/clixon/clixon_json.h +++ b/lib/clixon/clixon_json.h @@ -43,8 +43,8 @@ int xml2json_cbuf(cbuf *cb, cxobj *x, int pretty); int xml2json_cbuf_vec(cbuf *cb, cxobj **vec, size_t veclen, int pretty); int xml2json(FILE *f, cxobj *x, int pretty); int xml2json_vec(FILE *f, cxobj **vec, size_t veclen, int pretty); -int json2xml_ns(yang_spec *yspec, cxobj *x, cxobj **xerr); +int json2xml_ns(yang_stmt *yspec, cxobj *x, cxobj **xerr); int json_parse_str(char *str, cxobj **xt); -int json_parse_file(int fd, yang_spec *yspec, cxobj **xt); +int json_parse_file(int fd, yang_stmt *yspec, cxobj **xt); #endif /* _CLIXON_JSON_H */ diff --git a/lib/clixon/clixon_netconf_lib.h b/lib/clixon/clixon_netconf_lib.h index 81f454a0..01a7ee2f 100644 --- a/lib/clixon/clixon_netconf_lib.h +++ b/lib/clixon/clixon_netconf_lib.h @@ -66,7 +66,7 @@ int netconf_operation_failed(cbuf *cb, char *type, char *message); int netconf_operation_failed_xml(cxobj **xret, char *type, char *message); int netconf_malformed_message(cbuf *cb, char *message); int netconf_malformed_message_xml(cxobj **xret, char *message); -int netconf_trymerge(cxobj *x, yang_spec *yspec, cxobj **xret); +int netconf_trymerge(cxobj *x, yang_stmt *yspec, cxobj **xret); int netconf_module_load(clicon_handle h); char *netconf_db_find(cxobj *xn, char *name); diff --git a/lib/clixon/clixon_options.h b/lib/clixon/clixon_options.h index 944a2372..d0f60bab 100644 --- a/lib/clixon/clixon_options.h +++ b/lib/clixon/clixon_options.h @@ -84,7 +84,7 @@ int clicon_option_dump(clicon_handle h, int dblevel); int clicon_option_add(clicon_handle h, char *name, char *value); /* Initialize options: set defaults, read config-file, etc */ -int clicon_options_main(clicon_handle h, yang_spec *yspec); +int clicon_options_main(clicon_handle h, yang_stmt *yspec); /*! Check if a clicon option has a value */ int clicon_option_exists(clicon_handle h, const char *name); diff --git a/lib/clixon/clixon_proto.h b/lib/clixon/clixon_proto.h index e5457685..746c36f6 100644 --- a/lib/clixon/clixon_proto.h +++ b/lib/clixon/clixon_proto.h @@ -66,7 +66,7 @@ struct clicon_msg *clicon_msg_encode(char *format, ...) __attribute__ ((format ( #else struct clicon_msg *clicon_msg_encode(char *format, ...); #endif -int clicon_msg_decode(struct clicon_msg *msg, yang_spec *yspec, cxobj **xml); +int clicon_msg_decode(struct clicon_msg *msg, yang_stmt *yspec, cxobj **xml); int clicon_connect_unix(char *sockpath); diff --git a/lib/clixon/clixon_xml.h b/lib/clixon/clixon_xml.h index 4933115b..8114133d 100644 --- a/lib/clixon/clixon_xml.h +++ b/lib/clixon/clixon_xml.h @@ -153,12 +153,12 @@ int xml_free(cxobj *xn); int xml_print(FILE *f, cxobj *xn); int clicon_xml2file(FILE *f, cxobj *xn, int level, int prettyprint); int clicon_xml2cbuf(cbuf *xf, cxobj *xn, int level, int prettyprint); -int xml_parse_file(int fd, char *endtag, yang_spec *yspec, cxobj **xt); -int xml_parse_string(const char *str, yang_spec *yspec, cxobj **xml_top); +int xml_parse_file(int fd, char *endtag, yang_stmt *yspec, cxobj **xt); +int xml_parse_string(const char *str, yang_stmt *yspec, cxobj **xml_top); #if defined(__GNUC__) && __GNUC__ >= 3 -int xml_parse_va(cxobj **xt, yang_spec *yspec, const char *format, ...) __attribute__ ((format (printf, 3, 4))); +int xml_parse_va(cxobj **xt, yang_stmt *yspec, const char *format, ...) __attribute__ ((format (printf, 3, 4))); #else -int xml_parse_va(cxobj **xt, yang_spec *yspec, const char *format, ...); +int xml_parse_va(cxobj **xt, yang_stmt *yspec, const char *format, ...); #endif int xmltree2cbuf(cbuf *cb, cxobj *x, int level); int xml_copy_one(cxobj *xn0, cxobj *xn1); diff --git a/lib/clixon/clixon_xml_map.h b/lib/clixon/clixon_xml_map.h index afc04b3c..def72601 100644 --- a/lib/clixon/clixon_xml_map.h +++ b/lib/clixon/clixon_xml_map.h @@ -51,7 +51,7 @@ int xml_yang_validate_all(cxobj *xt, cbuf *cbret); int xml_yang_validate_all_top(cxobj *xt, cbuf *cbret); int xml2cvec(cxobj *xt, yang_stmt *ys, cvec **cvv0); int cvec2xml_1(cvec *cvv, char *toptag, cxobj *xp, cxobj **xt0); -int xml_diff(yang_spec *yspec, cxobj *xt1, cxobj *xt2, +int xml_diff(yang_stmt *yspec, cxobj *xt1, cxobj *xt2, cxobj ***first, size_t *firstlen, cxobj ***second, size_t *secondlen, cxobj ***changed1, cxobj ***changed2, size_t *changedlen); @@ -63,12 +63,12 @@ int xml_tree_prune_flagged(cxobj *xt, int flag, int test); int xml_default(cxobj *x, void *arg); int xml_sanity(cxobj *x, void *arg); int xml_non_config_data(cxobj *xt, void *arg); -int xml_spec_populate_rpc(clicon_handle h, cxobj *x, yang_spec *yspec); +int xml_spec_populate_rpc(clicon_handle h, cxobj *x, yang_stmt *yspec); int xml_spec_populate(cxobj *x, void *arg); -int api_path2xpath(yang_spec *yspec, cvec *cvv, int offset, cbuf *xpath); -int api_path2xml(char *api_path, yang_spec *yspec, cxobj *xtop, - yang_class nodeclass, cxobj **xpathp, yang_node **ypathp); -int xml_merge(cxobj *x0, cxobj *x1, yang_spec *yspec, char **reason); +int api_path2xpath(yang_stmt *yspec, cvec *cvv, int offset, cbuf *xpath); +int api_path2xml(char *api_path, yang_stmt *yspec, cxobj *xtop, + yang_class nodeclass, cxobj **xpathp, yang_stmt **ypathp); +int xml_merge(cxobj *x0, cxobj *x1, yang_stmt *yspec, char **reason); int yang_enum_int_value(cxobj *node, int32_t *val); #endif /* _CLIXON_XML_MAP_H_ */ diff --git a/lib/clixon/clixon_xml_sort.h b/lib/clixon/clixon_xml_sort.h index d38b91cf..7dea18b8 100644 --- a/lib/clixon/clixon_xml_sort.h +++ b/lib/clixon/clixon_xml_sort.h @@ -39,7 +39,7 @@ /* * Prototypes */ -int xml_child_spec(cxobj *x, cxobj *xp, yang_spec *yspec, yang_stmt **yp); +int xml_child_spec(cxobj *x, cxobj *xp, yang_stmt *yspec, yang_stmt **yp); int xml_sort(cxobj *x0, void *arg); cxobj *xml_search(cxobj *x, char *name, int yangi, enum rfc_6020 keyword, int keynr, char **keyvec, char **keyval); int xml_insert_pos(cxobj *x0, char *name, int yangi, enum rfc_6020 keyword, diff --git a/lib/clixon/clixon_yang.h b/lib/clixon/clixon_yang.h index 74660bc6..3e7a70ed 100644 --- a/lib/clixon/clixon_yang.h +++ b/lib/clixon/clixon_yang.h @@ -192,7 +192,7 @@ typedef struct yang_type_cache yang_type_cache; struct yang_stmt{ int ys_len; /* Number of children */ struct yang_stmt **ys_stmt; /* Vector of children statement pointers */ - struct yang_node *ys_parent; /* Backpointer to parent: yang-stmt or yang-spec */ + struct yang_stmt *ys_parent; /* Backpointer to parent: yang-stmt or yang-spec */ enum rfc_6020 ys_keyword; /* See clicon_yang_parse.tab.h */ char *ys_argument; /* String / argument depending on keyword */ @@ -220,68 +220,64 @@ struct yang_stmt{ yang_type_cache *ys_typecache; /* If ys_keyword==Y_TYPE, cache all typedef data except unions */ }; -/*! top-level yang parse-tree */ -struct yang_spec{ - int yp_len; /* Number of children */ - struct yang_stmt **yp_stmt; /* Vector of children statement pointers */ - struct yang_node *yp_parent; /* Backpointer to parent: always NULL. See yang_stmt */ - enum rfc_6020 yp_keyword; /* SHOULD BE Y_SPEC */ - char *yp_argument; /* XXX String / argument depending on keyword */ - int yp_flags; /* Flags according to YANG_FLAG_* above */ -}; -typedef struct yang_spec yang_spec; +#if 0 /* Backward compatible */ +typedef struct yang_stmt yang_node; +typedef struct yang_stmt yang_spec; -/*! super-class of yang_stmt and yang_spec: it must start exactly as those two classes */ -struct yang_node{ - int yn_len; /* Number of children */ - struct yang_stmt **yn_stmt; /* Vector of children statement pointers */ - struct yang_node *yn_parent; /* Backpointer to parent: yang-stmt or yang-spec */ - enum rfc_6020 yn_keyword; /* See clicon_yang_parse.tab.h */ - char *yn_argument; /* XXX String / argument depending on keyword */ - int yn_flags; /* Flags according to YANG_FLAG_* above */ -}; -typedef struct yang_node yang_node; +#define yn_len ys_len +#define yn_stmt ys_stmt +#define yn_parent ys_parent +#define yn_keyword ys_keyword +#define yn_argument ys_argument +#define yn_flags ys_flags +#define yp_len ys_len +#define yp_stmt ys_stmt +#define yp_parent ys_parent +#define yp_keyword ys_keyword +#define yp_argument ys_argument +#define yp_flags ys_flags +#endif typedef int (yang_applyfn_t)(yang_stmt *ys, void *arg); /* * Prototypes */ -yang_spec *yspec_new(void); +yang_stmt *yspec_new(void); yang_stmt *ys_new(enum rfc_6020 keyw); int ys_free(yang_stmt *ys); -int yspec_free(yang_spec *yspec); +int yspec_free(yang_stmt *yspec); int ys_cp(yang_stmt *new, yang_stmt *old); yang_stmt *ys_dup(yang_stmt *old); -int yn_insert(yang_node *yn_parent, yang_stmt *ys_child); -yang_stmt *yn_each(yang_node *yn, yang_stmt *ys); +int yn_insert(yang_stmt *ys_parent, yang_stmt *ys_child); +yang_stmt *yn_each(yang_stmt *yn, yang_stmt *ys); char *yang_key2str(int keyword); char *yarg_prefix(yang_stmt *ys); char *yarg_id(yang_stmt *ys); -int ys_module_by_xml(yang_spec *ysp, struct xml *xt, yang_stmt **ymodp); +int ys_module_by_xml(yang_stmt *ysp, struct xml *xt, yang_stmt **ymodp); yang_stmt *ys_module(yang_stmt *ys); -yang_spec *ys_spec(yang_stmt *ys); +yang_stmt *ys_spec(yang_stmt *ys); yang_stmt *yang_find_module_by_prefix(yang_stmt *ys, char *prefix); -yang_stmt *yang_find_module_by_namespace(yang_spec *yspec, char *namespace); -yang_stmt *yang_find_module_by_name(yang_spec *yspec, char *name); -yang_stmt *yang_find(yang_node *yn, int keyword, const char *argument); -int yang_match(yang_node *yn, int keyword, char *argument); -yang_stmt *yang_find_datanode(yang_node *yn, char *argument); -yang_stmt *yang_find_schemanode(yang_node *yn, char *argument); +yang_stmt *yang_find_module_by_namespace(yang_stmt *yspec, char *namespace); +yang_stmt *yang_find_module_by_name(yang_stmt *yspec, char *name); +yang_stmt *yang_find(yang_stmt *yn, int keyword, const char *argument); +int yang_match(yang_stmt *yn, int keyword, char *argument); +yang_stmt *yang_find_datanode(yang_stmt *yn, char *argument); +yang_stmt *yang_find_schemanode(yang_stmt *yn, char *argument); char *yang_find_myprefix(yang_stmt *ys); char *yang_find_mynamespace(yang_stmt *ys); -yang_node *yang_choice(yang_stmt *y); +yang_stmt *yang_choice(yang_stmt *y); int yang_order(yang_stmt *y); -int yang_print(FILE *f, yang_node *yn); -int yang_print_cbuf(cbuf *cb, yang_node *yn, int marginal); +int yang_print(FILE *f, yang_stmt *yn); +int yang_print_cbuf(cbuf *cb, yang_stmt *yn, int marginal); int ys_populate(yang_stmt *ys, void *arg); -yang_stmt *yang_parse_file(int fd, const char *name, yang_spec *ysp); -int yang_apply(yang_node *yn, enum rfc_6020 key, yang_applyfn_t fn, +yang_stmt *yang_parse_file(int fd, const char *name, yang_stmt *ysp); +int yang_apply(yang_stmt *yn, enum rfc_6020 key, yang_applyfn_t fn, void *arg); -int yang_abs_schema_nodeid(yang_spec *yspec, yang_stmt *ys, +int yang_abs_schema_nodeid(yang_stmt *yspec, yang_stmt *ys, char *schema_nodeid, enum rfc_6020 keyword, yang_stmt **yres); -int yang_desc_schema_nodeid(yang_node *yn, char *schema_nodeid, +int yang_desc_schema_nodeid(yang_stmt *yn, char *schema_nodeid, enum rfc_6020 keyword, yang_stmt **yres); int ys_parse_date_arg(char *datearg, uint32_t *dateint); @@ -290,10 +286,10 @@ int ys_parse_sub(yang_stmt *ys, char *extra); int yang_mandatory(yang_stmt *ys); int yang_config(yang_stmt *ys); int yang_spec_parse_module(clicon_handle h, const char *module, - const char *revision, yang_spec *yspec); -int yang_spec_parse_file(clicon_handle h, char *filename, yang_spec *yspec); -int yang_spec_load_dir(clicon_handle h, char *dir, yang_spec *yspec); + const char *revision, yang_stmt *yspec); +int yang_spec_parse_file(clicon_handle h, char *filename, yang_stmt *yspec); +int yang_spec_load_dir(clicon_handle h, char *dir, yang_stmt *yspec); cvec *yang_arg2cvec(yang_stmt *ys, char *delimi); -int yang_key_match(yang_node *yn, char *name); +int yang_key_match(yang_stmt *yn, char *name); #endif /* _CLIXON_YANG_H_ */ diff --git a/lib/clixon/clixon_yang_module.h b/lib/clixon/clixon_yang_module.h index f6870302..0381864e 100644 --- a/lib/clixon/clixon_yang_module.h +++ b/lib/clixon/clixon_yang_module.h @@ -64,7 +64,7 @@ int modstate_diff_free(modstate_diff_t *); int yang_modules_init(clicon_handle h); char *yang_modules_revision(clicon_handle h); -int yang_modules_state_get(clicon_handle h, yang_spec *yspec, char *xpath, +int yang_modules_state_get(clicon_handle h, yang_stmt *yspec, char *xpath, int brief, cxobj **xret); int clixon_module_upgrade(clicon_handle h, cxobj *xt, modstate_diff_t *msd, cbuf *cb); diff --git a/lib/src/clixon_data.c b/lib/src/clixon_data.c index 8f32bb84..98521bff 100644 --- a/lib/src/clixon_data.c +++ b/lib/src/clixon_data.c @@ -76,7 +76,7 @@ /*! Get YANG specification for application * Must use hash functions directly since they are not strings. */ -yang_spec * +yang_stmt * clicon_dbspec_yang(clicon_handle h) { clicon_hash_t *cdat = clicon_data(h); @@ -84,7 +84,7 @@ clicon_dbspec_yang(clicon_handle h) void *p; if ((p = hash_value(cdat, "dbspec_yang", &len)) != NULL) - return *(yang_spec **)p; + return *(yang_stmt **)p; return NULL; } @@ -92,8 +92,8 @@ clicon_dbspec_yang(clicon_handle h) * ys must be a malloced pointer */ int -clicon_dbspec_yang_set(clicon_handle h, - struct yang_spec *ys) +clicon_dbspec_yang_set(clicon_handle h, + yang_stmt *ys) { clicon_hash_t *cdat = clicon_data(h); @@ -151,7 +151,7 @@ clicon_nacm_ext_set(clicon_handle h, /*! Get YANG specification for clixon config * Must use hash functions directly since they are not strings. */ -yang_spec * +yang_stmt * clicon_config_yang(clicon_handle h) { clicon_hash_t *cdat = clicon_data(h); @@ -159,7 +159,7 @@ clicon_config_yang(clicon_handle h) void *p; if ((p = hash_value(cdat, "control_yang", &len)) != NULL) - return *(yang_spec **)p; + return *(yang_stmt **)p; return NULL; } @@ -167,8 +167,8 @@ clicon_config_yang(clicon_handle h) * ys must be a malloced pointer */ int -clicon_config_yang_set(clicon_handle h, - struct yang_spec *ys) +clicon_config_yang_set(clicon_handle h, + yang_stmt *ys) { clicon_hash_t *cdat = clicon_data(h); diff --git a/lib/src/clixon_datastore_read.c b/lib/src/clixon_datastore_read.c index 3515f4f2..720fecda 100644 --- a/lib/src/clixon_datastore_read.c +++ b/lib/src/clixon_datastore_read.c @@ -186,7 +186,7 @@ xml_copy_marked(cxobj *x0, * node in list is marked */ if (mark && yt && yt->ys_keyword == Y_LIST){ /* XXX: I think yang_key_match is suboptimal here */ - if ((iskey = yang_key_match((yang_node*)yt, name)) < 0) + if ((iskey = yang_key_match(yt, name)) < 0) goto done; if (iskey){ if ((xcopy = xml_new(name, x1, xml_spec(x))) == NULL) @@ -220,7 +220,7 @@ xml_copy_marked(cxobj *x0, */ static int text_read_modstate(clicon_handle h, - yang_spec *yspec, + yang_stmt *yspec, cxobj *xt, modstate_diff_t *msd) { @@ -306,7 +306,7 @@ text_read_modstate(clicon_handle h, int xmldb_readfile(clicon_handle h, const char *db, - yang_spec *yspec, + yang_stmt *yspec, cxobj **xp, modstate_diff_t *msd) { @@ -391,7 +391,7 @@ xmldb_get_nocache(clicon_handle h, { int retval = -1; char *dbfile = NULL; - yang_spec *yspec; + yang_stmt *yspec; cxobj *xt = NULL; cxobj *x; int fd = -1; @@ -513,7 +513,7 @@ xmldb_get_cache(clicon_handle h, modstate_diff_t *msd) { int retval = -1; - yang_spec *yspec; + yang_stmt *yspec; cxobj *x0t = NULL; /* (cached) top of tree */ cxobj *x0; cxobj **xvec = NULL; diff --git a/lib/src/clixon_datastore_read.h b/lib/src/clixon_datastore_read.h index b7a20ff6..29b1c979 100644 --- a/lib/src/clixon_datastore_read.h +++ b/lib/src/clixon_datastore_read.h @@ -41,6 +41,6 @@ */ int xmldb_get_cache(clicon_handle h, const char *db, char *xpath, int config, cxobj **xret, modstate_diff_t *msd); int xmldb_get_nocache(clicon_handle h, const char *db, char *xpath, int config, cxobj **xret, modstate_diff_t *msd); -int xmldb_readfile(clicon_handle h, const char *db, yang_spec *yspec, cxobj **xp, modstate_diff_t *msd); +int xmldb_readfile(clicon_handle h, const char *db, yang_stmt *yspec, cxobj **xp, modstate_diff_t *msd); #endif /* _CLIXON_DATASTORE_READ_H */ diff --git a/lib/src/clixon_datastore_write.c b/lib/src/clixon_datastore_write.c index 1e604f9b..0172cc0e 100644 --- a/lib/src/clixon_datastore_write.c +++ b/lib/src/clixon_datastore_write.c @@ -111,7 +111,7 @@ valgrind --tool=callgrind datastore_client -d candidate -b /tmp/text -p ../datas static int text_modify(clicon_handle h, cxobj *x0, - yang_node *y0, + yang_stmt *y0, cxobj *x0p, cxobj *x1, enum operation_type op, @@ -144,7 +144,7 @@ text_modify(clicon_handle h, if (xml_operation(opstr, &op) < 0) goto done; x1name = xml_name(x1); - if (y0->yn_keyword == Y_LEAF_LIST || y0->yn_keyword == Y_LEAF){ + if (y0->ys_keyword == Y_LEAF_LIST || y0->ys_keyword == Y_LEAF){ x1bstr = xml_body(x1); switch(op){ case OP_CREATE: @@ -181,7 +181,7 @@ text_modify(clicon_handle h, #if 0 /* If it is key I dont want to mark it */ - if ((iamkey=yang_key_match(y0->yn_parent, x1name)) < 0) + if ((iamkey=yang_key_match(y0->ys_parent, x1name)) < 0) goto done; if (!iamkey && op==OP_NONE) #else @@ -262,7 +262,7 @@ text_modify(clicon_handle h, can be modified in its entirety only. Any "operation" attributes present on subelements of an anyxml node are ignored by the NETCONF server.*/ - if (y0->yn_keyword == Y_ANYXML || y0->yn_keyword == Y_ANYDATA){ + if (y0->ys_keyword == Y_ANYXML || y0->ys_keyword == Y_ANYDATA){ if (op == OP_NONE) break; if (op==OP_MERGE && !permit && xnacm){ @@ -344,7 +344,7 @@ text_modify(clicon_handle h, x1cname = xml_name(x1c); x0c = x0vec[i++]; yc = yang_find_datanode(y0, x1cname); - if ((ret = text_modify(h, x0c, (yang_node*)yc, x0, x1c, op, + if ((ret = text_modify(h, x0c, yc, x0, x1c, op, username, xnacm, permit, cbret)) < 0) goto done; /* If xml return - ie netconf error xml tree, then stop and return OK */ @@ -404,7 +404,7 @@ static int text_modify_top(clicon_handle h, cxobj *x0, cxobj *x1, - yang_spec *yspec, + yang_stmt *yspec, enum operation_type op, char *username, cxobj *xnacm, @@ -489,7 +489,7 @@ text_modify_top(clicon_handle h, if (ys_module_by_xml(yspec, x1c, &ymod) <0) goto done; if (ymod != NULL) - yc = yang_find_datanode((yang_node*)ymod, x1cname); + yc = yang_find_datanode(ymod, x1cname); if (yc == NULL){ if (netconf_unknown_element(cbret, "application", x1cname, "Unassigned yang spec") < 0) goto done; @@ -506,7 +506,7 @@ text_modify_top(clicon_handle h, x0c = NULL; } #endif - if ((ret = text_modify(h, x0c, (yang_node*)yc, x0, x1c, op, + if ((ret = text_modify(h, x0c, yc, x0, x1c, op, username, xnacm, permit, cbret)) < 0) goto done; /* If xml return - ie netconf error xml tree, then stop and return OK */ @@ -552,7 +552,7 @@ xml_container_presence(cxobj *x, /* Mark node that is: container, have no children, dont have presence */ if (y->ys_keyword == Y_CONTAINER && xml_child_nr_notype(x, CX_ATTR)==0 && - yang_find((yang_node*)y, Y_PRESENCE, NULL) == NULL) + yang_find(y, Y_PRESENCE, NULL) == NULL) xml_flag_set(x, XML_FLAG_MARK); /* Mark, remove later */ retval = 0; done: @@ -597,7 +597,7 @@ xmldb_put(clicon_handle h, char *dbfile = NULL; FILE *f = NULL; cbuf *cb = NULL; - yang_spec *yspec; + yang_stmt *yspec; cxobj *x0 = NULL; db_elmnt *de = NULL; int ret; diff --git a/lib/src/clixon_json.c b/lib/src/clixon_json.c index 88b2d8ae..428831e4 100644 --- a/lib/src/clixon_json.c +++ b/lib/src/clixon_json.c @@ -318,7 +318,7 @@ xml2json1_cbuf(cbuf *cb, enum array_element_type xc_arraytype; yang_stmt *ys; yang_stmt *ymod; /* yang module */ - yang_spec *yspec = NULL; /* yang spec */ + yang_stmt *yspec = NULL; /* yang spec */ int bodystr0=1; char *prefix=NULL; /* prefix / local namespace name */ char *namespace=NULL; /* namespace uri */ @@ -728,7 +728,7 @@ xml2json_vec(FILE *f, * @note the opposite - xml2ns is made inline in xml2json1_cbuf */ int -json2xml_ns(yang_spec *yspec, +json2xml_ns(yang_stmt *yspec, cxobj *x, cxobj **xerr) { @@ -860,7 +860,7 @@ json_parse_str(char *str, */ int json_parse_file(int fd, - yang_spec *yspec, + yang_stmt *yspec, cxobj **xt) { int retval = -1; diff --git a/lib/src/clixon_netconf_lib.c b/lib/src/clixon_netconf_lib.c index 59ba1fd6..87763b85 100644 --- a/lib/src/clixon_netconf_lib.c +++ b/lib/src/clixon_netconf_lib.c @@ -976,7 +976,7 @@ netconf_malformed_message_xml(cxobj **xret, */ int netconf_trymerge(cxobj *x, - yang_spec *yspec, + yang_stmt *yspec, cxobj **xret) { int retval = -1; @@ -1018,7 +1018,7 @@ netconf_module_load(clicon_handle h) { int retval = -1; cxobj *xc; - yang_spec *yspec; + yang_stmt *yspec; yspec = clicon_dbspec_yang(h); if ((xc = clicon_conf_xml(h)) == NULL){ diff --git a/lib/src/clixon_options.c b/lib/src/clixon_options.c index 2b4719f3..bf815fd4 100644 --- a/lib/src/clixon_options.c +++ b/lib/src/clixon_options.c @@ -131,7 +131,7 @@ clicon_option_dump(clicon_handle h, static int parse_configfile(clicon_handle h, const char *filename, - yang_spec *yspec, + yang_stmt *yspec, cxobj **xconfig) { struct stat st; @@ -290,7 +290,7 @@ clicon_option_add(clicon_handle h, */ int clicon_options_main(clicon_handle h, - yang_spec *yspec) + yang_stmt *yspec) { int retval = -1; char *configfile; diff --git a/lib/src/clixon_proto.c b/lib/src/clixon_proto.c index 76c7816e..c357e300 100644 --- a/lib/src/clixon_proto.c +++ b/lib/src/clixon_proto.c @@ -165,7 +165,7 @@ clicon_msg_encode(char *format, ...) */ int clicon_msg_decode(struct clicon_msg *msg, - yang_spec *yspec, + yang_stmt *yspec, cxobj **xml) { int retval = -1; diff --git a/lib/src/clixon_proto_client.c b/lib/src/clixon_proto_client.c index 21534a1a..1bdcfb3e 100644 --- a/lib/src/clixon_proto_client.c +++ b/lib/src/clixon_proto_client.c @@ -92,7 +92,7 @@ clicon_rpc_msg(clicon_handle h, int port; char *retdata = NULL; cxobj *xret = NULL; - yang_spec *yspec; + yang_stmt *yspec; #ifdef RPC_USERNAME_ASSERT assert(strstr(msg->op_body, "username")!=NULL); /* XXX */ diff --git a/lib/src/clixon_stream.c b/lib/src/clixon_stream.c index 5ea7c4a5..7cc3b119 100644 --- a/lib/src/clixon_stream.c +++ b/lib/src/clixon_stream.c @@ -546,7 +546,7 @@ stream_notify(clicon_handle h, va_list args; int len; cxobj *xev = NULL; - yang_spec *yspec = NULL; + yang_stmt *yspec = NULL; char *str = NULL; cbuf *cb = NULL; char timestr[28]; @@ -621,7 +621,7 @@ stream_notify_xml(clicon_handle h, int retval = -1; cxobj *xev = NULL; cxobj *xml2; /* copy */ - yang_spec *yspec = NULL; + yang_stmt *yspec = NULL; char *str = NULL; cbuf *cb = NULL; char timestr[28]; diff --git a/lib/src/clixon_xml.c b/lib/src/clixon_xml.c index 4043e66f..966e37f5 100644 --- a/lib/src/clixon_xml.c +++ b/lib/src/clixon_xml.c @@ -1605,7 +1605,7 @@ xmltree2cbuf(cbuf *cb, */ static int _xml_parse(const char *str, - yang_spec *yspec, + yang_stmt *yspec, cxobj *xt) { int retval = -1; @@ -1685,7 +1685,7 @@ FSM(char *tag, int xml_parse_file(int fd, char *endtag, - yang_spec *yspec, + yang_stmt *yspec, cxobj **xt) { int retval = -1; @@ -1772,7 +1772,7 @@ xml_parse_file(int fd, */ int xml_parse_string(const char *str, - yang_spec *yspec, + yang_stmt *yspec, cxobj **xtop) { if (*xtop == NULL) @@ -1804,7 +1804,7 @@ xml_parse_string(const char *str, */ int xml_parse_va(cxobj **xtop, - yang_spec *yspec, + yang_stmt *yspec, const char *format, ...) { int retval = -1; diff --git a/lib/src/clixon_xml_changelog.c b/lib/src/clixon_xml_changelog.c index d466423f..fb96f8b1 100644 --- a/lib/src/clixon_xml_changelog.c +++ b/lib/src/clixon_xml_changelog.c @@ -423,7 +423,7 @@ clixon_xml_changelog_init(clicon_handle h) char *filename; int fd = -1; cxobj *xt = NULL; - yang_spec *yspec; + yang_stmt *yspec; cbuf *cbret = NULL; int ret; diff --git a/lib/src/clixon_xml_map.c b/lib/src/clixon_xml_map.c index 8a79bdac..f086aa62 100644 --- a/lib/src/clixon_xml_map.c +++ b/lib/src/clixon_xml_map.c @@ -213,7 +213,7 @@ xml2cli(FILE *f, /* If list then first loop through keys */ xe = NULL; while ((xe = xml_child_each(x, xe, -1)) != NULL){ - if ((match = yang_key_match((yang_node*)ys, xml_name(xe))) < 0) + if ((match = yang_key_match(ys, xml_name(xe))) < 0) goto done; if (!match) continue; @@ -226,7 +226,7 @@ xml2cli(FILE *f, xe = NULL; while ((xe = xml_child_each(x, xe, -1)) != NULL){ if (ys->ys_keyword == Y_LIST){ - if ((match = yang_key_match((yang_node*)ys, xml_name(xe))) < 0) + if ((match = yang_key_match(ys, xml_name(xe))) < 0) goto done; if (match){ fprintf(f, "%s\n", cbuf_get(cbpre)); @@ -268,7 +268,7 @@ validate_leafref(cxobj *xt, if ((leafrefbody = xml_body(xt)) == NULL) goto ok; - if ((ypath = yang_find((yang_node*)ytype, Y_PATH, NULL)) == NULL){ + if ((ypath = yang_find(ytype, Y_PATH, NULL)) == NULL){ if (netconf_missing_element(cbret, "application", ytype->ys_argument, "Leafref requires path statement") < 0) goto done; goto fail; @@ -348,7 +348,7 @@ validate_identityref(cxobj *xt, node = cbuf_get(cb); } /* This is the type's base reference */ - if ((ybaseref = yang_find((yang_node*)ytype, Y_BASE, NULL)) == NULL){ + if ((ybaseref = yang_find(ytype, Y_BASE, NULL)) == NULL){ if (netconf_missing_element(cbret, "application", ytype->ys_argument, "Identityref validation failed, no base") < 0) goto done; goto fail; @@ -501,9 +501,9 @@ check_choice(cxobj *xt, cbuf *cbret) { int retval = -1; - yang_node *yc; + yang_stmt *yc; yang_stmt *y; - yang_node *yp; + yang_stmt *yp; cxobj *x; cxobj *xp; @@ -516,7 +516,7 @@ check_choice(cxobj *xt, if ((x != xt) && (y = xml_spec(x)) != NULL && (yp = yang_choice(y)) != NULL && - yp == (yang_node*)yc){ + yp == yc){ if (netconf_bad_element(cbret, "application", xml_name(x), "Element in choice statement already exists") < 0) goto done; goto fail; @@ -549,7 +549,7 @@ check_mandatory(cxobj *xt, cxobj *x; yang_stmt *y; yang_stmt *yc; - yang_node *yp; + yang_stmt *yp; cvec *cvk = NULL; /* vector of index keys */ cg_var *cvi; char *keyname; @@ -598,7 +598,7 @@ check_mandatory(cxobj *xt, while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL) { if ((y = xml_spec(x)) != NULL && (yp = yang_choice(y)) != NULL && - yp == (yang_node*)yc){ + yp == yc){ break; /* leave loop with x set */ } } @@ -777,7 +777,7 @@ xml_yang_validate_all(cxobj *xt, /* Special case if leaf is leafref, then first check against current xml tree */ - if ((yc = yang_find((yang_node*)ys, Y_TYPE, NULL)) != NULL){ + if ((yc = yang_find(ys, Y_TYPE, NULL)) != NULL){ if (strcmp(yc->ys_argument, "leafref") == 0){ if (validate_leafref(xt, yc, cbret) < 0) goto done; @@ -787,7 +787,7 @@ xml_yang_validate_all(cxobj *xt, goto done; } } - if ((yc = yang_find((yang_node*)ys, Y_MIN_ELEMENTS, NULL)) != NULL){ + if ((yc = yang_find(ys, Y_MIN_ELEMENTS, NULL)) != NULL){ /* The behavior of the constraint depends on the type of the * leaf-list's or list's closest ancestor node in the schema tree * that is not a non-presence container (see Section 7.5.1): @@ -811,7 +811,7 @@ xml_yang_validate_all(cxobj *xt, } #endif } - if ((yc = yang_find((yang_node*)ys, Y_MAX_ELEMENTS, NULL)) != NULL){ + if ((yc = yang_find(ys, Y_MAX_ELEMENTS, NULL)) != NULL){ } break; @@ -821,14 +821,14 @@ xml_yang_validate_all(cxobj *xt, /* must sub-node RFC 7950 Sec 7.5.3. Can be several. * XXX. use yang path instead? */ yc = NULL; - while ((yc = yn_each((yang_node*)ys, yc)) != NULL) { + while ((yc = yn_each(ys, yc)) != NULL) { if (yc->ys_keyword != Y_MUST) continue; xpath = yc->ys_argument; /* "must" has xpath argument */ if ((nr = xpath_vec_bool(xt, "%s", xpath)) < 0) goto done; if (!nr){ - ye = yang_find((yang_node*)yc, Y_ERROR_MESSAGE, NULL); + ye = yang_find(yc, Y_ERROR_MESSAGE, NULL); if (netconf_operation_failed(cbret, "application", ye?ye->ys_argument:"must xpath validation failed") < 0) goto done; @@ -836,7 +836,7 @@ xml_yang_validate_all(cxobj *xt, } } /* "when" sub-node RFC 7950 Sec 7.21.5. Can only be one. */ - if ((yc = yang_find((yang_node*)ys, Y_WHEN, NULL)) != NULL){ + if ((yc = yang_find(ys, Y_WHEN, NULL)) != NULL){ xpath = yc->ys_argument; /* "when" has xpath argument */ if ((nr = xpath_vec_bool(xt, "%s", xpath)) < 0) goto done; @@ -932,7 +932,7 @@ xml2cvec(cxobj *xt, /* Go through all children of the xml tree */ while ((xc = xml_child_each(xt, xc, CX_ELMNT)) != NULL){ name = xml_name(xc); - if ((ys = yang_find_datanode((yang_node*)yt, name)) == NULL){ + if ((ys = yang_find_datanode(yt, name)) == NULL){ clicon_debug(0, "%s: yang sanity problem: %s in xml but not present in yang under %s", __FUNCTION__, name, yt->ys_argument); if ((body = xml_body(xc)) != NULL){ @@ -1161,7 +1161,7 @@ xml_diff1(yang_stmt *ys, * Bot xml trees should be freed with xml_free() */ int -xml_diff(yang_spec *yspec, +xml_diff(yang_stmt *yspec, cxobj *x1, cxobj *x2, cxobj ***first, @@ -1215,7 +1215,7 @@ yang2api_path_fmt_1(yang_stmt *ys, int inclkey, cbuf *cb) { - yang_node *yp; /* parent */ + yang_stmt *yp; /* parent */ int i; cvec *cvk = NULL; /* vector of index keys */ int retval = -1; @@ -1225,15 +1225,15 @@ yang2api_path_fmt_1(yang_stmt *ys, goto done; } if (yp != NULL && /* XXX rm */ - yp->yn_keyword != Y_MODULE && - yp->yn_keyword != Y_SUBMODULE){ + yp->ys_keyword != Y_MODULE && + yp->ys_keyword != Y_SUBMODULE){ if (yang2api_path_fmt_1((yang_stmt *)yp, 1, cb) < 0) /* recursive call */ goto done; - if (yp->yn_keyword != Y_CHOICE && yp->yn_keyword != Y_CASE) + if (yp->ys_keyword != Y_CHOICE && yp->ys_keyword != Y_CASE) cprintf(cb, "/"); } else /* top symbol - mark with name prefix */ - cprintf(cb, "/%s:", yp->yn_argument); + cprintf(cb, "/%s:", yp->ys_argument); if (inclkey){ if (ys->ys_keyword != Y_CHOICE && ys->ys_keyword != Y_CASE) @@ -1241,7 +1241,7 @@ yang2api_path_fmt_1(yang_stmt *ys, } else{ if (ys->ys_keyword == Y_LEAF && yp && - yp->yn_keyword == Y_LIST){ + yp->ys_keyword == Y_LIST){ if (yang_key_match(yp, ys->ys_argument) == 0) cprintf(cb, "%s", ys->ys_argument); /* Not if leaf and key */ } @@ -1521,7 +1521,7 @@ xml_tree_prune_flagged_sub(cxobj *xt, } /* If it is key dont remove it yet (see second round) */ if (yt){ - if ((iskey = yang_key_match((yang_node*)yt, xml_name(x))) < 0) + if ((iskey = yang_key_match(yt, xml_name(x))) < 0) goto done; if (iskey){ anykey++; @@ -1549,7 +1549,7 @@ xml_tree_prune_flagged_sub(cxobj *xt, while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL) { /* If it is key remove it here */ if (yt){ - if ((iskey = yang_key_match((yang_node*)yt, xml_name(x))) < 0) + if ((iskey = yang_key_match(yt, xml_name(x))) < 0) goto done; if (iskey && xml_purge(x) < 0) goto done; @@ -1726,7 +1726,7 @@ xml_non_config_data(cxobj *xt, int xml_spec_populate_rpc(clicon_handle h, cxobj *xrpc, - yang_spec *yspec) + yang_stmt *yspec) { int retval = -1; yang_stmt *yrpc = NULL; /* yang node */ @@ -1743,12 +1743,12 @@ xml_spec_populate_rpc(clicon_handle h, if (ys_module_by_xml(yspec, x, &ymod) < 0) goto done; if (ymod != NULL) - yrpc = yang_find((yang_node*)ymod, Y_RPC, xml_name(x)); + yrpc = yang_find(ymod, Y_RPC, xml_name(x)); /* Non-strict semantics: loop through all modules to find the node */ if (yrpc){ xml_spec_set(x, yrpc); - if ((yi = yang_find((yang_node*)yrpc, Y_INPUT, NULL)) != NULL){ + if ((yi = yang_find(yrpc, Y_INPUT, NULL)) != NULL){ /* kludge rpc -> input XXX THIS HIDES AN ERROR IN xml_spec_populate */ xml_spec_set(x, yi); if (xml_apply(x, CX_ELMNT, xml_spec_populate, yspec) < 0) @@ -1777,25 +1777,25 @@ xml_spec_populate(cxobj *x, { int retval = -1; // clicon_handle h = (clicon_handle)arg; - yang_spec *yspec = NULL; /* yang spec */ + yang_stmt *yspec = NULL; /* yang spec */ yang_stmt *y = NULL; /* yang node */ yang_stmt *yparent; /* yang parent */ yang_stmt *ymod; /* yang module */ cxobj *xp = NULL; /* xml parent */ char *name; - yspec = (yang_spec*)arg; + yspec = (yang_stmt*)arg; if (xml_spec(x)) ; // goto ok; xp = xml_parent(x); name = xml_name(x); if (xp && (yparent = xml_spec(xp)) != NULL) - y = yang_find_datanode((yang_node*)yparent, name); + y = yang_find_datanode(yparent, name); else if (yspec){ if (ys_module_by_xml(yspec, x, &ymod) < 0) goto done; if (ymod != NULL) - y = yang_find_schemanode((yang_node*)ymod, name); + y = yang_find_schemanode(ymod, name); } if (y) xml_spec_set(x, y); @@ -1848,7 +1848,7 @@ xml_spec_populate(cxobj *x, * @see api_path2xml For api-path to xml tree */ int -api_path2xpath(yang_spec *yspec, +api_path2xpath(yang_stmt *yspec, cvec *cvv, int offset, cbuf *xpath) @@ -1881,10 +1881,10 @@ api_path2xpath(yang_spec *yspec, clicon_err(OE_YANG, ENOENT, "No such yang module: %s", prefix); goto fail; } - y = yang_find_datanode((yang_node*)ymod, name); + y = yang_find_datanode(ymod, name); } else - y = yang_find_datanode((yang_node*)y, name); + y = yang_find_datanode(y, name); if (y == NULL){ clicon_err(OE_YANG, errno, "Unknown element: '%s'", name); goto fail; @@ -1955,10 +1955,10 @@ static int api_path2xml_vec(char **vec, int nvec, cxobj *x0, - yang_node *y0, + yang_stmt *y0, yang_class nodeclass, cxobj **xpathp, - yang_node **ypathp) + yang_stmt **ypathp) { int retval = -1; int j; @@ -1997,22 +1997,22 @@ api_path2xml_vec(char **vec, /* Split into prefix and localname */ if (nodeid_split(nodeid, &prefix, &name) < 0) goto done; - if (y0->yn_keyword == Y_SPEC){ /* top-node */ + if (y0->ys_keyword == Y_SPEC){ /* top-node */ if (prefix == NULL){ clicon_err(OE_XML, EINVAL, "api-path element '%s', expected prefix:name", nodeid); goto fail; } - if ((ymod = yang_find_module_by_name((yang_spec*)y0, prefix)) == NULL){ + if ((ymod = yang_find_module_by_name(y0, prefix)) == NULL){ clicon_err(OE_YANG, EINVAL, "api-path element prefix: '%s', no such yang module", prefix); goto fail; } namespace = yang_find_mynamespace(ymod); - y0 = (yang_node*)ymod; + y0 = ymod; } y = (nodeclass==YC_SCHEMANODE)? - yang_find_schemanode((yang_node*)y0, name): - yang_find_datanode((yang_node*)y0, name); + yang_find_schemanode(y0, name): + yang_find_datanode(y0, name); if (y == NULL){ clicon_err(OE_YANG, EINVAL, "api-path name: '%s', no such yang element", name); goto fail; @@ -2082,7 +2082,7 @@ api_path2xml_vec(char **vec, goto done; } if ((retval = api_path2xml_vec(vec+1, nvec-1, - x, (yang_node*)y, + x, y, nodeclass, xpathp, ypathp)) < 1) goto done; @@ -2127,11 +2127,11 @@ api_path2xml_vec(char **vec, */ int api_path2xml(char *api_path, - yang_spec *yspec, + yang_stmt *yspec, cxobj *xtop, yang_class nodeclass, cxobj **xbotp, - yang_node **ybotp) + yang_stmt **ybotp) { int retval = -1; char **vec = NULL; @@ -2155,7 +2155,7 @@ api_path2xml(char *api_path, } nvec--; /* NULL-terminated */ if ((retval = api_path2xml_vec(vec+1, nvec, - xtop, (yang_node*)yspec, nodeclass, + xtop, yspec, nodeclass, xbotp, ybotp)) < 1) goto done; xml_yang_root(*xbotp, &xroot); @@ -2229,7 +2229,7 @@ xmlns_assign(cxobj *x) */ static int xml_merge1(cxobj *x0, - yang_node *y0, + yang_stmt *y0, cxobj *x0p, cxobj *x1, char **reason) @@ -2250,7 +2250,7 @@ xml_merge1(cxobj *x0, assert(y0); x1name = xml_name(x1); - if (y0->yn_keyword == Y_LEAF_LIST || y0->yn_keyword == Y_LEAF){ + if (y0->ys_keyword == Y_LEAF_LIST || y0->ys_keyword == Y_LEAF){ x1bstr = xml_body(x1); if (x0==NULL){ if ((x0 = xml_new(x1name, x0p, (yang_stmt*)y0)) == NULL) @@ -2300,7 +2300,7 @@ xml_merge1(cxobj *x0, x0c = NULL; if (yc && match_base_child(x0, x1c, yc, &x0c) < 0) goto done; - if (xml_merge1(x0c, (yang_node*)yc, x0, x1c, reason) < 0) + if (xml_merge1(x0c, yc, x0, x1c, reason) < 0) goto done; if (*reason != NULL) goto ok; @@ -2339,7 +2339,7 @@ xml_merge1(cxobj *x0, int xml_merge(cxobj *x0, cxobj *x1, - yang_spec *yspec, + yang_stmt *yspec, char **reason) { int retval = -1; @@ -2370,7 +2370,7 @@ xml_merge(cxobj *x0, goto ok; } /* Get yang spec of the child */ - if ((yc = yang_find_datanode((yang_node*)ymod, x1cname)) == NULL){ + if ((yc = yang_find_datanode(ymod, x1cname)) == NULL){ if (reason){ if ((cbr = cbuf_new()) == NULL){ clicon_err(OE_XML, errno, "cbuf_new"); @@ -2391,7 +2391,7 @@ xml_merge(cxobj *x0, * it is treated as a match, and x0c will remain * If it is overwritten, then x0c should be removed here. */ - if (xml_merge1(x0c, (yang_node*)yc, x0, x1c, reason) < 0) + if (xml_merge1(x0c, yc, x0, x1c, reason) < 0) goto done; if (*reason != NULL) break; @@ -2422,7 +2422,7 @@ yang_enum_int_value(cxobj *node, int32_t *val) { int retval = -1; - yang_spec *yspec; + yang_stmt *yspec; yang_stmt *ys; yang_stmt *ytype; yang_stmt *yrestype; /* resolved type */ @@ -2436,17 +2436,17 @@ yang_enum_int_value(cxobj *node, goto done; if ((yspec = ys_spec(ys)) == NULL) goto done; - if ((ytype = yang_find((yang_node *)ys, Y_TYPE, NULL)) == NULL) + if ((ytype = yang_find(ys, Y_TYPE, NULL)) == NULL) goto done; if (yang_type_resolve(ys, ys, ytype, &yrestype, NULL, NULL, NULL, NULL) < 0) goto done; if (yrestype==NULL || strcmp(yrestype->ys_argument, "enumeration")) goto done; - if ((yenum = yang_find((yang_node *)yrestype, Y_ENUM, xml_body(node))) == NULL) + if ((yenum = yang_find(yrestype, Y_ENUM, xml_body(node))) == NULL) goto done; /* Should assign value if yval not found */ - if ((yval = yang_find((yang_node *)yenum, Y_VALUE, NULL)) == NULL) + if ((yval = yang_find(yenum, Y_VALUE, NULL)) == NULL) goto done; /* reason is string containing why int could not be parsed */ if (parse_int32(yval->ys_argument, val, &reason) < 0) diff --git a/lib/src/clixon_xml_parse.h b/lib/src/clixon_xml_parse.h index 35ee2dee..d93754d3 100644 --- a/lib/src/clixon_xml_parse.h +++ b/lib/src/clixon_xml_parse.h @@ -50,7 +50,7 @@ struct xml_parse_yacc_arg{ cxobj *ya_xelement; /* xml active element */ cxobj *ya_xparent; /* xml parent element*/ int ya_skipspace; /* If set, remove all non-terminal bodies (strip pretty-print) */ - yang_spec *ya_yspec; /* If set, top-level yang-spec */ + yang_stmt *ya_yspec; /* If set, top-level yang-spec */ int ya_lex_state; /* lex start condition (AMPERSAND) */ }; diff --git a/lib/src/clixon_xml_sort.c b/lib/src/clixon_xml_sort.c index 99f1d474..62d55b01 100644 --- a/lib/src/clixon_xml_sort.c +++ b/lib/src/clixon_xml_sort.c @@ -145,7 +145,7 @@ xml_cv_cache(cxobj *x, int xml_child_spec(cxobj *x, cxobj *xp, - yang_spec *yspec, + yang_stmt *yspec, yang_stmt **yresult) { int retval = -1; @@ -161,11 +161,11 @@ xml_child_spec(cxobj *x, /* First case: parent already has an associated yang statement, * then find matching child of that */ if (yparent->ys_keyword == Y_RPC){ - if ((yi = yang_find((yang_node*)yparent, Y_INPUT, NULL)) != NULL) - y = yang_find_datanode((yang_node*)yi, name); + if ((yi = yang_find(yparent, Y_INPUT, NULL)) != NULL) + y = yang_find_datanode(yi, name); } else - y = yang_find_datanode((yang_node*)yparent, name); + y = yang_find_datanode(yparent, name); } else if (yspec){ /* Second case, this is a "root", need to find yang stmt from spec @@ -173,13 +173,13 @@ xml_child_spec(cxobj *x, if (ys_module_by_xml(yspec, xp, &ymod) < 0) goto done; if (ymod != NULL) - y = yang_find_schemanode((yang_node*)ymod, name); + y = yang_find_schemanode(ymod, name); } else y = NULL; /* kludge rpc -> input */ - if (y && y->ys_keyword == Y_RPC && yang_find((yang_node*)y, Y_INPUT, NULL)) - y = yang_find((yang_node*)y, Y_INPUT, NULL); + if (y && y->ys_keyword == Y_RPC && yang_find(y, Y_INPUT, NULL)) + y = yang_find(y, Y_INPUT, NULL); *yresult = y; retval = 0; done: @@ -256,7 +256,7 @@ xml_cmp(const void* arg1, * otherwise sort according to key */ if (yang_config(y1)==0 || - yang_find((yang_node*)y1, Y_ORDERED_BY, "user") != NULL){ + yang_find(y1, Y_ORDERED_BY, "user") != NULL){ equal = nr1-nr2; goto done; /* Ordered by user or state data : maintain existing order */ } @@ -349,7 +349,7 @@ xml_cmp1(cxobj *x, match = strcmp(name, xml_name(x)); break; case Y_LEAF_LIST: /* Match with name and value */ - if (userorder && yang_find((yang_node*)y, Y_ORDERED_BY, "user") != NULL) + if (userorder && yang_find(y, Y_ORDERED_BY, "user") != NULL) *userorder=1; if ((b=xml_body(x)) == NULL) match = 1; @@ -357,7 +357,7 @@ xml_cmp1(cxobj *x, match = strcmp(keyval[0], b); break; case Y_LIST: /* Match with array of key values */ - if (userorder && yang_find((yang_node*)y, Y_ORDERED_BY, "user") != NULL) + if (userorder && yang_find(y, Y_ORDERED_BY, "user") != NULL) *userorder=1; /* All must match */ for (i=0; iyp_keyword = Y_SPEC; + yspec->ys_keyword = Y_SPEC; return yspec; } @@ -254,32 +254,32 @@ ys_free(yang_stmt *ys) /*! Free a yang specification recursively */ int -yspec_free(yang_spec *yspec) +yspec_free(yang_stmt *yspec) { int i; yang_stmt *ys; - for (i=0; iyp_len; i++){ - if ((ys = yspec->yp_stmt[i]) != NULL) + for (i=0; iys_len; i++){ + if ((ys = yspec->ys_stmt[i]) != NULL) ys_free(ys); } - if (yspec->yp_stmt) - free(yspec->yp_stmt); + if (yspec->ys_stmt) + free(yspec->ys_stmt); free(yspec); return 0; } /*! Allocate larger yang statement vector adding empty field last */ static int -yn_realloc(yang_node *yn) +yn_realloc(yang_stmt *yn) { - yn->yn_len++; + yn->ys_len++; - if ((yn->yn_stmt = realloc(yn->yn_stmt, (yn->yn_len)*sizeof(yang_stmt *))) == 0){ + if ((yn->ys_stmt = realloc(yn->ys_stmt, (yn->ys_len)*sizeof(yang_stmt *))) == 0){ clicon_err(OE_YANG, errno, "realloc"); return -1; } - yn->yn_stmt[yn->yn_len - 1] = NULL; /* init field */ + yn->ys_stmt[yn->ys_len - 1] = NULL; /* init field */ return 0; } @@ -338,7 +338,7 @@ ys_cp(yang_stmt *ynew, if ((ycn = ys_dup(yco)) == NULL) goto done; ynew->ys_stmt[i] = ycn; - ycn->ys_parent = (yang_node*)ynew; + ycn->ys_parent = ynew; } retval = 0; done: @@ -373,20 +373,20 @@ ys_dup(yang_stmt *old) /*! Insert yang statement as child of a parent yang_statement, last in list * - * @param[in] yn_parent Add child to this parent + * @param[in] ys_parent Add child to this parent * @param[in] ys_child Add this child * Also add parent to child as up-pointer */ int -yn_insert(yang_node *yn_parent, +yn_insert(yang_stmt *ys_parent, yang_stmt *ys_child) { - int pos = yn_parent->yn_len; + int pos = ys_parent->ys_len; - if (yn_realloc(yn_parent) < 0) + if (yn_realloc(ys_parent) < 0) return -1; - yn_parent->yn_stmt[pos] = ys_child; - ys_child->ys_parent = yn_parent; + ys_parent->ys_stmt[pos] = ys_child; + ys_child->ys_parent = ys_parent; return 0; } @@ -401,14 +401,14 @@ yn_insert(yang_node *yn_parent, * @endcode */ yang_stmt * -yn_each(yang_node *yn, +yn_each(yang_stmt *yn, yang_stmt *ys) { yang_stmt *yc = NULL; int i; - for (i=0; iyn_len; i++){ - yc = yn->yn_stmt[i]; + for (i=0; iys_len; i++){ + yc = yn->ys_stmt[i]; if (ys==NULL) return yc; if (ys==yc) @@ -429,7 +429,7 @@ yn_each(yang_node *yn, * @see yang_match returns number of matches */ yang_stmt * -yang_find(yang_node *yn, +yang_find(yang_stmt *yn, int keyword, const char *argument) { @@ -437,8 +437,8 @@ yang_find(yang_node *yn, int i; int match = 0; - for (i=0; iyn_len; i++){ - ys = yn->yn_stmt[i]; + for (i=0; iys_len; i++){ + ys = yn->ys_stmt[i]; if (keyword == 0 || ys->ys_keyword == keyword){ if (argument == NULL) match++; @@ -463,7 +463,7 @@ yang_find(yang_node *yn, * @see yang_find */ int -yang_match(yang_node *yn, +yang_match(yang_stmt *yn, int keyword, char *argument) { @@ -471,8 +471,8 @@ yang_match(yang_node *yn, int i; int match = 0; - for (i=0; iyn_len; i++){ - ys = yn->yn_stmt[i]; + for (i=0; iys_len; i++){ + ys = yn->ys_stmt[i]; if (keyword == 0 || ys->ys_keyword == keyword){ if (argument == NULL) match++; @@ -493,7 +493,7 @@ yang_match(yang_node *yn, * @note May deviate from RFC since it explores choice/case not just return it. */ yang_stmt * -yang_find_datanode(yang_node *yn, +yang_find_datanode(yang_stmt *yn, char *argument) { yang_stmt *ys = NULL; @@ -501,13 +501,13 @@ yang_find_datanode(yang_node *yn, yang_stmt *ysmatch = NULL; int i, j; - for (i=0; iyn_len; i++){ - ys = yn->yn_stmt[i]; + for (i=0; iys_len; i++){ + ys = yn->ys_stmt[i]; if (ys->ys_keyword == Y_CHOICE){ /* Look for its children */ for (j=0; jys_len; j++){ yc = ys->ys_stmt[j]; if (yc->ys_keyword == Y_CASE) /* Look for its children */ - ysmatch = yang_find_datanode((yang_node*)yc, argument); + ysmatch = yang_find_datanode(yc, argument); else if (yang_datanode(yc)){ if (argument == NULL) @@ -542,7 +542,7 @@ yang_find_datanode(yang_node *yn, * @see yang_find_datanode */ yang_stmt * -yang_find_schemanode(yang_node *yn, +yang_find_schemanode(yang_stmt *yn, char *argument) { yang_stmt *ys = NULL; @@ -550,13 +550,13 @@ yang_find_schemanode(yang_node *yn, yang_stmt *ysmatch = NULL; int i, j; - for (i=0; iyn_len; i++){ - ys = yn->yn_stmt[i]; + for (i=0; iys_len; i++){ + ys = yn->ys_stmt[i]; if (ys->ys_keyword == Y_CHOICE){ /* Look for its children */ for (j=0; jys_len; j++){ yc = ys->ys_stmt[j]; if (yc->ys_keyword == Y_CASE) /* Look for its children */ - ysmatch = yang_find_schemanode((yang_node*)yc, argument); + ysmatch = yang_find_schemanode(yc, argument); else if (yang_schemanode(yc)){ if (argument == NULL) @@ -604,7 +604,7 @@ yang_find_myprefix(yang_stmt *ys) clicon_err(OE_YANG, 0, "My yang module not found"); goto done; } - if ((yprefix = yang_find((yang_node*)ymod, Y_PREFIX, NULL)) == NULL) + if ((yprefix = yang_find(ymod, Y_PREFIX, NULL)) == NULL) goto done; prefix = yprefix->ys_argument; done: @@ -631,7 +631,7 @@ yang_find_mynamespace(yang_stmt *ys) clicon_err(OE_YANG, 0, "My yang module not found"); goto done; } - if ((ynamespace = yang_find((yang_node*)ymod, Y_NAMESPACE, NULL)) == NULL) + if ((ynamespace = yang_find(ymod, Y_NAMESPACE, NULL)) == NULL) goto done; namespace = ynamespace->ys_argument; done: @@ -640,18 +640,18 @@ yang_find_mynamespace(yang_stmt *ys) /*! If a given yang stmt has a choice/case as parent, return the choice statement */ -yang_node * +yang_stmt * yang_choice(yang_stmt *y) { - yang_node *yp; + yang_stmt *yp; if ((yp = y->ys_parent) != NULL){ - switch (yp->yn_keyword){ + switch (yp->ys_keyword){ case Y_CHOICE: return yp; break; case Y_CASE: - return yp->yn_parent; + return yp->ys_parent; break; default: break; @@ -668,15 +668,15 @@ yang_choice(yang_stmt *y) * @retval 1 found */ static int -order1(yang_node *yp, +order1(yang_stmt *yp, yang_stmt *y, int *index) { yang_stmt *ys; int i; - for (i=0; iyn_len; i++){ - ys = yp->yn_stmt[i]; + for (i=0; iys_len; i++){ + ys = yp->ys_stmt[i]; if (!yang_datanode(ys)) continue; if (ys==y) @@ -696,8 +696,8 @@ order1(yang_node *yp, int yang_order(yang_stmt *y) { - yang_node *yp; - yang_node *ypp; + yang_stmt *yp; + yang_stmt *ypp; yang_stmt *ym; int i; int j=0; @@ -710,11 +710,11 @@ yang_order(yang_stmt *y) * Example: * The order of x and y cannot be compared within a single yang module since they belong to different */ - if (yp->yn_keyword == Y_MODULE || yp->yn_keyword == Y_SUBMODULE){ - ypp = yp->yn_parent; /* yang spec */ - for (i=0; iyn_len; i++){ /* iterate through other modules */ - ym = ypp->yn_stmt[i]; - if (yp == (yang_node*)ym) + if (yp->ys_keyword == Y_MODULE || yp->ys_keyword == Y_SUBMODULE){ + ypp = yp->ys_parent; /* yang spec */ + for (i=0; iys_len; i++){ /* iterate through other modules */ + ym = ypp->ys_stmt[i]; + if (yp == ym) break; tot += ym->ys_len; } @@ -750,7 +750,7 @@ yang_key2str(int keyword) * @note works for xml namespaces (xmlns / xmlns:ns) */ int -ys_module_by_xml(yang_spec *ysp, +ys_module_by_xml(yang_stmt *ysp, cxobj *xt, yang_stmt **ymodp) { @@ -797,7 +797,7 @@ ys_module_by_xml(yang_spec *ysp, yang_stmt * ys_module(yang_stmt *ys) { - yang_node *yn; + yang_stmt *yn; if (ys==NULL || ys->ys_keyword==Y_SPEC) return NULL; @@ -812,7 +812,7 @@ ys_module(yang_stmt *ys) } yn = ys->ys_parent; /* Some extra stuff to ensure ys is a stmt */ - if (yn && yn->yn_keyword == Y_SPEC) + if (yn && yn->ys_keyword == Y_SPEC) yn = NULL; ys = (yang_stmt*)yn; } @@ -826,17 +826,17 @@ ys_module(yang_stmt *ys) * @see ys_module * @see ys_yang_augment_node where shortcut is set */ -yang_spec * +yang_stmt * ys_spec(yang_stmt *ys) { - yang_node *yn; + yang_stmt *yn; while (ys != NULL && ys->ys_keyword != Y_SPEC){ yn = ys->ys_parent; ys = (yang_stmt*)yn; } /* Here it is either NULL or is a typedef-kind yang-stmt */ - return (yang_spec*)ys; + return (yang_stmt*)ys; } /* Assume argument is id on the type: <[prefix:]id>, return 'id' @@ -895,7 +895,7 @@ yang_find_module_by_prefix(yang_stmt *ys, yang_stmt *yprefix; yang_stmt *my_ymod; yang_stmt *ymod = NULL; - yang_spec *yspec; + yang_stmt *yspec; char *myprefix; if ((yspec = ys_spec(ys)) == NULL){ @@ -906,31 +906,24 @@ yang_find_module_by_prefix(yang_stmt *ys, clicon_err(OE_YANG, 0, "My yang module not found"); goto done; } -#if 0 - if (my_ymod->ys_keyword != Y_MODULE && - my_ymod->ys_keyword != Y_SUBMODULE){ - clicon_err(OE_YANG, 0, "%s not module or sub-module", my_ymod->ys_argument); - goto done; - } -#endif myprefix = yang_find_myprefix(ys); if (myprefix && strcmp(myprefix, prefix) == 0){ ymod = my_ymod; goto done; } yimport = NULL; - while ((yimport = yn_each((yang_node*)my_ymod, yimport)) != NULL) { + while ((yimport = yn_each(my_ymod, yimport)) != NULL) { if (yimport->ys_keyword != Y_IMPORT && yimport->ys_keyword != Y_INCLUDE) continue; - if ((yprefix = yang_find((yang_node*)yimport, Y_PREFIX, NULL)) != NULL && + if ((yprefix = yang_find(yimport, Y_PREFIX, NULL)) != NULL && strcmp(yprefix->ys_argument, prefix) == 0){ break; } } if (yimport){ - if ((ymod = yang_find((yang_node*)yspec, Y_MODULE, yimport->ys_argument)) == NULL && - (ymod = yang_find((yang_node*)yspec, Y_SUBMODULE, yimport->ys_argument)) == NULL){ + if ((ymod = yang_find(yspec, Y_MODULE, yimport->ys_argument)) == NULL && + (ymod = yang_find(yspec, Y_SUBMODULE, yimport->ys_argument)) == NULL){ clicon_err(OE_YANG, 0, "No module or sub-module found with prefix %s", prefix); yimport = NULL; @@ -951,15 +944,15 @@ yang_find_module_by_prefix(yang_stmt *ys, * @see yang_find_module_by_prefix module-specific prefix */ yang_stmt * -yang_find_module_by_namespace(yang_spec *yspec, +yang_find_module_by_namespace(yang_stmt *yspec, char *namespace) { yang_stmt *ymod = NULL; if (namespace == NULL) goto done; - while ((ymod = yn_each((yang_node*)yspec, ymod)) != NULL) { - if (yang_find((yang_node*)ymod, Y_NAMESPACE, namespace) != NULL) + while ((ymod = yn_each(yspec, ymod)) != NULL) { + if (yang_find(ymod, Y_NAMESPACE, namespace) != NULL) break; } done: @@ -976,12 +969,12 @@ yang_find_module_by_namespace(yang_spec *yspec, * @see yang_find_module_by_prefix module-specific prefix */ yang_stmt * -yang_find_module_by_name(yang_spec *yspec, +yang_find_module_by_name(yang_stmt *yspec, char *name) { yang_stmt *ymod = NULL; - while ((ymod = yn_each((yang_node*)yspec, ymod)) != NULL) + while ((ymod = yn_each(yspec, ymod)) != NULL) if ((ymod->ys_keyword == Y_MODULE || ymod->ys_keyword == Y_SUBMODULE) && strcmp(ymod->ys_argument, name)==0) return ymod; @@ -1008,7 +1001,7 @@ quotedstring(char *s) */ int yang_print(FILE *f, - yang_node *yn) + yang_stmt *yn) { int retval = -1; cbuf *cb = NULL; @@ -1040,7 +1033,7 @@ yang_print(FILE *f, */ int yang_print_cbuf(cbuf *cb, - yang_node *yn, + yang_stmt *yn, int marginal) { yang_stmt *ys = NULL; @@ -1059,7 +1052,7 @@ yang_print_cbuf(cbuf *cb, } if (ys->ys_len){ cprintf(cb, " {\n"); - yang_print_cbuf(cb, (yang_node*)ys, marginal+3); + yang_print_cbuf(cb, ys, marginal+3); cprintf(cb, "%*s%s\n", marginal, "", "}"); } else @@ -1089,7 +1082,7 @@ ys_populate_leaf(yang_stmt *ys, { int retval = -1; cg_var *cv = NULL; - yang_node *yparent; + yang_stmt *yparent; yang_stmt *ydef; enum cv_type cvtype = CGV_ERR; int cvret; @@ -1124,7 +1117,7 @@ ys_populate_leaf(yang_stmt *ys, /* 3. Check if default value. Here we parse the string in the default-stmt * and add it to the leafs cv. */ - if ((ydef = yang_find((yang_node*)ys, Y_DEFAULT, NULL)) != NULL){ + if ((ydef = yang_find(ys, Y_DEFAULT, NULL)) != NULL){ if ((cvret = cv_parse1(ydef->ys_argument, cv, &reason)) < 0){ /* error */ clicon_err(OE_YANG, errno, "parsing cv"); goto done; @@ -1141,7 +1134,7 @@ ys_populate_leaf(yang_stmt *ys, } /* 4. Check if leaf is part of list, if key exists mark leaf as key/unique */ - if (yparent && yparent->yn_keyword == Y_LIST){ + if (yparent && yparent->ys_keyword == Y_LIST){ if ((ret = yang_key_match(yparent, ys->ys_argument)) < 0) goto done; if (ret == 1) @@ -1161,7 +1154,7 @@ ys_populate_list(yang_stmt *ys, { yang_stmt *ykey; - if ((ykey = yang_find((yang_node*)ys, Y_KEY, NULL)) == NULL) + if ((ykey = yang_find(ys, Y_KEY, NULL)) == NULL) return 0; cvec_free(ys->ys_cvec); if ((ys->ys_cvec = yang_arg2cvec(ykey, " ")) == NULL) @@ -1266,7 +1259,7 @@ ys_populate_range(yang_stmt *ys, void *arg) { int retval = -1; - yang_node *yparent; /* type */ + yang_stmt *yparent; /* type */ char *origtype; /* orig type */ yang_stmt *yrestype; /* resolved type */ char *restype; /* resolved type */ @@ -1275,7 +1268,7 @@ ys_populate_range(yang_stmt *ys, enum cv_type cvtype = CGV_ERR; yparent = ys->ys_parent; /* Find parent: type */ - if (yparent->yn_keyword != Y_TYPE){ + if (yparent->ys_keyword != Y_TYPE){ clicon_err(OE_YANG, 0, "parent should be type"); goto done; } @@ -1315,11 +1308,11 @@ ys_populate_length(yang_stmt *ys, void *arg) { int retval = -1; - yang_node *yparent; /* type */ + yang_stmt *yparent; /* type */ enum cv_type cvtype = CGV_ERR; yparent = ys->ys_parent; /* Find parent: type */ - if (yparent->yn_keyword != Y_TYPE){ + if (yparent->ys_keyword != Y_TYPE){ clicon_err(OE_YANG, 0, "parent should be type"); goto done; } @@ -1344,14 +1337,14 @@ ys_populate_type(yang_stmt *ys, yang_stmt *ybase; if (strcmp(ys->ys_argument, "decimal64") == 0){ - if (yang_find((yang_node*)ys, Y_FRACTION_DIGITS, NULL) == NULL){ + if (yang_find(ys, Y_FRACTION_DIGITS, NULL) == NULL){ clicon_err(OE_YANG, 0, "decimal64 type requires fraction-digits sub-statement"); goto done; } } else if (strcmp(ys->ys_argument, "identityref") == 0){ - if ((ybase = yang_find((yang_node*)ys, Y_BASE, NULL)) == NULL){ + if ((ybase = yang_find(ys, Y_BASE, NULL)) == NULL){ clicon_err(OE_YANG, 0, "identityref type requires base sub-statement"); goto done; } @@ -1409,7 +1402,7 @@ ys_populate_identity(yang_stmt *ys, * AND populate the base identity recursively */ yc = NULL; - while ((yc = yn_each((yang_node*)ys, yc)) != NULL) { + while ((yc = yn_each(ys, yc)) != NULL) { if (yc->ys_keyword != Y_BASE) continue; baseid = yc->ys_argument; @@ -1527,7 +1520,7 @@ ys_populate_unknown(yang_stmt *ys) name = yarg_id(ys); /* This is the type to resolve */ if ((ymod = yang_find_module_by_prefix(ys, prefix)) == NULL) goto ok; /* shouldnt happen */ - if (yang_find((yang_node*)ymod, Y_EXTENSION, name) == NULL){ + if (yang_find(ymod, Y_EXTENSION, name) == NULL){ clicon_err(OE_YANG, errno, "Extension %s:%s not found", prefix, name); goto done; } @@ -1620,17 +1613,17 @@ ys_grouping_resolve(yang_stmt *ys, int retval = -1; yang_stmt *ymodule; yang_stmt *ygrouping = NULL; - yang_node *yn; + yang_stmt *yn; /* find the grouping associated with argument and expand(?) */ if (prefix){ /* Go to top and find import that matches */ if ((ymodule = yang_find_module_by_prefix(ys, prefix)) != NULL) - ygrouping = yang_find((yang_node*)ymodule, Y_GROUPING, name); + ygrouping = yang_find(ymodule, Y_GROUPING, name); } else while (1){ /* Check upwards in hierarchy for matching groupings */ - if ((yn = ys->ys_parent) == NULL || yn->yn_keyword == Y_SPEC) + if ((yn = ys->ys_parent) == NULL || yn->ys_keyword == Y_SPEC) break; /* Here find grouping */ if ((ygrouping = yang_find(yn, Y_GROUPING, name)) != NULL) @@ -1658,7 +1651,7 @@ ys_grouping_resolve(yang_stmt *ys, */ static int yang_augment_node(yang_stmt *ys, - yang_spec *ysp) + yang_stmt *ysp) { int retval = -1; char *schema_nodeid; @@ -1685,7 +1678,7 @@ yang_augment_node(yang_stmt *ys, if ((yc = ys_dup(ys->ys_stmt[i])) == NULL) goto done; yc->ys_module = ymod; - if (yn_insert((yang_node*)ytarget, yc) < 0) + if (yn_insert(ytarget, yc) < 0) goto done; } ok: @@ -1696,7 +1689,7 @@ yang_augment_node(yang_stmt *ys, /*! Find all top-level augments and change original datamodels. */ static int -yang_augment_spec(yang_spec *ysp, +yang_augment_spec(yang_stmt *ysp, int modnr) { int retval = -1; @@ -1706,8 +1699,8 @@ yang_augment_spec(yang_spec *ysp, int j; i = modnr; - while (iyp_len){ /* Loop through modules and sub-modules */ - ym = ysp->yp_stmt[i++]; + while (iys_len){ /* Loop through modules and sub-modules */ + ym = ysp->ys_stmt[i++]; j = 0; while (jys_len){ /* Top-level symbols in modules */ ys = ym->ys_stmt[j++]; @@ -1737,7 +1730,7 @@ yang_augment_spec(yang_spec *ysp, macro-expand them */ static int -yang_expand(yang_node *yn) +yang_expand(yang_stmt *yn) { int retval = -1; yang_stmt *ys = NULL; @@ -1752,8 +1745,8 @@ yang_expand(yang_node *yn) /* Cannot use yang_apply here since child-list is modified (is destructive) */ i = 0; - while (iyn_len){ - ys = yn->yn_stmt[i]; + while (iys_len){ + ys = yn->ys_stmt[i]; switch(ys->ys_keyword){ case Y_USES: /* Split argument into prefix and name */ @@ -1774,7 +1767,7 @@ yang_expand(yang_node *yn) If not, this needs to be done before we can insert it into the 'uses' place */ if ((ygrouping->ys_flags & YANG_FLAG_MARK) == 0){ - if (yang_expand((yang_node*)ygrouping) < 0) + if (yang_expand(ygrouping) < 0) goto done; ygrouping->ys_flags |= YANG_FLAG_MARK; /* Mark as expanded */ } @@ -1787,23 +1780,23 @@ yang_expand(yang_node *yn) * Is there a case when glen == 0? YES AND THIS BREAKS */ if (glen != 1){ - size = (yn->yn_len - i - 1)*sizeof(struct yang_stmt *); - yn->yn_len += glen - 1; - if (glen && (yn->yn_stmt = realloc(yn->yn_stmt, (yn->yn_len)*sizeof(yang_stmt *))) == 0){ + size = (yn->ys_len - i - 1)*sizeof(struct yang_stmt *); + yn->ys_len += glen - 1; + if (glen && (yn->ys_stmt = realloc(yn->ys_stmt, (yn->ys_len)*sizeof(yang_stmt *))) == 0){ clicon_err(OE_YANG, errno, "realloc"); return -1; } /* Then move all existing elements up from i+1 (not uses-stmt) */ if (size) - memmove(&yn->yn_stmt[i+glen], - &yn->yn_stmt[i+1], + memmove(&yn->ys_stmt[i+glen], + &yn->ys_stmt[i+1], size); } /* Then copy and insert each child element */ for (j=0; jys_stmt[j])) == NULL) goto done; - yn->yn_stmt[i+j] = yg; + yn->ys_stmt[i+j] = yg; yg->ys_parent = yn; } /* XXX: refine */ @@ -1816,9 +1809,9 @@ yang_expand(yang_node *yn) } } /* Second pass since length may have changed */ - for (i=0; iyn_len; i++){ - ys = yn->yn_stmt[i]; - if (yang_expand((yang_node*)ys) < 0) + for (i=0; iys_len; i++){ + ys = yn->ys_stmt[i]; + if (yang_expand(ys) < 0) goto done; } retval = 0; @@ -1849,7 +1842,7 @@ yang_expand(yang_node *yn) static yang_stmt * yang_parse_str(char *str, const char *name, /* just for errs */ - yang_spec *yspec) + yang_stmt *yspec) { struct clicon_yang_yacc_arg yy = {0,}; yang_stmt *ymod = NULL; @@ -1863,7 +1856,7 @@ yang_parse_str(char *str, yy.yy_parse_string = str; yy.yy_stack = NULL; yy.yy_module = NULL; /* this is the return value - the module/sub-module */ - if (ystack_push(&yy, (yang_node*)yspec) == NULL) + if (ystack_push(&yy, yspec) == NULL) goto done; if (strlen(str)){ /* Not empty */ if (yang_scan_init(&yy) < 0) @@ -1901,7 +1894,7 @@ yang_parse_str(char *str, yang_stmt * yang_parse_file(int fd, const char *name, - yang_spec *ysp) + yang_stmt *ysp) { char *buf = NULL; int i; @@ -2033,7 +2026,7 @@ yang_parse_find_match(clicon_handle h, */ static yang_stmt * yang_parse_filename(const char *filename, - yang_spec *ysp) + yang_stmt *ysp) { yang_stmt *ymod = NULL; int fd = -1; @@ -2060,7 +2053,7 @@ static yang_stmt * yang_parse_module(clicon_handle h, const char *module, const char *revision, - yang_spec *ysp) + yang_stmt *ysp) { cbuf *fbuf = NULL; int nr; @@ -2105,7 +2098,7 @@ yang_parse_module(clicon_handle h, static int yang_parse_recurse(clicon_handle h, yang_stmt *ymod, - yang_spec *ysp) + yang_stmt *ysp) { int retval = -1; yang_stmt *yi = NULL; /* import */ @@ -2116,19 +2109,19 @@ yang_parse_recurse(clicon_handle h, enum rfc_6020 keyw; /* go through all import (modules) and include(submodules) of ysp */ - while ((yi = yn_each((yang_node*)ymod, yi)) != NULL){ + while ((yi = yn_each(ymod, yi)) != NULL){ keyw = yi->ys_keyword; if (keyw != Y_IMPORT && keyw != Y_INCLUDE) continue; /* common part */ submodule = yi->ys_argument; /* Is there a specific revision (or just latest)? */ - if ((yrev = yang_find((yang_node*)yi, Y_REVISION_DATE, NULL)) != NULL) + if ((yrev = yang_find(yi, Y_REVISION_DATE, NULL)) != NULL) subrevision = yrev->ys_argument; else subrevision = NULL; /* if already loaded, ignore, else parse the file */ - if (yang_find((yang_node*)ysp, + if (yang_find(ysp, keyw==Y_IMPORT?Y_MODULE:Y_SUBMODULE, submodule) == NULL){ /* recursive call */ @@ -2151,15 +2144,15 @@ ys_schemanode_check(yang_stmt *ys, void *arg) { int retval = -1; - yang_spec *yspec; + yang_stmt *yspec; yang_stmt *yres; - yang_node *yp; + yang_stmt *yp; yp = ys->ys_parent; switch (ys->ys_keyword){ case Y_AUGMENT: - if (yp->yn_keyword == Y_MODULE || /* Not top-level */ - yp->yn_keyword == Y_SUBMODULE) + if (yp->ys_keyword == Y_MODULE || /* Not top-level */ + yp->ys_keyword == Y_SUBMODULE) break; /* fallthru */ case Y_REFINE: @@ -2223,7 +2216,7 @@ yang_features(clicon_handle h, ymod = yang_find_module_by_prefix(yt, prefix); /* Check if feature exists, and is set, otherwise remove */ - if ((yfeat = yang_find((yang_node*)ymod, Y_FEATURE, feature)) == NULL || + if ((yfeat = yang_find(ymod, Y_FEATURE, feature)) == NULL || yfeat->ys_cv == NULL || !cv_bool_get(yfeat->ys_cv)){ retval = 0; /* feature not enabled */ goto done; @@ -2267,6 +2260,7 @@ yang_features(clicon_handle h, return retval; } +#if 1 /* This will be made OBSOLETE */ /*! Merge yang submodule into the module it belongs to * Skip submodule header fields * @param[in] h Clicon handle @@ -2275,7 +2269,7 @@ yang_features(clicon_handle h, */ static int yang_merge_submodules(clicon_handle h, - yang_spec *yspec, + yang_stmt *yspec, yang_stmt *ysubm) { int retval = -1; @@ -2287,12 +2281,12 @@ yang_merge_submodules(clicon_handle h, assert(ysubm->ys_keyword == Y_SUBMODULE); /* Get parent name (via belongs-to) and find parent module */ - if ((yb = yang_find((yang_node*)ysubm, Y_BELONGS_TO, NULL)) == NULL){ + if ((yb = yang_find(ysubm, Y_BELONGS_TO, NULL)) == NULL){ clicon_err(OE_YANG, ENOENT, "submodule %s does not have a mandatory belongs-to statement", ysubm->ys_argument); goto done; } modname = yb->ys_argument; - if ((ymod = yang_find((yang_node*)yspec, Y_MODULE, modname)) == NULL){ + if ((ymod = yang_find(yspec, Y_MODULE, modname)) == NULL){ clicon_err(OE_YANG, ENOENT, "Submodule %s is loaded before/without its main module %s (you need to load the submodule together with or after the main module)", ysubm->ys_argument, modname); @@ -2314,7 +2308,7 @@ yang_merge_submodules(clicon_handle h, yc->ys_keyword == Y_YANG_VERSION) ys_free(yc); else{ - if (yn_insert((yang_node*)ymod, yc) < 0) + if (yn_insert(ymod, yc) < 0) goto done; } } @@ -2328,6 +2322,7 @@ yang_merge_submodules(clicon_handle h, done: return retval; } +#endif /*! Parse top yang module including all its sub-modules. Expand and populate yang tree * @@ -2352,7 +2347,7 @@ yang_merge_submodules(clicon_handle h, */ static int yang_parse_post(clicon_handle h, - yang_spec *yspec, + yang_stmt *yspec, int modnr) { int retval = -1; @@ -2361,49 +2356,51 @@ yang_parse_post(clicon_handle h, /* 1: Parse from text to yang parse-tree. * Iterate through modules and detect module/submodules to parse * - note the list may grow on each iteration */ - for (i=modnr; iyp_len; i++) - if (yang_parse_recurse(h, yspec->yp_stmt[i], yspec) < 0) + for (i=modnr; iys_len; i++) + if (yang_parse_recurse(h, yspec->ys_stmt[i], yspec) < 0) goto done; /* 2. Check cardinality maybe this should be done after grouping/augment */ - for (i=modnr; iyp_len; i++) - if (yang_cardinality(h, yspec->yp_stmt[i], yspec->yp_stmt[i]->ys_argument) < 0) + for (i=modnr; iys_len; i++) + if (yang_cardinality(h, yspec->ys_stmt[i], yspec->ys_stmt[i]->ys_argument) < 0) goto done; +#if 1 /* Will be OBSOLETE */ /* 3: Merge sub-modules with modules - after this step, no submodules exist * In the merge, remove submodule headers */ i = modnr; - while (iyp_len){ + while (iys_len){ int j; - if (yspec->yp_stmt[i]->ys_keyword != Y_SUBMODULE){ + if (yspec->ys_stmt[i]->ys_keyword != Y_SUBMODULE){ i++; continue; } - if (yang_merge_submodules(h, yspec, yspec->yp_stmt[i]) < 0) + if (yang_merge_submodules(h, yspec, yspec->ys_stmt[i]) < 0) goto done; /* shift down one step */ - for (j=i; jyp_len-1; j++) - yspec->yp_stmt[j] = yspec->yp_stmt[j+1]; - yspec->yp_len--; + for (j=i; jys_len-1; j++) + yspec->ys_stmt[j] = yspec->ys_stmt[j+1]; + yspec->ys_len--; } - +#endif /* OBSOLETE */ + /* 4: Check features: check if enabled and remove disabled features */ - for (i=modnr; iyp_len; i++) /* XXX */ - if (yang_features(h, yspec->yp_stmt[i]) < 0) + for (i=modnr; iys_len; i++) /* XXX */ + if (yang_features(h, yspec->ys_stmt[i]) < 0) goto done; /* 5: Go through parse tree and populate it with cv types */ - for (i=modnr; iyp_len; i++) - if (yang_apply((yang_node*)yspec->yp_stmt[i], -1, ys_populate, (void*)h) < 0) + for (i=modnr; iys_len; i++) + if (yang_apply(yspec->ys_stmt[i], -1, ys_populate, (void*)h) < 0) goto done; /* 6: Resolve all types: populate type caches. Requires eg length/range cvecs * from ys_populate step. * Must be done using static binding. */ - for (i=modnr; iyp_len; i++) - if (yang_apply((yang_node*)yspec->yp_stmt[i], Y_TYPE, ys_resolve_type, NULL) < 0) + for (i=modnr; iys_len; i++) + if (yang_apply(yspec->ys_stmt[i], Y_TYPE, ys_resolve_type, NULL) < 0) goto done; /* Up to here resolving is made in the context they are defined, rather @@ -2414,10 +2411,10 @@ yang_parse_post(clicon_handle h, */ /* 7: Macro expansion of all grouping/uses pairs. Expansion needs marking */ - for (i=modnr; iyp_len; i++){ - if (yang_expand((yang_node*)yspec->yp_stmt[i]) < 0) + for (i=modnr; iys_len; i++){ + if (yang_expand(yspec->ys_stmt[i]) < 0) goto done; - yang_apply((yang_node*)yspec->yp_stmt[i], -1, ys_flag_reset, (void*)YANG_FLAG_MARK); + yang_apply(yspec->ys_stmt[i], -1, ys_flag_reset, (void*)YANG_FLAG_MARK); } /* 8: Top-level augmentation of all modules XXX: only new modules? */ @@ -2425,8 +2422,8 @@ yang_parse_post(clicon_handle h, goto done; /* 9: sanity check of schemanode references, need more here */ - for (i=modnr; iyp_len; i++) - if (yang_apply((yang_node*)yspec->yp_stmt[i], -1, ys_schemanode_check, NULL) < 0) + for (i=modnr; iys_len; i++) + if (yang_apply(yspec->ys_stmt[i], -1, ys_schemanode_check, NULL) < 0) goto done; retval = 0; done: @@ -2447,7 +2444,7 @@ int yang_spec_parse_module(clicon_handle h, const char *module, const char *revision, - yang_spec *yspec) + yang_stmt *yspec) { int retval = -1; int modnr; /* Existing number of modules */ @@ -2462,9 +2459,9 @@ yang_spec_parse_module(clicon_handle h, goto done; } /* Apply steps 2.. on new modules, ie ones after modnr. */ - modnr = yspec->yp_len; + modnr = yspec->ys_len; /* Do not load module if it already exists */ - if (yang_find((yang_node*)yspec, Y_MODULE, module) != NULL) + if (yang_find(yspec, Y_MODULE, module) != NULL) goto ok; if (yang_parse_module(h, module, revision, yspec) == NULL) goto done; @@ -2492,14 +2489,14 @@ yang_spec_parse_module(clicon_handle h, int yang_spec_parse_file(clicon_handle h, char *filename, - yang_spec *yspec) + yang_stmt *yspec) { int retval = -1; int modnr; /* Existing number of modules */ char *base = NULL;; /* Apply steps 2.. on new modules, ie ones after modnr. */ - modnr = yspec->yp_len; + modnr = yspec->ys_len; /* Find module, and do not load file if module already exists */ if (basename(filename) == NULL){ clicon_err(OE_YANG, errno, "No basename"); @@ -2511,7 +2508,7 @@ yang_spec_parse_file(clicon_handle h, } if (index(base, '@') != NULL) *index(base, '@') = '\0'; - if (yang_find((yang_node*)yspec, Y_MODULE, base) != NULL) + if (yang_find(yspec, Y_MODULE, base) != NULL) goto ok; if (yang_parse_filename(filename, yspec) == NULL) goto done; @@ -2543,7 +2540,7 @@ yang_spec_parse_file(clicon_handle h, int yang_spec_load_dir(clicon_handle h, char *dir, - yang_spec *yspec) + yang_stmt *yspec) { int retval = -1; int ndp; @@ -2575,7 +2572,7 @@ yang_spec_load_dir(clicon_handle h, clicon_log(LOG_WARNING, "%s: No yang files found in %s", __FUNCTION__, dir); /* Apply post steps on new modules, ie ones after modnr. */ - modnr = yspec->yp_len; + modnr = yspec->ys_len; /* Load all yang files in dir */ for (i = 0; i < ndp; i++) { /* base = module name [+ @rev ] + .yang */ @@ -2613,9 +2610,9 @@ yang_spec_load_dir(clicon_handle h, /* Here only a single file is reached(taken) * Check if module already exists -> ym0/rev0 */ rev0 = 0; - if ((ym0 = yang_find((yang_node*)yspec, Y_MODULE, base)) != NULL || - (ym0 = yang_find((yang_node*)yspec, Y_SUBMODULE, base)) != NULL){ - yrev = yang_find((yang_node*)ym0, Y_REVISION, NULL); + if ((ym0 = yang_find(yspec, Y_MODULE, base)) != NULL || + (ym0 = yang_find(yspec, Y_SUBMODULE, base)) != NULL){ + yrev = yang_find(ym0, Y_REVISION, NULL); rev0 = cv_uint32_get(yrev->ys_cv); continue; /* skip if already added by specific file or module */ } @@ -2624,7 +2621,7 @@ yang_spec_load_dir(clicon_handle h, if ((ym = yang_parse_filename(filename, yspec)) == NULL) goto done; revm = 0; - if ((yrev = yang_find((yang_node*)ym, Y_REVISION, NULL)) != NULL) + if ((yrev = yang_find(ym, Y_REVISION, NULL)) != NULL) revm = cv_uint32_get(yrev->ys_cv); /* Sanity check that file revision does not match internal rev stmt */ if (revf && revm && revm != revf){ @@ -2638,16 +2635,16 @@ yang_spec_load_dir(clicon_handle h, int size; if (revm > rev0) /* Loaded module is older or eq -> remove ym */ ym = ym0; - for (j=0; jyp_len; j++) - if (yspec->yp_stmt[j] == ym) + for (j=0; jys_len; j++) + if (yspec->ys_stmt[j] == ym) break; - size = (yspec->yp_len - j - 1)*sizeof(struct yang_stmt *); - memmove(&yspec->yp_stmt[j], - &yspec->yp_stmt[j+1], + size = (yspec->ys_len - j - 1)*sizeof(struct yang_stmt *); + memmove(&yspec->ys_stmt[j], + &yspec->ys_stmt[j+1], size); ys_free(ym); - yspec->yp_len--; - yspec->yp_stmt[yspec->yp_len] = NULL; + yspec->ys_len--; + yspec->ys_stmt[yspec->ys_len] = NULL; } } if (yang_parse_post(h, yspec, modnr) < 0) @@ -2682,12 +2679,12 @@ yang_spec_load_dir(clicon_handle h, * { * return 0; * } - * yang_apply((yang_node*)ys, Y_TYPE, ys_fn, NULL); + * yang_apply(ys, Y_TYPE, ys_fn, NULL); * @endcode * @note do not delete or move around any children during this function */ int -yang_apply(yang_node *yn, +yang_apply(yang_stmt *yn, enum rfc_6020 keyword, yang_applyfn_t fn, void *arg) @@ -2697,8 +2694,8 @@ yang_apply(yang_node *yn, int i; int ret; - for (i=0; iyn_len; i++){ - ys = yn->yn_stmt[i]; + for (i=0; iys_len; i++){ + ys = yn->ys_stmt[i]; if (keyword == -1 || keyword == ys->ys_keyword){ if ((ret = fn(ys, arg)) < 0) goto done; @@ -2707,7 +2704,7 @@ yang_apply(yang_node *yn, goto done; } } - if ((ret = yang_apply((yang_node*)ys, keyword, fn, arg)) < 0) + if ((ret = yang_apply(ys, keyword, fn, arg)) < 0) goto done; if (ret > 0){ retval = ret; @@ -2730,7 +2727,7 @@ yang_apply(yang_node *yn, * @retval 0 OK */ static int -schema_nodeid_vec(yang_node *yn, +schema_nodeid_vec(yang_stmt *yn, char **vec, int nvec, enum rfc_6020 keyword, @@ -2738,7 +2735,7 @@ schema_nodeid_vec(yang_node *yn, { int retval = -1; char *arg; - yang_node *ynext; + yang_stmt *ynext; char *nodeid = NULL; int i; yang_stmt *ys; @@ -2748,10 +2745,10 @@ schema_nodeid_vec(yang_node *yn, goto done; arg = vec[0]; clicon_debug(2, "%s: key=%s arg=%s match=%s len=%d", - __FUNCTION__, yang_key2str(yn->yn_keyword), yn->yn_argument, - arg, yn->yn_len); + __FUNCTION__, yang_key2str(yn->ys_keyword), yn->ys_argument, + arg, yn->ys_len); if (strcmp(arg, "..") == 0) - ynext = yn->yn_parent; /* This could actually be a MODULE */ + ynext = yn->ys_parent; /* This could actually be a MODULE */ else{ /* ignore prefixes */ if ((nodeid = strchr(arg, ':')) == NULL) @@ -2760,8 +2757,8 @@ schema_nodeid_vec(yang_node *yn, nodeid++; match = 0; ys = NULL; - for (i=0; iyn_len; i++){ - ys = yn->yn_stmt[i]; + for (i=0; iys_len; i++){ + ys = yn->ys_stmt[i]; if (!yang_schemanode(ys)) continue; if (keyword != -1 && keyword != ys->ys_keyword) @@ -2782,7 +2779,7 @@ schema_nodeid_vec(yang_node *yn, clicon_debug(1, "%s: %s not found", __FUNCTION__, nodeid); goto ok; } - ynext = (yang_node*)ys; + ynext = ys; } if (nvec == 1){ /* match */ if (yang_schemanode((yang_stmt*)ynext)) @@ -2817,7 +2814,7 @@ schema_nodeid_vec(yang_node *yn, * Used in yang: deviation, top-level augment */ int -yang_abs_schema_nodeid(yang_spec *yspec, +yang_abs_schema_nodeid(yang_stmt *yspec, yang_stmt *yn, char *schema_nodeid, enum rfc_6020 keyword, @@ -2861,14 +2858,14 @@ yang_abs_schema_nodeid(yang_spec *yspec, ymod = yang_find_module_by_prefix(yn, prefix); if (ymod == NULL){ /* Try (global) prefix the module itself uses */ ymod = NULL; - while ((ymod = yn_each((yang_node*)yspec, ymod)) != NULL) { - if ((yprefix = yang_find((yang_node*)ymod, Y_PREFIX, NULL)) != NULL && + while ((ymod = yn_each(yspec, ymod)) != NULL) { + if ((yprefix = yang_find(ymod, Y_PREFIX, NULL)) != NULL && strcmp(yprefix->ys_argument, prefix) == 0){ break; } } } - if (schema_nodeid_vec((yang_node*)ymod, vec+1, nvec-1, keyword, yres) < 0) + if (schema_nodeid_vec(ymod, vec+1, nvec-1, keyword, yres) < 0) goto done; ok: /* yres may not be set */ retval = 0; @@ -2891,7 +2888,7 @@ yang_abs_schema_nodeid(yang_spec *yspec, * Used in yang: unique, refine, uses augment */ int -yang_desc_schema_nodeid(yang_node *yn, +yang_desc_schema_nodeid(yang_stmt *yn, char *schema_nodeid, enum rfc_6020 keyword, yang_stmt **yres) @@ -3080,7 +3077,7 @@ yang_mandatory(yang_stmt *ys) * statement with the value "true". */ if (ys->ys_keyword == Y_LEAF || ys->ys_keyword == Y_CHOICE || ys->ys_keyword == Y_ANYDATA || ys->ys_keyword == Y_ANYXML){ - if ((ym = yang_find((yang_node*)ys, Y_MANDATORY, NULL)) != NULL){ + if ((ym = yang_find(ys, Y_MANDATORY, NULL)) != NULL){ if (ym->ys_cv != NULL) /* shouldnt happen */ return cv_bool_get(ym->ys_cv); } @@ -3088,7 +3085,7 @@ yang_mandatory(yang_stmt *ys) /* 2) A list or leaf-list node with a "min-elements" statement with a * value greater than zero. */ else if (ys->ys_keyword == Y_LIST || ys->ys_keyword == Y_LEAF_LIST){ - if ((ym = yang_find((yang_node*)ys, Y_MIN_ELEMENTS, NULL)) != NULL){ + if ((ym = yang_find(ys, Y_MIN_ELEMENTS, NULL)) != NULL){ /* XXX change to 32 (need new cligen version) */ if (parse_uint8(ym->ys_argument, &min_elements, &reason) != 1){ clicon_err(OE_YANG, EINVAL, "%s", reason?reason:"parse_uint8"); @@ -3100,7 +3097,7 @@ yang_mandatory(yang_stmt *ys) /* 3) A container node without a "presence" statement and that has at * least one mandatory node as a child. */ else if (ys->ys_keyword == Y_CONTAINER && - yang_find((yang_node*)ys, Y_PRESENCE, NULL) == NULL){ + yang_find(ys, Y_PRESENCE, NULL) == NULL){ yang_stmt *yc; int i; for (i=0; iys_len; i++){ @@ -3124,7 +3121,7 @@ yang_config(yang_stmt *ys) { yang_stmt *ym; - if ((ym = yang_find((yang_node*)ys, Y_CONFIG, NULL)) != NULL){ + if ((ym = yang_find(ys, Y_CONFIG, NULL)) != NULL){ if (ym->ys_cv == NULL) /* shouldnt happen */ return 1; return cv_bool_get(ym->ys_cv); @@ -3190,7 +3187,7 @@ yang_arg2cvec(yang_stmt *ys, * @retval 1 Yes match */ int -yang_key_match(yang_node *yn, +yang_key_match(yang_stmt *yn, char *name) { int retval = -1; @@ -3199,8 +3196,8 @@ yang_key_match(yang_node *yn, cvec *cvv = NULL; cg_var *cv; - for (i=0; iyn_len; i++){ - ys = yn->yn_stmt[i]; + for (i=0; iys_len; i++){ + ys = yn->ys_stmt[i]; if (ys->ys_keyword == Y_KEY){ if ((cvv = yang_arg2cvec(ys, " ")) == NULL) goto done; diff --git a/lib/src/clixon_yang_cardinality.c b/lib/src/clixon_yang_cardinality.c index ac7e594d..5fbe7787 100644 --- a/lib/src/clixon_yang_cardinality.c +++ b/lib/src/clixon_yang_cardinality.c @@ -524,7 +524,7 @@ yang_cardinality(clicon_handle h, /* 2) For all in 1 and 1..n list, if 0 such children ->ERROR */ for (yc = &ycplist[0]; (int)yc->yc_parent == pk; yc++){ if (yc->yc_min && - yang_find((yang_node*)yt, yc->yc_child, NULL) == NULL){ + yang_find(yt, yc->yc_child, NULL) == NULL){ clicon_err(OE_YANG, 0, "%s: \"%s\" is missing but is mandatory child of \"%s\"", modname, yang_key2str(yc->yc_child), yang_key2str(pk)); goto done; @@ -533,7 +533,7 @@ yang_cardinality(clicon_handle h, /* 3) For all in 0..1 and 1 list, if >1 such children ->ERROR */ for (yc = &ycplist[0]; (int)yc->yc_parent == pk; yc++){ if (yc->yc_maxyc_child, NULL)) > yc->yc_max){ + (nr = yang_match(yt, yc->yc_child, NULL)) > yc->yc_max){ clicon_err(OE_YANG, 0, "%s: \"%s\" has %d children of type \"%s\", but only %d allowed", modname, yang_key2str(pk), diff --git a/lib/src/clixon_yang_module.c b/lib/src/clixon_yang_module.c index 9e806c3b..4b6c0937 100644 --- a/lib/src/clixon_yang_module.c +++ b/lib/src/clixon_yang_module.c @@ -111,7 +111,7 @@ int yang_modules_init(clicon_handle h) { int retval = -1; - yang_spec *yspec; + yang_stmt *yspec; yspec = clicon_dbspec_yang(h); if (!clicon_option_bool(h, "CLICON_MODULE_LIBRARY_RFC7895")) @@ -143,15 +143,15 @@ yang_modules_init(clicon_handle h) char * yang_modules_revision(clicon_handle h) { - yang_spec *yspec; + yang_stmt *yspec; yang_stmt *ymod; yang_stmt *yrev; char *revision = NULL; yspec = clicon_dbspec_yang(h); - if ((ymod = yang_find((yang_node*)yspec, Y_MODULE, "ietf-yang-library")) != NULL || - (ymod = yang_find((yang_node*)yspec, Y_SUBMODULE, "ietf-yang-library")) != NULL){ - if ((yrev = yang_find((yang_node*)ymod, Y_REVISION, NULL)) != NULL){ + if ((ymod = yang_find(yspec, Y_MODULE, "ietf-yang-library")) != NULL || + (ymod = yang_find(yspec, Y_SUBMODULE, "ietf-yang-library")) != NULL){ + if ((yrev = yang_find(ymod, Y_REVISION, NULL)) != NULL){ revision = yrev->ys_argument; } } @@ -162,7 +162,7 @@ yang_modules_revision(clicon_handle h) */ static int yms_build(clicon_handle h, - yang_spec *yspec, + yang_stmt *yspec, char *msid, int brief, cbuf *cb) @@ -175,12 +175,12 @@ yms_build(clicon_handle h, yang_stmt *ymod; /* generic module */ yang_stmt *yns = NULL; /* namespace */ - if ((ylib = yang_find((yang_node*)yspec, Y_MODULE, module)) == NULL && - (ylib = yang_find((yang_node*)yspec, Y_SUBMODULE, module)) == NULL){ + if ((ylib = yang_find(yspec, Y_MODULE, module)) == NULL && + (ylib = yang_find(yspec, Y_SUBMODULE, module)) == NULL){ clicon_err(OE_YANG, 0, "%s not found", module); goto done; } - if ((yns = yang_find((yang_node*)ylib, Y_NAMESPACE, NULL)) == NULL){ + if ((yns = yang_find(ylib, Y_NAMESPACE, NULL)) == NULL){ clicon_err(OE_YANG, 0, "%s yang namespace not found", module); goto done; } @@ -189,17 +189,17 @@ yms_build(clicon_handle h, cprintf(cb,"%s", msid); ymod = NULL; - while ((ymod = yn_each((yang_node*)yspec, ymod)) != NULL) { + while ((ymod = yn_each(yspec, ymod)) != NULL) { if (ymod->ys_keyword != Y_MODULE && ymod->ys_keyword != Y_SUBMODULE) continue; cprintf(cb,""); cprintf(cb,"%s", ymod->ys_argument); - if ((ys = yang_find((yang_node*)ymod, Y_REVISION, NULL)) != NULL) + if ((ys = yang_find(ymod, Y_REVISION, NULL)) != NULL) cprintf(cb,"%s", ys->ys_argument); else cprintf(cb,""); - if ((ys = yang_find((yang_node*)ymod, Y_NAMESPACE, NULL)) != NULL) + if ((ys = yang_find(ymod, Y_NAMESPACE, NULL)) != NULL) cprintf(cb,"%s", ys->ys_argument); else cprintf(cb,""); @@ -207,7 +207,7 @@ yms_build(clicon_handle h, submodules */ if (!brief){ yc = NULL; - while ((yc = yn_each((yang_node*)ymod, yc)) != NULL) { + while ((yc = yn_each(ymod, yc)) != NULL) { switch(yc->ys_keyword){ case Y_FEATURE: if (yc->ys_cv && cv_bool_get(yc->ys_cv)) @@ -220,12 +220,12 @@ yms_build(clicon_handle h, cprintf(cb, "implement"); } yc = NULL; - while ((yc = yn_each((yang_node*)ymod, yc)) != NULL) { + while ((yc = yn_each(ymod, yc)) != NULL) { switch(yc->ys_keyword){ case Y_SUBMODULE: cprintf(cb,""); cprintf(cb,"%s", yc->ys_argument); - if ((ys = yang_find((yang_node*)yc, Y_REVISION, NULL)) != NULL) + if ((ys = yang_find(yc, Y_REVISION, NULL)) != NULL) cprintf(cb,"%s", ys->ys_argument); else cprintf(cb,""); @@ -273,7 +273,7 @@ x +--ro namespace inet:uri */ int yang_modules_state_get(clicon_handle h, - yang_spec *yspec, + yang_stmt *yspec, char *xpath, int brief, cxobj **xret) @@ -362,7 +362,7 @@ mod_ns_upgrade(clicon_handle h, uint32_t from = 0; uint32_t to = 0; int ret; - yang_spec *yspec; + yang_stmt *yspec; /* Make upgrade callback for this XML, specifying the module * namespace, from and to revision. @@ -376,7 +376,7 @@ mod_ns_upgrade(clicon_handle h, yspec = clicon_dbspec_yang(h); if ((ymod = yang_find_module_by_namespace(yspec, ns)) == NULL) goto fail; - if ((yrev = yang_find((yang_node*)ymod, Y_REVISION, NULL)) == NULL) + if ((yrev = yang_find(ymod, Y_REVISION, NULL)) == NULL) goto fail; if (ys_parse_date_arg(yrev->ys_argument, &to) < 0) goto done; diff --git a/lib/src/clixon_yang_parse.h b/lib/src/clixon_yang_parse.h index d85e8f6b..dc419c89 100644 --- a/lib/src/clixon_yang_parse.h +++ b/lib/src/clixon_yang_parse.h @@ -46,8 +46,8 @@ */ struct ys_stack{ - struct ys_stack *ys_next; - struct yang_node *ys_node; + struct ys_stack *ys_next; + yang_stmt *ys_node; }; struct clicon_yang_yacc_arg{ /* XXX: mostly unrelevant */ @@ -88,7 +88,7 @@ extern char *clixon_yang_parsetext; int yang_scan_init(struct clicon_yang_yacc_arg *ya); int yang_scan_exit(struct clicon_yang_yacc_arg *ya); -int yang_parse_init(struct clicon_yang_yacc_arg *ya, yang_spec *ysp); +int yang_parse_init(struct clicon_yang_yacc_arg *ya, yang_stmt *ysp); int yang_parse_exit(struct clicon_yang_yacc_arg *ya); int clixon_yang_parselex(void *_ya); @@ -96,6 +96,6 @@ int clixon_yang_parseparse(void *); void clixon_yang_parseerror(void *_ya, char*); int ystack_pop(struct clicon_yang_yacc_arg *ya); -struct ys_stack *ystack_push(struct clicon_yang_yacc_arg *ya, yang_node *yn); +struct ys_stack *ystack_push(struct clicon_yang_yacc_arg *ya, yang_stmt *yn); #endif /* _CLIXON_YANG_PARSE_H_ */ diff --git a/lib/src/clixon_yang_parse.y b/lib/src/clixon_yang_parse.y index 553ae319..779b3195 100644 --- a/lib/src/clixon_yang_parse.y +++ b/lib/src/clixon_yang_parse.y @@ -218,7 +218,7 @@ clixon_yang_parseerror(void *_yy, int yang_parse_init(struct clicon_yang_yacc_arg *yy, - yang_spec *ysp) + yang_stmt *ysp) { return 0; } @@ -246,7 +246,7 @@ ystack_pop(struct clicon_yang_yacc_arg *yy) struct ys_stack * ystack_push(struct clicon_yang_yacc_arg *yy, - yang_node *yn) + yang_stmt *yn) { struct ys_stack *ystack; @@ -278,7 +278,7 @@ ysp_add(struct clicon_yang_yacc_arg *yy, { struct ys_stack *ystack = yy->yy_stack; yang_stmt *ys = NULL; - yang_node *yn; + yang_stmt *yn; ystack = yy->yy_stack; if (ystack == NULL){ @@ -317,7 +317,7 @@ ysp_add_push(struct clicon_yang_yacc_arg *yy, if ((ys = ysp_add(yy, keyword, argument, extra)) == NULL) return NULL; - if (ystack_push(yy, (yang_node*)ys) == NULL) + if (ystack_push(yy, ys) == NULL) return NULL; return ys; } diff --git a/lib/src/clixon_yang_type.c b/lib/src/clixon_yang_type.c index e182b02b..378c9d98 100644 --- a/lib/src/clixon_yang_type.c +++ b/lib/src/clixon_yang_type.c @@ -474,7 +474,7 @@ cv_validate1(cg_var *cv, if (strcmp(restype, "enumeration") == 0){ found = 0; yi = NULL; - while ((yi = yn_each((yang_node*)yrestype, yi)) != NULL){ + while ((yi = yn_each(yrestype, yi)) != NULL){ if (yi->ys_keyword != Y_ENUM) continue; if (strcmp(yi->ys_argument, str) == 0){ @@ -500,7 +500,7 @@ cv_validate1(cg_var *cv, continue; found = 0; yi = NULL; - while ((yi = yn_each((yang_node*)yrestype, yi)) != NULL){ + while ((yi = yn_each(yrestype, yi)) != NULL){ if (yi->ys_keyword != Y_BIT) continue; if (strcmp(yi->ys_argument, v) == 0){ @@ -630,7 +630,7 @@ ys_cv_validate_union(yang_stmt *ys, yang_stmt *yt = NULL; char *reason1 = NULL; /* saved reason */ - while ((yt = yn_each((yang_node*)yrestype, yt)) != NULL){ + while ((yt = yn_each(yrestype, yt)) != NULL){ if (yt->ys_keyword != Y_TYPE) continue; if ((retval = ys_cv_validate_union_one(ys, reason, yt, type, val)) < 0) @@ -744,12 +744,12 @@ ys_typedef(yang_stmt *ys) static yang_stmt * ys_typedef_up(yang_stmt *ys) { - yang_node *yn; + yang_stmt *yn; while (ys != NULL && !ys_typedef(ys)){ yn = ys->ys_parent; /* Some extra stuff to ensure ys is a stmt */ - if (yn && yn->yn_keyword == Y_SPEC) + if (yn && yn->ys_keyword == Y_SPEC) yn = NULL; ys = (yang_stmt*)yn; } @@ -791,7 +791,7 @@ yang_find_identity(yang_stmt *ys, char *prefix = NULL; yang_stmt *ymodule; yang_stmt *yid = NULL; - yang_node *yn; + yang_stmt *yn; if ((id = strchr(identity, ':')) == NULL) id = identity; @@ -804,7 +804,7 @@ yang_find_identity(yang_stmt *ys, if (prefix){ /* Go to top and find import that matches */ if ((ymodule = yang_find_module_by_prefix(ys, prefix)) == NULL) goto done; - yid = yang_find((yang_node*)ymodule, Y_IDENTITY, id); + yid = yang_find(ymodule, Y_IDENTITY, id); } else{ while (1){ @@ -812,11 +812,11 @@ yang_find_identity(yang_stmt *ys, if ((ys = ys_typedef_up(ys)) == NULL) /* If reach top */ break; /* Here find identity */ - if ((yid = yang_find((yang_node*)ys, Y_IDENTITY, id)) != NULL) + if ((yid = yang_find(ys, Y_IDENTITY, id)) != NULL) break; /* Did not find a matching typedef there, proceed to next level */ yn = ys->ys_parent; - if (yn && yn->yn_keyword == Y_SPEC) + if (yn && yn->ys_keyword == Y_SPEC) yn = NULL; ys = (yang_stmt*)yn; } @@ -910,7 +910,7 @@ yang_type_resolve(yang_stmt *yorig, char *type; char *prefix = NULL; int retval = -1; - yang_node *yn; + yang_stmt *yn; yang_stmt *yrmod; /* module where resolved type is looked for */ if (options) @@ -926,10 +926,10 @@ yang_type_resolve(yang_stmt *yorig, goto ok; } /* Resolving type restrictions */ - yrange = yang_find((yang_node*)ytype, Y_RANGE, NULL); - ylength = yang_find((yang_node*)ytype, Y_LENGTH, NULL); - ypattern = yang_find((yang_node*)ytype, Y_PATTERN, NULL); - yfraction = yang_find((yang_node*)ytype, Y_FRACTION_DIGITS, NULL); + yrange = yang_find(ytype, Y_RANGE, NULL); + ylength = yang_find(ytype, Y_LENGTH, NULL); + ypattern = yang_find(ytype, Y_PATTERN, NULL); + yfraction = yang_find(ytype, Y_FRACTION_DIGITS, NULL); /* Check if type is basic type. If so, return that */ if (prefix == NULL && yang_builtin(type)){ @@ -946,7 +946,7 @@ yang_type_resolve(yang_stmt *yorig, prefix, type, ys_module(yorig)->ys_argument); goto done; } - if ((rytypedef = yang_find((yang_node*)yrmod, Y_TYPEDEF, type)) == NULL) + if ((rytypedef = yang_find(yrmod, Y_TYPEDEF, type)) == NULL) goto ok; /* unresolved */ ys = rytypedef; } @@ -958,17 +958,17 @@ yang_type_resolve(yang_stmt *yorig, break; } /* Here find typedef */ - if ((rytypedef = yang_find((yang_node*)ys, Y_TYPEDEF, type)) != NULL) + if ((rytypedef = yang_find(ys, Y_TYPEDEF, type)) != NULL) break; /* Did not find a matching typedef there, proceed to next level */ yn = ys->ys_parent; - if (yn && (yn->yn_keyword == Y_SPEC)) + if (yn && (yn->ys_keyword == Y_SPEC)) yn = NULL; ys = (yang_stmt*)yn; } if (rytypedef != NULL){ /* We have found a typedef */ /* Find associated type statement */ - if ((rytype = yang_find((yang_node*)rytypedef, Y_TYPE, NULL)) == NULL){ + if ((rytype = yang_find(rytypedef, Y_TYPE, NULL)) == NULL){ clicon_err(OE_DB, 0, "mandatory type object is not found"); goto done; } @@ -1045,7 +1045,7 @@ yang_type_get(yang_stmt *ys, if (options) *options = 0x0; /* Find mandatory type */ - if ((ytype = yang_find((yang_node*)ys, Y_TYPE, NULL)) == NULL){ + if ((ytype = yang_find(ys, Y_TYPE, NULL)) == NULL){ clicon_err(OE_DB, 0, "mandatory type object is not found"); goto done; } diff --git a/util/clixon_util_datastore.c b/util/clixon_util_datastore.c index 3f62efdd..72f7353c 100644 --- a/util/clixon_util_datastore.c +++ b/util/clixon_util_datastore.c @@ -103,7 +103,7 @@ main(int argc, char **argv) char *argv0; char *db = "running"; char *cmd = NULL; - yang_spec *yspec = NULL; + yang_stmt *yspec = NULL; char *yangfilename = NULL; char *dbdir = NULL; int ret; diff --git a/util/clixon_util_yang.c b/util/clixon_util_yang.c index b7e0bf1d..f1fb46ce 100644 --- a/util/clixon_util_yang.c +++ b/util/clixon_util_yang.c @@ -79,7 +79,7 @@ usage(char *argv0) int main(int argc, char **argv) { - yang_spec *yspec = NULL; + yang_stmt *yspec = NULL; int c; int logdst = CLICON_LOG_STDERR; @@ -109,7 +109,7 @@ main(int argc, char **argv) fprintf(stderr, "yang parse error %s\n", clicon_err_reason); return -1; } - yang_print(stdout, (yang_node*)yspec); + yang_print(stdout, yspec); done: if (yspec) yspec_free(yspec);