test restconf bugfix, added xml_nsctx_cbuf

This commit is contained in:
Olof hagsand 2020-12-29 15:57:21 +01:00
parent 41e23865a1
commit 7f49c13eba
5 changed files with 48 additions and 20 deletions

View file

@ -59,6 +59,7 @@ int xml_nsctx_add(cvec *nsc, char *prefix, char *ns);
int xml_nsctx_node(cxobj *x, cvec **ncp);
int xml_nsctx_yang(yang_stmt *yn, cvec **ncp);
int xml_nsctx_yangspec(yang_stmt *yspec, cvec **ncp);
int xml_nsctx_cbuf(cbuf *cb, cvec *nsc);
int xml2ns(cxobj *x, char *localname, char **ns);
int xml2ns_recurse(cxobj *x);

View file

@ -234,8 +234,10 @@ clixon_proc_background(char **argv,
goto done;
}
if (child == 0) { /* Child */
#ifdef HAVE_SETNS
char nsfile[PATH_MAX];
int nsfd;
#endif
clicon_debug(1, "%s child", __FUNCTION__);
clicon_signal_unblock(0);

View file

@ -327,8 +327,6 @@ clicon_rpc_get_config(clicon_handle h,
cxobj *xret = NULL;
cxobj *xerr = NULL;
cxobj *xd;
cg_var *cv = NULL;
char *prefix;
uint32_t session_id;
int ret;
yang_stmt *yspec;
@ -349,12 +347,8 @@ clicon_rpc_get_config(clicon_handle h,
cprintf(cb, "<%s:filter %s:type=\"xpath\" %s:select=\"%s\"",
NETCONF_BASE_PREFIX, NETCONF_BASE_PREFIX, NETCONF_BASE_PREFIX,
xpath);
while ((cv = cvec_each(nsc, cv)) != NULL){
cprintf(cb, " xmlns");
if ((prefix = cv_name_get(cv)))
cprintf(cb, ":%s", prefix);
cprintf(cb, "=\"%s\"", cv_string_get(cv));
}
if (xml_nsctx_cbuf(cb, nsc) < 0)
goto done;
cprintf(cb, "/>");
}
cprintf(cb, "</get-config></rpc>");
@ -689,8 +683,6 @@ clicon_rpc_get(clicon_handle h,
cxobj *xerr = NULL;
cxobj *xd;
char *username;
cg_var *cv = NULL;
char *prefix;
uint32_t session_id;
int ret;
yang_stmt *yspec;
@ -716,13 +708,8 @@ clicon_rpc_get(clicon_handle h,
cprintf(cb, "<%s:filter %s:type=\"xpath\" %s:select=\"%s\"",
NETCONF_BASE_PREFIX, NETCONF_BASE_PREFIX, NETCONF_BASE_PREFIX,
xpath);
while ((cv = cvec_each(nsc, cv)) != NULL){
cprintf(cb, " xmlns");
if ((prefix = cv_name_get(cv)))
cprintf(cb, ":%s", prefix);
cprintf(cb, "=\"%s\"", cv_string_get(cv));
}
if (xml_nsctx_cbuf(cb, nsc) < 0)
goto done;
cprintf(cb, "/>");
}
cprintf(cb, "</get></rpc>");

View file

@ -440,6 +440,33 @@ xml_nsctx_yangspec(yang_stmt *yspec,
return retval;
}
/*! Print a namespace context to a cbuf using xmlns notation
* @param[in] *cb CLIgen buf written to
* @param[in] *nsc Namespace context
* @retval 0 OK
* @code
* cbuf *cb = cbuf_new();
* cprintf(cb, "<foo ");
* if (xml_nsctx_cbuf(cb, nsc) < 0)
* err;
* @endcode
*/
int
xml_nsctx_cbuf(cbuf *cb,
cvec *nsc)
{
cg_var *cv = NULL;
char *prefix;
while ((cv = cvec_each(nsc, cv)) != NULL){
cprintf(cb, " xmlns");
if ((prefix = cv_name_get(cv)))
cprintf(cb, ":%s", prefix);
cprintf(cb, "=\"%s\"", cv_string_get(cv));
}
return 0;
}
/*! Given an xml tree return URI namespace recursively : default or localname given
*
* Given an XML tree and a prefix (or NULL) return URI namespace.

View file

@ -23,9 +23,20 @@ APPNAME=example
cfg=$dir/conf.xml
# clixon-example and clixon-restconf is used in the test, need local copy
cp ${TOP_SRCDIR}/example/main/clixon-example@2020-12-01.yang $dir/
cp ${TOP_SRCDIR}/yang/clixon/clixon-restconf@2020-10-30.yang $dir/
# This is a kludge: look in src otherwise assume it is installed in /usr/local/share
# Note that revisions may change and may need to be updated
y=clixon-example@2020-12-01.yang
if [ -d ${TOP_SRCDIR}/example/main/$y ]; then
cp ${TOP_SRCDIR}/example/main/$y $dir/
else
cp /usr/local/share/clixon/$y $dir/
fi
y=clixon-restconf@2020-10-30.yang
if [ -d ${TOP_SRCDIR}/yang/clixon ]; then
cp ${TOP_SRCDIR}/yang/clixon/$y $dir/
else
cp /usr/local/share/clixon/$y $dir/
fi
cat <<EOF > $cfg
<clixon-config xmlns="http://clicon.org/config">
<CLICON_CONFIGFILE>$cfg</CLICON_CONFIGFILE>