order lists according to yang order

This commit is contained in:
Olof hagsand 2016-12-27 17:31:30 +01:00
parent 9a52cfecf6
commit ec9502fd66
5 changed files with 3740 additions and 1 deletions

File diff suppressed because it is too large Load diff

View file

@ -111,6 +111,9 @@ enum rfc_6020{
#define YANG_FLAG_MARK 0x01 /* Marker for dynamic algorithms, eg expand */
/* Yang syntz nodes */
#define yang_is_syntax(y) ((y)->ys_keyword == Y_CONTAINER || (y)->ys_keyword == Y_LEAF || (y)->ys_keyword == Y_LIST || (y)->ys_keyword == Y_LEAF_LIST)
typedef struct yang_stmt yang_stmt; /* forward */
/*! Yang type cache. Yang type statements can cache all typedef info here

View file

@ -361,6 +361,12 @@ xml_child_i(cxobj *xn,
return NULL;
}
/*! Set specific child
* @param[in] xn xml node
* @param[in] i the number of the child, eg order in children vector
* @param[in] xc The child to set at position i
* @retval 0 OK
*/
cxobj *
xml_child_i_set(cxobj *xt,
int i,

View file

@ -812,6 +812,60 @@ xml_default(cxobj *x,
return retval;
}
/*! Order XML children according to YANG
*/
static int
xml_order(cxobj *x,
void *arg)
{
int retval = -1;
yang_stmt *y;
yang_stmt *yc;
int i;
int j0;
int j;
cxobj *xc;
cxobj *xj;
char *yname; /* yang child name */
char *xname; /* xml child name */
y = (yang_stmt*)xml_spec(x);
j0 = 0;
/* Go through xml children and ensure they are same order as yspec children */
for (i=0; i<y->ys_len; i++){
yc = y->ys_stmt[i];
if (!yang_is_syntax(yc))
continue;
yname = yc->ys_argument;
/* First go thru xml children with same name */
for (;j0<xml_child_nr(x); j0++){
xc = xml_child_i(x, j0);
if (xml_type(xc) != CX_ELMNT)
continue;
xname = xml_name(xc);
if (strcmp(xname, yname))
break;
}
/* Now we have children not with same name */
for (j=j0; j<xml_child_nr(x); j++){
xc = xml_child_i(x, j);
if (xml_type(xc) != CX_ELMNT)
continue;
xname = xml_name(xc);
if (strcmp(xname, yname))
continue;
/* reorder */
xj = xml_child_i(x, j0);
xml_child_i_set(x, j0, xc);
xml_child_i_set(x, j, xj);
j0++;
}
}
retval = 0;
// done:
return retval;
}
/*! Get content of database using xpath. return a single tree
* The function returns a minimal tree that includes all sub-trees that match
* xpath.
@ -875,6 +929,8 @@ xmldb_get_tree(char *dbname,
*xtop = xt;
if (xml_apply(xt, CX_ELMNT, xml_default, NULL) < 0)
goto done;
if (xml_apply(xt, CX_ELMNT, xml_order, NULL) < 0)
goto done;
if (1) /* sanity */
if (xml_apply(xt, CX_ELMNT, xml_sanity, NULL) < 0)
goto done;
@ -957,6 +1013,8 @@ xmldb_get_vec(char *dbname,
goto done;
if (xml_apply(xt, CX_ELMNT, xml_default, NULL) < 0)
goto done;
if (xml_apply(xt, CX_ELMNT, xml_order, NULL) < 0)
goto done;
if (1)
if (xml_apply(xt, CX_ELMNT, xml_sanity, NULL) < 0)
goto done;

View file

@ -408,7 +408,7 @@ yang_find(yang_node *yn,
* @note check if argument==NULL really required?
*/
/*! Is this yang-stmt a container, list, leaf or leaf-list? */
#define yang_is_syntax(y) ((y)->ys_keyword == Y_CONTAINER || (y)->ys_keyword == Y_LEAF || (y)->ys_keyword == Y_LIST || (y)->ys_keyword == Y_LEAF_LIST)
yang_stmt *
yang_find_syntax(yang_node *yn,