C-API changes: Replace yn_each with yn_iter, add keyw argument to yang_stats()
This commit is contained in:
parent
3e07a1d279
commit
4b9ee6740b
23 changed files with 358 additions and 248 deletions
|
|
@ -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;
|
||||
|
|
@ -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");
|
||||
|
|
@ -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;
|
||||
|
|
@ -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;
|
||||
|
|
@ -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;
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -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)
|
||||
|
|
@ -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++)
|
||||
|
|
@ -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)
|
||||
|
|
@ -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)
|
||||
|
|
@ -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){
|
||||
|
|
@ -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.
|
||||
*/
|
||||
|
|
@ -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)
|
||||
|
|
@ -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");
|
||||
|
|
@ -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;
|
||||
|
|
@ -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;
|
||||
|
|
@ -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");
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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");
|
||||
|
|
@ -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
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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>]");
|
||||
|
|
@ -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);
|
||||
|
|
@ -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){
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
|
@ -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;
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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, "");
|
||||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
@ -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)
|
||||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -170,7 +170,7 @@ is_same_subtypes_union(yang_stmt *ytype,
|
|||
char **restype)
|
||||
{
|
||||
int retval = 0;
|
||||
yang_stmt *y_sub_type = NULL;
|
||||
yang_stmt *y_sub_type;
|
||||
yang_stmt *y_resolved_type = NULL; /* resolved type */
|
||||
char *resolved_type_str; /* resolved type */
|
||||
char *type_str = NULL;
|
||||
|
|
@ -178,12 +178,14 @@ is_same_subtypes_union(yang_stmt *ytype,
|
|||
cvec *cvv = NULL;
|
||||
cvec *patterns = NULL;
|
||||
uint8_t fraction_digits = 0;
|
||||
int inext;
|
||||
|
||||
/* 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 ((y_sub_type = yn_each(ytype, y_sub_type)) != NULL){
|
||||
inext = 0;
|
||||
while ((y_sub_type = yn_iter(ytype, &inext)) != NULL){
|
||||
if (yang_keyword_get(y_sub_type) != Y_TYPE)
|
||||
continue;
|
||||
|
||||
|
|
@ -413,6 +415,7 @@ yang_extension_value_opt(yang_stmt *ys,
|
|||
int retval = -1;
|
||||
yang_stmt *yext;
|
||||
cg_var *cv;
|
||||
int inext;
|
||||
|
||||
if (ys == NULL){
|
||||
clixon_err(OE_YANG, EINVAL, "ys is NULL");
|
||||
|
|
@ -420,8 +423,9 @@ yang_extension_value_opt(yang_stmt *ys,
|
|||
}
|
||||
if (exist)
|
||||
*exist = 0;
|
||||
yext = NULL; /* This loop gets complicated in the case the extension is augmented */
|
||||
while ((yext = yn_each(ys, yext)) != NULL) {
|
||||
/* This loop gets complicated in the case the extension is augmented */
|
||||
inext = 0;
|
||||
while ((yext = yn_iter(ys, &inext)) != NULL) {
|
||||
if (yang_keyword_get(yext) != Y_UNKNOWN)
|
||||
continue;
|
||||
if (strcmp(yang_argument_get(yext), id) != 0)
|
||||
|
|
|
|||
|
|
@ -237,6 +237,7 @@ mibyang_table_register(clixon_handle h,
|
|||
int asn1type;
|
||||
yang_stmt *ys;
|
||||
char *name;
|
||||
int inext;
|
||||
|
||||
if ((ys = yang_parent_get(ylist)) == NULL ||
|
||||
yang_keyword_get(ys) != Y_CONTAINER){
|
||||
|
|
@ -315,9 +316,9 @@ mibyang_table_register(clixon_handle h,
|
|||
table_info->min_column = 1;
|
||||
|
||||
/* Count columns */
|
||||
yleaf = NULL;
|
||||
table_info->max_column = 0;
|
||||
while ((yleaf = yn_each(ylist, yleaf)) != NULL) {
|
||||
inext = 0;
|
||||
while ((yleaf = yn_iter(ylist, &inext)) != NULL) {
|
||||
if ((yang_keyword_get(yleaf) != Y_LEAF) || (ret = yangext_is_oid_exist(yleaf)) != 1)
|
||||
continue;
|
||||
table_info->max_column++;
|
||||
|
|
@ -557,6 +558,7 @@ mibyang_traverse(clixon_handle h,
|
|||
yang_stmt *ys = NULL;
|
||||
yang_stmt *yp;
|
||||
int ret;
|
||||
int inext;
|
||||
static oid zero_oid = 0;
|
||||
|
||||
clixon_debug(CLIXON_DBG_SNMP, "%s", yang_argument_get(yn));
|
||||
|
|
@ -586,8 +588,8 @@ mibyang_traverse(clixon_handle h,
|
|||
break;
|
||||
}
|
||||
/* Traverse data nodes in tree (module is special case */
|
||||
ys = NULL;
|
||||
while ((ys = yn_each(yn, ys)) != NULL) {
|
||||
inext = 0;
|
||||
while ((ys = yn_iter(yn, &inext)) != NULL) {
|
||||
/* augment special case of table */
|
||||
if (!yang_schemanode(ys) && yang_keyword_get(ys) != Y_AUGMENT)
|
||||
continue;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue