Upgrade creator-attr code

This commit is contained in:
Olof hagsand 2024-01-09 10:52:32 +01:00
parent ea645d1334
commit 7b5dc3d24c
3 changed files with 8 additions and 77 deletions

View file

@ -859,10 +859,6 @@ xmldb_get_nocache(clixon_handle h,
if (disable_nacm_on_empty(xt, yspec) < 0)
goto done;
}
#if 0 /* debug */
if (xml_apply0(xt, -1, xml_sort_verify, NULL) < 0)
clixon_log(h, LOG_NOTICE, "%s: sort verify failed #2", __FUNCTION__);
#endif
if (clixon_debug_get()>1)
if (clixon_xml2file(stderr, xt, 0, 1, NULL, fprintf, 0, 0) < 0)
goto done;
@ -1007,8 +1003,10 @@ xmldb_get_cache(clixon_handle h,
goto done;
}
/* Original tree: Remove global defaults and empty non-presence containers */
#if 0
if (xml_defaults_nopresence(x0t, 2) < 0)
goto done;
#endif
switch (wdef){
case WITHDEFAULTS_REPORT_ALL:
break;
@ -1016,8 +1014,7 @@ xmldb_get_cache(clixon_handle h,
/* Mark and remove nodes having schema default values */
if (xml_apply(x1t, CX_ELMNT, (xml_applyfn_t*) xml_flag_default_value, (void*) XML_FLAG_MARK) < 0)
goto done;
if (xml_tree_prune_flags(x1t, XML_FLAG_MARK, XML_FLAG_MARK)
< 0)
if (xml_tree_prune_flags(x1t, XML_FLAG_MARK, XML_FLAG_MARK) < 0)
goto done;
if (xml_defaults_nopresence(x1t, 1) < 0)
goto done;

View file

@ -145,70 +145,6 @@ attr_ns_value(cxobj *x,
goto done;
}
/*! Add creator data to metadata xml object on the form name:xpath*
*
* Callback function type for xml_apply
* @param[in] x XML node
* @param[in] arg General-purpose argument
* @retval -1 Error, aborted at first error encounter, return -1 to end user
* @retval 0 OK, continue
* @retval 1 Abort, dont continue with others, return 1 to end user
* @retval 2 Locally abort this subtree, continue with others
* On the form:
* <creator>
* <name>testA[name='foo']</name>
* <xpath>...</xpath>
* ...
* </creator>
* @see xml_creator_metadata_read
*/
static int
xml_creator_metadata_write(cxobj *x,
void *arg)
{
int retval = -1;
cxobj *xmeta = (cxobj*)arg;
cxobj *xmc;
cvec *cvv;
cg_var *cv;
char *val;
cvec *nsc = NULL;
char *xpath = NULL;
if ((cvv = xml_creator_get(x)) == NULL){
retval = 0;
goto done;
}
/* Note this requires x to have YANG spec */
if (xml2xpath(x, nsc, 0, 0, &xpath) < 0)
goto done;
cv = NULL;
while ((cv = cvec_each(cvv, cv)) != NULL){
val = cv_name_get(cv);
/* Find existing entry where name is val */
xmc = NULL;
while ((xmc = xml_child_each(xmeta, xmc, CX_ELMNT)) != NULL){
if (strcmp(xml_find_body(xmc, "name"), val) == 0)
break;
}
if (xmc != NULL){
if (clixon_xml_parse_va(YB_NONE, NULL, &xmc, NULL, "<path>%s</path>", xpath) < 0)
goto done;
}
else {
if (clixon_xml_parse_va(YB_NONE, NULL, &xmeta, NULL,
"<creator><name>%s</name><path>%s</path></creator>",
val, xpath) < 0)
goto done;
}
}
retval = 2;
done:
if (xpath)
free(xpath);
return retval;
}
/*! When new body is added, some needs type lookup is made and namespace checked
*
* This includes identityrefs, paths
@ -1416,13 +1352,12 @@ xmldb_put(clixon_handle h,
goto done;
}
pretty = clicon_option_bool(h, "CLICON_XMLDB_PRETTY");
/* Add creator attribute */
/* Add creator attributes to datastore */
if (clicon_option_bool(h, "CLICON_NETCONF_CREATOR_ATTR")){
if ((xmeta = xml_new("creators", x0, CX_ELMNT)) == NULL)
/* @see xml_creator_metadata_read */
if (xml_creator_tree(x0, &xmeta) < 0)
goto done;
if (xmlns_set(xmeta, NULL, CLIXON_LIB_NS) < 0)
goto done;
if (xml_apply(x0, CX_ELMNT, xml_creator_metadata_write, xmeta) < 0)
if (xml_addsub(x0, xmeta) < 0)
goto done;
if (xml_child_nr_type(xmeta, CX_ELMNT) == 0){
xml_purge(xmeta);