Skip to content

Commit

Permalink
C-API changes: Replace yn_each with yn_iter, add keyw argument to yan…
Browse files Browse the repository at this point in the history
…g_stats()
  • Loading branch information
olofhagsand committed Jul 4, 2024
1 parent 3e07a1d commit 4b9ee67
Show file tree
Hide file tree
Showing 23 changed files with 358 additions and 248 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@
## 7.2.0
Expected: October 2024

### C/CLI-API changes on existing features

Developers may need to change their code

* New `yn_iter()` yang iterator replaces `yn_each()`
* Use an integer iteratorinstead of yang object
* Replace `y1 = NULL; y1 = yn_each(y0, y1)` with `int inext = 0; yn_iter(y0, &inext)`
* Add `keyw`argument to `yang_stats()`

## 7.1.0
3 July 2024

Expand Down
16 changes: 9 additions & 7 deletions apps/backend/backend_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ clixon_stats_module_get(clixon_handle h,

if (ys == NULL)
return 0;
if (yang_stats(ys, &nr, &sz) < 0)
if (yang_stats(ys, 0, &nr, &sz) < 0)
goto done;
cprintf(cb, "<nr>%" PRIu64 "</nr><size>%zu</size>", nr, sz);
retval = 0;
Expand Down Expand Up @@ -1248,6 +1248,7 @@ from_client_get_schema(clixon_handle h,
cbuf *cbyang = NULL;
cbuf *cbmsg = NULL;
const char *filename;
int inext;

if ((yspec = clicon_dbspec_yang(h)) == NULL){
clixon_err(OE_YANG, ENOENT, "No yang spec");
Expand All @@ -1266,8 +1267,8 @@ from_client_get_schema(clixon_handle h,
if ((x = xpath_first(xe, nsc, "format")) != NULL)
format = xml_body(x);
ymatch = NULL;
ymod = NULL;
while ((ymod = yn_each(yspec, ymod)) != NULL) {
inext = 0;
while ((ymod = yn_iter(yspec, &inext)) != NULL) {
if (yang_keyword_get(ymod) != Y_MODULE &&
yang_keyword_get(ymod) != Y_SUBMODULE)
continue;
Expand Down Expand Up @@ -1425,6 +1426,7 @@ from_client_stats(clixon_handle h,
yang_stmt *ymodext;
cxobj *xt = NULL;
int ret;
int inext;

if ((str = xml_find_body(xe, "modules")) != NULL)
modules = strcmp(str, "true") == 0;
Expand Down Expand Up @@ -1454,8 +1456,8 @@ from_client_stats(clixon_handle h,
if (clixon_stats_module_get(h, yspec, cbret) < 0)
goto done;
if (modules){
ym = NULL;
while ((ym = yn_each(yspec, ym)) != NULL) {
inext = 0;
while ((ym = yn_iter(yspec, &inext)) != NULL) {
cprintf(cbret, "<module><name>%s</name>", yang_argument_get(ym));
if (clixon_stats_module_get(h, ym, cbret) < 0)
goto done;
Expand All @@ -1468,8 +1470,8 @@ from_client_stats(clixon_handle h,
if (clixon_stats_module_get(h, yspec, cbret) < 0)
goto done;
if (modules){
ym = NULL;
while ((ym = yn_each(yspec, ym)) != NULL) {
inext = 0;
while ((ym = yn_iter(yspec, &inext)) != NULL) {
cprintf(cbret, "<module><name>%s</name>", yang_argument_get(ym));
if (clixon_stats_module_get(h, ym, cbret) < 0)
goto done;
Expand Down
53 changes: 32 additions & 21 deletions apps/cli/cli_generate.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,8 @@ yang2cli_var_sub(clixon_handle h,
int retval = -1;
char *type;
yang_stmt *yi = NULL;
int i = 0;
int i;
int inext;
int j;
const char *cvtypestr;
char *arg;
Expand All @@ -503,8 +504,8 @@ yang2cli_var_sub(clixon_handle h,
if (strcmp(type, "enumeration") == 0 || strcmp(type, "bits") == 0){
cprintf(cb, " choice:");
i = 0;
yi = NULL;
while ((yi = yn_each(ytype, yi)) != NULL){
inext = 0;
while ((yi = yn_iter(ytype, &inext)) != NULL){
if (yang_keyword_get(yi) != Y_ENUM && yang_keyword_get(yi) != Y_BIT)
continue;
if (i)
Expand Down Expand Up @@ -629,15 +630,17 @@ yang2cli_var_union(clixon_handle h,
cbuf *cb)
{
int retval = -1;
yang_stmt *ytsub = NULL;
yang_stmt *ytsub;
int i;
int inext;

i = 0;
inext = 0;
/* Loop over all sub-types in the resolved union type, note these are
* not resolved types (unless they are built-in, but the resolve call is
* made in the union_one call.
*/
while ((ytsub = yn_each(ytype, ytsub)) != NULL){
while ((ytsub = yn_iter(ytype, &inext)) != NULL){
if (yang_keyword_get(ytsub) != Y_TYPE)
continue;
if (i++)
Expand Down Expand Up @@ -952,6 +955,7 @@ yang2cli_container(clixon_handle h,
int compress = 0;
yang_stmt *ymod = NULL;
int extvalue = 0;
int inext;
int ret;

if (ys_real_module(ys, &ymod) < 0)
Expand Down Expand Up @@ -990,8 +994,8 @@ yang2cli_container(clixon_handle h,
cprintf(cb, "%*s%s", (level+1)*3, "", "@mountpoint;\n");
}
}
yc = NULL;
while ((yc = yn_each(ys, yc)) != NULL)
inext = 0;
while ((yc = yn_iter(ys, &inext)) != NULL)
if (yang2cli_stmt(h, yc, level+1, cb) < 0)
goto done;
if (!compress)
Expand Down Expand Up @@ -1030,6 +1034,7 @@ yang2cli_list(clixon_handle h,
int last_key = 0;
int exist = 0;
int keynr = 0;
int inext;

cprintf(cb, "%*s%s", level*3, "", yang_argument_get(ys));
if ((yd = yang_find(ys, Y_DESCRIPTION, NULL)) != NULL){
Expand Down Expand Up @@ -1078,8 +1083,8 @@ yang2cli_list(clixon_handle h,
keynr++;
}
cprintf(cb, "{\n");
yc = NULL;
while ((yc = yn_each(ys, yc)) != NULL) {
inext = 0;
while ((yc = yn_iter(ys, &inext)) != NULL) {
/* cvk is a cvec of strings containing variable names
yc is a leaf that may match one of the values of cvk.
*/
Expand Down Expand Up @@ -1128,11 +1133,12 @@ yang2cli_choice(clixon_handle h,
int level,
cbuf *cb)
{
int retval = -1;
yang_stmt *yc;
int retval = -1;
yang_stmt *yc;
int inext;

yc = NULL;
while ((yc = yn_each(ys, yc)) != NULL) {
inext = 0;
while ((yc = yn_iter(ys, &inext)) != NULL) {
switch (yang_keyword_get(yc)){
case Y_CASE:
if (yang2cli_stmt(h, yc, level+2, cb) < 0)
Expand Down Expand Up @@ -1257,6 +1263,7 @@ yang2cli_stmt(clixon_handle h,
int treeref_state = 0;
int grouping_treeref = 0;
int extvalue = 0;
int inext;

if (ys == NULL){
clixon_err(OE_YANG, EINVAL, "No yang spec");
Expand Down Expand Up @@ -1319,8 +1326,8 @@ yang2cli_stmt(clixon_handle h,
case Y_CASE:
case Y_SUBMODULE:
case Y_MODULE:
yc = NULL;
while ((yc = yn_each(ys, yc)) != NULL)
inext = 0;
while ((yc = yn_iter(ys, &inext)) != NULL)
if (yang2cli_stmt(h, yc, level+1, cb) < 0)
goto done;
break;
Expand Down Expand Up @@ -1443,8 +1450,10 @@ yang2cli_post(clixon_handle h,
if ((yc = yang_find_datanode(yp, co->co_command)) == NULL){
#if 1
/* XXX In case of compress, look at next level */
yang_stmt *y = NULL;
while ((y = yn_each(yp, y)) != NULL){
yang_stmt *y;
int inext = 0;

while ((y = yn_iter(yp, &inext)) != NULL){
if (yang_datanode(y)){
if ((yc = yang_find_datanode(y, co->co_command)) != NULL)
break;
Expand Down Expand Up @@ -1530,6 +1539,7 @@ yang2cli_grouping(clixon_handle h,
cg_obj *co;
int config;
int i;
int inext;

if ((pt0 = pt_new()) == NULL){
clixon_err(OE_UNIX, errno, "pt_new");
Expand All @@ -1551,8 +1561,8 @@ yang2cli_grouping(clixon_handle h,
if (autocli_treeref_state(h, &treeref_state) < 0)
goto done;
if (treeref_state || yang_config(ys)){
yc = NULL;
while ((yc = yn_each(ys, yc)) != NULL)
inext = 0;
while ((yc = yn_iter(ys, &inext)) != NULL)
if (yang2cli_stmt(h, yc, 1, cb) < 0)
goto done;
}
Expand Down Expand Up @@ -1664,6 +1674,7 @@ yang2cli_yspec(clixon_handle h,
cg_obj *co;
int i;
int config;
int inext;

if ((pt0 = pt_new()) == NULL){
clixon_err(OE_UNIX, errno, "pt_new");
Expand All @@ -1674,8 +1685,8 @@ yang2cli_yspec(clixon_handle h,
goto done;
}
/* Traverse YANG, loop through all modules and generate CLI */
ymod = NULL;
while ((ymod = yn_each(yspec, ymod)) != NULL){
inext = 0;
while ((ymod = yn_iter(yspec, &inext)) != NULL){
/* Filter module name according to cli_autocli.yang setting
* Default is pass and ordering is significant
*/
Expand Down
15 changes: 8 additions & 7 deletions apps/cli/cli_show.c
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ expand_yang_list(void *h,
yang_stmt *ymod;
int modname = 0;
cbuf *cb = NULL;
int inext;

if (argv == NULL || cvec_len(argv) < 1 || cvec_len(argv) > 2){
clixon_err(OE_PLUGIN, EINVAL, "requires arguments: <schemanode> [<modname>]");
Expand All @@ -518,8 +519,8 @@ expand_yang_list(void *h,
clixon_err(OE_UNIX, errno, "cbuf_new");
goto done;
}
yn = NULL;
while ((yn = yn_each(yres, yn)) != NULL) {
inext = 0;
while ((yn = yn_iter(yres, &inext)) != NULL) {
if (yang_keyword_get(yn) != Y_LIST)
continue;
cbuf_reset(cb);
Expand Down Expand Up @@ -559,6 +560,7 @@ show_yang(clixon_handle h,
yang_stmt *yn;
char *str = NULL;
yang_stmt *yspec;
int inext;

yspec = clicon_dbspec_yang(h);
if (cvec_len(argv) > 0){
Expand All @@ -568,8 +570,8 @@ show_yang(clixon_handle h,
goto done;
}
else{
yn = NULL;
while ((yn = yn_each(yspec, yn)) != NULL) {
inext = 0;
while ((yn = yn_iter(yspec, &inext)) != NULL) {
if (yang_print_cb(stdout, yn, cligen_output) < 0)
goto done;
}
Expand Down Expand Up @@ -1900,7 +1902,6 @@ cli_show_statistics(clixon_handle h,
uint64_t u64;
char *unit;


if (argv == NULL || (cvec_len(argv) < 1 || cvec_len(argv) > 2)){
clixon_err(OE_PLUGIN, EINVAL, "Expected arguments: [(cli|backend|all) [detail]]");
goto done;
Expand Down Expand Up @@ -1938,7 +1939,7 @@ cli_show_statistics(clixon_handle h,
cligen_output(stdout, "%-25s %-10s\n", "YANG", "Mem");
}
nr = 0; sz = 0;
if (yang_stats(yspec, &nr, &sz) < 0)
if (yang_stats(yspec, 0, &nr, &sz) < 0)
goto done;
tnr = nr;
tsz = sz;
Expand All @@ -1961,7 +1962,7 @@ cli_show_statistics(clixon_handle h,
while ((cv2 = cvec_each(cvv2, cv2)) != NULL) {
yspec1 = cv_void_get(cv2);
nr = 0; sz = 0;
if (yang_stats(yspec1, &nr, &sz) < 0)
if (yang_stats(yspec1, 0, &nr, &sz) < 0)
goto done;
/* check if not duplicate */
cv3 = cv2;
Expand Down
10 changes: 6 additions & 4 deletions apps/restconf/restconf_methods_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,8 @@ api_operations_get(clixon_handle h,
char *namespace;
cbuf *cbx = NULL;
cxobj *xt = NULL;
int inext;
int inext2;
int i;

clixon_debug(CLIXON_DBG_RESTCONF, "");
Expand All @@ -735,12 +737,12 @@ api_operations_get(clixon_handle h,
default:
break;
}
ymod = NULL;
i = 0;
while ((ymod = yn_each(yspec, ymod)) != NULL) {
inext = 0;
while ((ymod = yn_iter(yspec, &inext)) != NULL) {
namespace = yang_find_mynamespace(ymod);
yc = NULL;
while ((yc = yn_each(ymod, yc)) != NULL) {
inext2 = 0;
while ((yc = yn_iter(ymod, &inext2)) != NULL) {
if (yang_keyword_get(yc) != Y_RPC)
continue;
switch (media_out){
Expand Down
10 changes: 6 additions & 4 deletions apps/snmp/snmp_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -852,11 +852,12 @@ snmp_table_get(clixon_handle h,
int i;
cg_var *cv;
char *defaultval = NULL;
int inext;
int ret;

/* Get yang of leaf from first part of OID */
ys = NULL;
while ((ys = yn_each(yt, ys)) != NULL) {
inext = 0;
while ((ys = yn_iter(yt, &inext)) != NULL) {
if (yang_keyword_get(ys) != Y_LEAF)
continue;
/* reset oid */
Expand Down Expand Up @@ -973,6 +974,7 @@ snmp_table_set(clixon_handle h,
netsnmp_variable_list *requestvb;
int rowstatus = 0;
char *origtype;
int inext;

/* Get OID from table /list */
if ((ret = yangext_oid_get(yt, oidt, &oidtlen, NULL)) < 0)
Expand All @@ -984,8 +986,8 @@ snmp_table_set(clixon_handle h,
*/
ys = NULL;
yrowst = NULL;
yi = NULL;
while ((yi = yn_each(yt, yi)) != NULL) {
inext = 0;
while ((yi = yn_iter(yt, &inext)) != NULL) {
if (yang_keyword_get(yi) != Y_LEAF)
continue;
/* reset oid */
Expand Down
Loading

0 comments on commit 4b9ee67

Please sign in to comment.