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

@ -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.