* Stricter handling of multi-namespace handling

* This occurs in cases where there are more than one XML namespaces in a config tree, such as `augment`:ed trees.
  * Affects all parts of the system, including datastore, backend, restconf and cli.
* Invalid api-path syntax (eg non-matching yang) error changed from 412 operation-failed to 400 Bad request invalid-value, or unknown-element.
This commit is contained in:
Olof hagsand 2019-09-29 14:45:08 +02:00
parent a547b3f31d
commit d9136c8972
22 changed files with 777 additions and 236 deletions

View file

@ -527,11 +527,10 @@ from_client_edit_config(clicon_handle h,
if (xml_spec(xc) != NULL)
xml_spec_set(xc, NULL);
/* Populate XML with Yang spec (why not do this in parser?)
* Maybe validate xml here as in text_modify_top?
*/
if (xml_apply(xc, CX_ELMNT, xml_spec_populate, yspec) < 0)
goto done;
/* Maybe validate xml here as in text_modify_top? */
if (xml_apply(xc, CX_ELMNT, xml_non_config_data, &non_config) < 0)
goto done;
if (non_config){

View file

@ -195,10 +195,12 @@ startup_common(clicon_handle h,
goto ok;
}
if (msd){
/* Here xt is old syntax */
if ((ret = clixon_module_upgrade(h, xt, msd, cbret)) < 0)
goto done;
if (ret == 0)
goto fail;
/* Here xt is new syntax */
}
if ((yspec = clicon_dbspec_yang(h)) == NULL){
clicon_err(OE_YANG, 0, "Yang spec not set");

View file

@ -70,7 +70,6 @@
#include "backend_commit.h"
#include "backend_startup.h"
/*! Merge db1 into db2 without commit
* @retval -1 Error
* @retval 0 Validation failed (with cbret set)
@ -166,9 +165,10 @@ load_extraxml(clicon_handle h,
const char *db,
cbuf *cbret)
{
int retval = -1;
cxobj *xt = NULL;
int fd = -1;
int retval = -1;
cxobj *xt = NULL;
int fd = -1;
yang_stmt *yspec = NULL;
if (filename == NULL)
return 1;
@ -176,7 +176,8 @@ load_extraxml(clicon_handle h,
clicon_err(OE_UNIX, errno, "open(%s)", filename);
goto done;
}
if (xml_parse_file(fd, "</config>", NULL, &xt) < 0)
yspec = clicon_dbspec_yang(h);
if (xml_parse_file(fd, "</config>", yspec, &xt) < 0)
goto done;
/* Replace parent w first child */
if (xml_rootchild(xt, 0, &xt) < 0)

View file

@ -526,6 +526,7 @@ api_return_err(clicon_handle h,
FCGX_FPrintF(r->out, "%s", cbuf_get(cb));
FCGX_FPrintF(r->out, "}\r\n");
}
break;
default:
clicon_err(OE_YANG, EINVAL, "Invalid media type %d", media);
goto done;

View file

@ -165,8 +165,16 @@ api_data_get2(clicon_handle h,
if ((cbpath = cbuf_new()) == NULL)
goto done;
cprintf(cbpath, "/");
/* We know "data" is element pi-1 */
if ((ret = api_path2xpath_cvv(pcvec, pi, yspec, cbpath, &namespace, &xerr)) < 0)
/* Create a namespace context for ymod as the default namespace to use with
* xpath expressions */
if ((nsc = cvec_new(0)) == NULL){
clicon_err(OE_XML, errno, "cvec_new");
goto done;
}
/* We know "data" is element pi-1.
* Translate api-path to xpath: xpath (cbpath) and namespace context (nsc)
*/
if ((ret = api_path2xpath_cvv2(pcvec, pi, yspec, cbpath, nsc, &xerr)) < 0)
goto done;
if (ret == 0){
clicon_err_reset();
@ -178,36 +186,17 @@ api_data_get2(clicon_handle h,
goto done;
goto ok;
}
if (ret == 0){
if (netconf_operation_failed_xml(&xerr, "protocol", clicon_err_reason) < 0)
goto done;
clicon_err_reset();
if ((xe = xpath_first(xerr, "rpc-error")) == NULL){
clicon_err(OE_XML, EINVAL, "rpc-error not found (internal error)");
goto done;
}
if (api_return_err(h, r, xe, pretty, media_out, 0) < 0)
goto done;
goto ok;
}
xpath = cbuf_get(cbpath);
clicon_debug(1, "%s path:%s", __FUNCTION__, xpath);
/* Create a namespace context for ymod as the default namespace to use with
* xpath expressions */
if ((nsc = xml_nsctx_init(NULL, namespace)) == NULL)
goto done;
switch (content){
case CONTENT_CONFIG:
ret = clicon_rpc_get(h, xpath, namespace, CONTENT_CONFIG, depth, &xret);
break;
case CONTENT_NONCONFIG:
ret = clicon_rpc_get(h, xpath, namespace, CONTENT_NONCONFIG, depth, &xret);
break;
case CONTENT_ALL:
ret = clicon_rpc_get(h, xpath, namespace, CONTENT_ALL, depth, &xret);
ret = clicon_rpc_get_nsc(h, xpath, nsc, content, depth, &xret);
break;
default:
clicon_err(OE_XML, EINVAL, "Invalid content attribute %d", content);
goto done;
break;
}
if (ret < 0){
@ -291,14 +280,14 @@ api_data_get2(clicon_handle h,
switch (media_out){
case YANG_DATA_XML:
for (i=0; i<xlen; i++){
char *prefix, *namespace2; /* Same as namespace? */
char *prefix;
x = xvec[i];
/* Some complexities in grafting namespace in existing trees to new */
prefix = xml_prefix(x);
if (xml_find_type_value(x, prefix, "xmlns", CX_ATTR) == NULL){
if (xml2ns(x, prefix, &namespace2) < 0)
if (xml2ns(x, prefix, &namespace) < 0)
goto done;
if (namespace2 && xmlns_set(x, prefix, namespace2) < 0)
if (namespace && xmlns_set(x, prefix, namespace) < 0)
goto done;
}
if (clicon_xml2cbuf(cbx, x, 0, pretty, -1) < 0) /* Dont print top object? */