sort xml children on parsing
This commit is contained in:
parent
9681c91681
commit
19301ae240
5 changed files with 35 additions and 23 deletions
|
|
@ -403,7 +403,11 @@ from_client_edit_config(clicon_handle h,
|
||||||
"</rpc-error></rpc-reply>");
|
"</rpc-error></rpc-reply>");
|
||||||
goto ok;
|
goto ok;
|
||||||
}
|
}
|
||||||
|
/* Cant do this earlier since we dont have a yang spec to
|
||||||
|
* the upper part of the tree, until we get the "config" tree.
|
||||||
|
*/
|
||||||
|
if (xml_child_sort && xml_apply0(xc, CX_ELMNT, xml_sort, NULL) < 0)
|
||||||
|
goto done;
|
||||||
if (xmldb_put(h, target, operation, xc) < 0){
|
if (xmldb_put(h, target, operation, xc) < 0){
|
||||||
cprintf(cbret, "<rpc-reply><rpc-error>"
|
cprintf(cbret, "<rpc-reply><rpc-error>"
|
||||||
"<error-tag>operation-failed</error-tag>"
|
"<error-tag>operation-failed</error-tag>"
|
||||||
|
|
|
||||||
|
|
@ -474,9 +474,6 @@ text_get(xmldb_handle xh,
|
||||||
if (singleconfigroot(xt, &xt) < 0)
|
if (singleconfigroot(xt, &xt) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
/* Sort XML children according to YANG */
|
|
||||||
if (xml_child_sort && xml_apply0(xt, CX_ELMNT, xml_sort, NULL) < 0)
|
|
||||||
goto done;
|
|
||||||
} /* xt == NULL */
|
} /* xt == NULL */
|
||||||
/* Here xt looks like: <config>...</config> */
|
/* Here xt looks like: <config>...</config> */
|
||||||
|
|
||||||
|
|
@ -540,11 +537,10 @@ text_get(xmldb_handle xh,
|
||||||
/* Order XML children according to YANG */
|
/* Order XML children according to YANG */
|
||||||
if (!xml_child_sort && xml_apply(xt, CX_ELMNT, xml_order, NULL) < 0)
|
if (!xml_child_sort && xml_apply(xt, CX_ELMNT, xml_order, NULL) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
/* Again just so default values are placed correctly */
|
#if 0 /* debug */
|
||||||
if (xml_child_sort && xml_apply0(xt, CX_ELMNT, xml_sort, NULL) < 0)
|
|
||||||
goto done;
|
|
||||||
if (xml_child_sort && xml_apply0(xt, -1, xml_sort_verify, NULL) < 0)
|
if (xml_child_sort && xml_apply0(xt, -1, xml_sort_verify, NULL) < 0)
|
||||||
clicon_log(LOG_NOTICE, "%s: verify failed #2", __FUNCTION__);
|
clicon_log(LOG_NOTICE, "%s: verify failed #2", __FUNCTION__);
|
||||||
|
#endif
|
||||||
if (debug>1)
|
if (debug>1)
|
||||||
clicon_xml2file(stderr, xt, 0, 1);
|
clicon_xml2file(stderr, xt, 0, 1);
|
||||||
*xtop = xt;
|
*xtop = xt;
|
||||||
|
|
@ -730,6 +726,7 @@ text_modify(cxobj *x0,
|
||||||
} /* CONTAINER switch op */
|
} /* CONTAINER switch op */
|
||||||
} /* else Y_CONTAINER */
|
} /* else Y_CONTAINER */
|
||||||
// ok:
|
// ok:
|
||||||
|
xml_sort(x0p, NULL);
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
if (x0vec)
|
if (x0vec)
|
||||||
|
|
@ -916,8 +913,10 @@ text_put(xmldb_handle xh,
|
||||||
/* XXX: where is this created? Add yspec */
|
/* XXX: where is this created? Add yspec */
|
||||||
if (xml_apply(x1, CX_ELMNT, xml_spec_populate, yspec) < 0)
|
if (xml_apply(x1, CX_ELMNT, xml_spec_populate, yspec) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if (xml_child_sort && xml_apply0(x1, CX_ELMNT, xml_sort, NULL) < 0)
|
#if 0 /* debug */
|
||||||
goto done;
|
if (xml_child_sort && xml_apply0(x1, -1, xml_sort_verify, NULL) < 0)
|
||||||
|
clicon_log(LOG_NOTICE, "%s: verify failed #1", __FUNCTION__);
|
||||||
|
#endif
|
||||||
/*
|
/*
|
||||||
* Modify base tree x with modification x1. This is where the
|
* Modify base tree x with modification x1. This is where the
|
||||||
* new tree is made.
|
* new tree is made.
|
||||||
|
|
@ -937,9 +936,10 @@ text_put(xmldb_handle xh,
|
||||||
/* Remove (prune) nodes that are marked (non-presence containers w/o children) */
|
/* Remove (prune) nodes that are marked (non-presence containers w/o children) */
|
||||||
if (xml_tree_prune_flagged(x0, XML_FLAG_MARK, 1) < 0)
|
if (xml_tree_prune_flagged(x0, XML_FLAG_MARK, 1) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if (xml_child_sort && xml_apply0(x0, CX_ELMNT, xml_sort, NULL) < 0)
|
#if 0 /* debug */
|
||||||
goto done;
|
if (xml_child_sort && xml_apply0(x0, -1, xml_sort_verify, NULL) < 0)
|
||||||
|
clicon_log(LOG_NOTICE, "%s: verify failed #3", __FUNCTION__);
|
||||||
|
#endif
|
||||||
/* Write back to datastore cache if first time */
|
/* Write back to datastore cache if first time */
|
||||||
if (xmltree_cache){
|
if (xmltree_cache){
|
||||||
struct db_element de0 = {0,};
|
struct db_element de0 = {0,};
|
||||||
|
|
|
||||||
|
|
@ -534,7 +534,7 @@ xml_childvec_get(cxobj *x)
|
||||||
cxobj *
|
cxobj *
|
||||||
xml_new(char *name,
|
xml_new(char *name,
|
||||||
cxobj *xp,
|
cxobj *xp,
|
||||||
yang_stmt *spec)
|
yang_stmt *yspec)
|
||||||
{
|
{
|
||||||
cxobj *x;
|
cxobj *x;
|
||||||
|
|
||||||
|
|
@ -545,11 +545,12 @@ xml_new(char *name,
|
||||||
memset(x, 0, sizeof(cxobj));
|
memset(x, 0, sizeof(cxobj));
|
||||||
if ((xml_name_set(x, name)) < 0)
|
if ((xml_name_set(x, name)) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
if (xp){
|
||||||
xml_parent_set(x, xp);
|
xml_parent_set(x, xp);
|
||||||
if (xp && xml_child_append(xp, x) < 0)
|
if (xml_child_append(xp, x) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
x->x_spec = spec; /* Can be NULL */
|
}
|
||||||
|
x->x_spec = yspec; /* Can be NULL */
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1233,6 +1234,13 @@ _xml_parse(const char *str,
|
||||||
goto done;
|
goto done;
|
||||||
if (clixon_xml_parseparse(&ya) != 0) /* yacc returns 1 on error */
|
if (clixon_xml_parseparse(&ya) != 0) /* yacc returns 1 on error */
|
||||||
goto done;
|
goto done;
|
||||||
|
/* Sort the complete tree after parsing */
|
||||||
|
if (yspec){
|
||||||
|
if (xml_apply0(xt, CX_ELMNT, xml_sort, NULL) < 0)
|
||||||
|
goto done;
|
||||||
|
if (xml_apply0(xt, -1, xml_sort_verify, NULL) < 0)
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
clixon_xml_parsel_exit(&ya);
|
clixon_xml_parsel_exit(&ya);
|
||||||
|
|
|
||||||
|
|
@ -1206,6 +1206,7 @@ xml_default(cxobj *xt,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
xml_sort(xt, NULL);
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
return retval;
|
return retval;
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ cfg=/tmp/scaling-conf.xml
|
||||||
fyang=/tmp/scaling.yang
|
fyang=/tmp/scaling.yang
|
||||||
fconfig=/tmp/config
|
fconfig=/tmp/config
|
||||||
|
|
||||||
|
|
||||||
# include err() and new() functions
|
# include err() and new() functions
|
||||||
. ./lib.sh
|
. ./lib.sh
|
||||||
|
|
||||||
|
|
@ -67,7 +66,7 @@ if [ $? -ne 0 ]; then
|
||||||
err
|
err
|
||||||
fi
|
fi
|
||||||
|
|
||||||
new "start backend"
|
new "start backend -s init -f $cfg -y $fyang"
|
||||||
# start new backend
|
# start new backend
|
||||||
sudo clixon_backend -s init -f $cfg -y $fyang
|
sudo clixon_backend -s init -f $cfg -y $fyang
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue