From 9f73014500f9a74b0decbd08e9538d4fe893e563 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Mon, 26 Feb 2024 13:16:48 +0100 Subject: [PATCH] Added `yspec` parameter to `api_path_fmt2api_path()` Added "%k" as extra flag character to api-path-fmt --- CHANGELOG.md | 7 +++-- apps/cli/cli_auto.c | 21 ++++++++++++--- apps/cli/cli_common.c | 4 +-- apps/cli/cli_show.c | 11 ++++---- apps/snmp/snmp_handler.c | 2 +- lib/clixon/clixon_path.h | 2 +- lib/src/clixon_path.c | 58 ++++++++++++++++++++++++++++++++++++++-- lib/src/clixon_string.c | 12 ++++++--- lib/src/clixon_xml_map.c | 2 +- 9 files changed, 98 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 29d8c8d0..2edaba66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Clixon Changelog -* [6.6.0](#660) Expected: February 2024 +* [6.6.0](#660) Expected: March 2024 * [6.5.0](#650) 6 December 2023 * [6.4.0](#640) 30 September 2023 * [6.3.0](#630) 29 July 2023 @@ -9,7 +9,7 @@ * [6.0.0](#600) 29 Nov 2022 ## 6.6.0 -Expected: February 2024 +Expected: March 2024 ### Minor features @@ -33,6 +33,7 @@ Expected: February 2024 * Filtered state data if not match xpath * Added reference count for shared yang-specs (schema mounts) * Allowed for sharing yspec+modules between several mountpoints +* Added "%k" as extra flag character to api-path-fmt ### API changes on existing protocol/config features Users may have to change how they access the system @@ -51,6 +52,8 @@ Users may have to change how they access the system ### C/CLI-API changes on existing features Developers may need to change their code +* Added `yspec` parameter to `api_path_fmt2api_path()`: + * `api_path_fmt2api_path(af, c, a, c)` --> `api_path_fmt2api_path(af, c, yspec, a, c)` * Added flags parameter to default functions: * `xml_default_recurse(...)` -> `xml_default_recurse(..., 0)` * `xml_defaults_nopresence(...)` -> `xml_default_nopresence(..., 0)` diff --git a/apps/cli/cli_auto.c b/apps/cli/cli_auto.c index 5e3b389e..4dbb408d 100644 --- a/apps/cli/cli_auto.c +++ b/apps/cli/cli_auto.c @@ -128,11 +128,16 @@ cli_auto_edit(clixon_handle h, int argc = 0; char *str; char *mtpoint = NULL; + yang_stmt *yspec0; if (cvec_len(argv) != 2 && cvec_len(argv) != 3){ clixon_err(OE_PLUGIN, EINVAL, "Usage: %s(api_path_fmt>*, )", __FUNCTION__); goto done; } + if ((yspec0 = clicon_dbspec_yang(h)) == NULL){ + clixon_err(OE_FATAL, 0, "No DB_SPEC"); + goto done; + } api_path_fmt = cv_string_get(cvec_i(argv, argc++)); str = cv_string_get(cvec_i(argv, argc++)); if (str && strncmp(str, "mtpoint:", strlen("mtpoint:")) == 0){ @@ -172,7 +177,7 @@ cli_auto_edit(clixon_handle h, goto done; } /* get api-path and xpath */ - if (api_path_fmt2api_path(api_path_fmt, cvv2, &api_path, NULL) < 0) + if (api_path_fmt2api_path(api_path_fmt, cvv2, yspec0, &api_path, NULL) < 0) goto done; /* Store this as edit-mode */ if (clicon_data_set(h, "cli-edit-mode", api_path) < 0) @@ -234,11 +239,16 @@ cli_auto_up(clixon_handle h, int j; size_t len; cvec *cvv_filter = NULL; + yang_stmt *yspec0; if (cvec_len(argv) != 1){ clixon_err(OE_PLUGIN, EINVAL, "Usage: %s()", __FUNCTION__); goto done; } + if ((yspec0 = clicon_dbspec_yang(h)) == NULL){ + clixon_err(OE_FATAL, 0, "No DB_SPEC"); + goto done; + } cv = cvec_i(argv, 0); treename = cv_string_get(cv); if ((ph = cligen_ph_find(cli_cligen(h), treename)) == NULL){ @@ -289,7 +299,7 @@ cli_auto_up(clixon_handle h, cvec_append_var(cvv1, cv); } /* get api-path and xpath */ - if (api_path_fmt2api_path(api_path_fmt1, cvv1, &api_path, NULL) < 0) + if (api_path_fmt2api_path(api_path_fmt1, cvv1, yspec0, &api_path, NULL) < 0) goto done; /* Store this as edit-mode */ clicon_data_set(h, "cli-edit-mode", api_path); @@ -506,11 +516,16 @@ cli_auto_sub_enter(clixon_handle h, cg_var *cv = NULL; pt_head *ph; struct findpt_arg fa = {0,}; + yang_stmt *yspec0; if (cvec_len(argv) < 2){ clixon_err(OE_PLUGIN, EINVAL, "Usage: %s( (,vars)*)", __FUNCTION__); goto done; } + if ((yspec0 = clicon_dbspec_yang(h)) == NULL){ + clixon_err(OE_FATAL, 0, "No DB_SPEC"); + goto done; + } /* First argv argument: treename */ cv = cvec_i(argv, 0); treename = cv_string_get(cv); @@ -540,7 +555,7 @@ cli_auto_sub_enter(clixon_handle h, if (cvec_append_var(cvv1, cvec_i(cvv, i)) < 0) goto done; } - if (api_path_fmt2api_path(api_path_fmt, cvv1, &api_path, NULL) < 0) + if (api_path_fmt2api_path(api_path_fmt, cvv1, yspec0, &api_path, NULL) < 0) goto done; /* Assign the variables */ if ((cvv2 = cvec_append(clicon_data_cvec_get(h, "cli-edit-cvv"), cvv1)) == NULL) diff --git a/apps/cli/cli_common.c b/apps/cli/cli_common.c index 7feae119..c373c346 100644 --- a/apps/cli/cli_common.c +++ b/apps/cli/cli_common.c @@ -443,7 +443,7 @@ cli_dbxml(clixon_handle h, /* Transform template format string + cvv to actual api-path * cvvi indicates if all cvv entries were used */ - if (api_path_fmt2api_path(api_path_fmt01, cvv, &api_path, &cvvi) < 0) + if (api_path_fmt2api_path(api_path_fmt01, cvv, yspec0, &api_path, &cvvi) < 0) goto done; } else { @@ -451,7 +451,7 @@ cli_dbxml(clixon_handle h, /* Transform template format string + cvv to actual api-path * cvvi indicates if all cvv entries were used */ - if (api_path_fmt2api_path(api_path_fmt, cvv, &api_path, &cvvi) < 0) + if (api_path_fmt2api_path(api_path_fmt, cvv, yspec0, &api_path, &cvvi) < 0) goto done; } /* Create config top-of-tree */ diff --git a/apps/cli/cli_show.c b/apps/cli/cli_show.c index 282a3d6a..baae3ce4 100644 --- a/apps/cli/cli_show.c +++ b/apps/cli/cli_show.c @@ -204,7 +204,8 @@ xpath_append(cbuf *cb0, * @retval -1 Error * @see cli_expand_var_generate where api_path_fmt + mt-point are generated * The syntax of is of RFC8040 api-path with the following extension: - * "%s" represents the values of cvv in order starting from element 1 + * %s Represents the values of cvv in order starting from element 1 + * %k Represents the (first) key of the (previous) list */ int expand_dbvar(void *h, @@ -297,11 +298,11 @@ expand_dbvar(void *h, /* Get and combined api-path01 */ if (mtpoint_paths(yspec0, mtpoint, api_path_fmt, &api_path_fmt01) < 0) goto done; - if (api_path_fmt2api_path(api_path_fmt01, cvv, &api_path, &cvvi) < 0) + if (api_path_fmt2api_path(api_path_fmt01, cvv, yspec0, &api_path, &cvvi) < 0) goto done; } else{ - if (api_path_fmt2api_path(api_path_fmt, cvv, &api_path, &cvvi) < 0) + if (api_path_fmt2api_path(api_path_fmt, cvv, yspec0, &api_path, &cvvi) < 0) goto done; } if (api_path == NULL) @@ -1092,11 +1093,11 @@ cli_show_auto(clixon_handle h, /* Get and combined api-path01 */ if (mtpoint_paths(yspec0, mtpoint, api_path_fmt, &api_path_fmt01) < 0) goto done; - if (api_path_fmt2api_path(api_path_fmt01, cvv, &api_path, &cvvi) < 0) + if (api_path_fmt2api_path(api_path_fmt01, cvv, yspec0, &api_path, &cvvi) < 0) goto done; } else{ - if (api_path_fmt2api_path(api_path_fmt, cvv, &api_path, &cvvi) < 0) + if (api_path_fmt2api_path(api_path_fmt, cvv, yspec0, &api_path, &cvvi) < 0) goto done; } if (api_path2xpath(api_path, yspec0, &xpath, &nsc, NULL) < 0) diff --git a/apps/snmp/snmp_handler.c b/apps/snmp/snmp_handler.c index 3586eb41..aafec1aa 100644 --- a/apps/snmp/snmp_handler.c +++ b/apps/snmp/snmp_handler.c @@ -358,7 +358,7 @@ snmp_yang2xml(cxobj *xtop, } for (i=0; i 1){ diff --git a/lib/src/clixon_xml_map.c b/lib/src/clixon_xml_map.c index 89f88e65..463c3974 100644 --- a/lib/src/clixon_xml_map.c +++ b/lib/src/clixon_xml_map.c @@ -316,7 +316,7 @@ xml_diff_ordered_by_user(cxobj *x0, } while ((xj = xml_child_each(x1, xj, CX_ELMNT)) != NULL && xml_spec(xj) == yc); retval = 0; - done: + // done: return retval; }