State callback error message changed to include namespace and use proper <bad-element>

This commit is contained in:
Olof hagsand 2019-12-21 20:50:55 +01:00
parent 7ad16bd84b
commit b78054e7cf
4 changed files with 38 additions and 14 deletions

View file

@ -12,7 +12,7 @@
* Get it with `clicon_nsctx_global_get(h)` * Get it with `clicon_nsctx_global_get(h)`
* Added wildcard `*` as a mode to `CLICON_MODE` in clispec files * Added wildcard `*` as a mode to `CLICON_MODE` in clispec files
* If you set "CLICON_MODE="*";" in a clispec file it means that syntax will appear in all CLI spec modes. * If you set "CLICON_MODE="*";" in a clispec file it means that syntax will appear in all CLI spec modes.
* State callbacks provided by user are validated. If they are invalid an internal error is returned. * State callbacks provided by user are validated. If they are invalid an internal error is returned, example, with error-tag: `operation-failed`and with error-message containing. `Internal error, state callback returned invalid XML`.
* Fixed multi-namespace for augmented state which was not covered in 4.2.0. * Fixed multi-namespace for augmented state which was not covered in 4.2.0.
### API changes on existing features (you may need to change your code) ### API changes on existing features (you may need to change your code)

View file

@ -134,19 +134,25 @@ clixon_plugin_statedata(clicon_handle h,
if (ret > 0 && (ret = xml_yang_validate_add(h, x, &xerr)) < 0) if (ret > 0 && (ret = xml_yang_validate_add(h, x, &xerr)) < 0)
goto done; goto done;
if (ret == 0){ if (ret == 0){
if ((cberr = cbuf_new()) ==NULL){ cxobj *xe;
clicon_err(OE_XML, errno, "cbuf_new"); cxobj *xb;
goto done;
if ((xe = xpath_first(xerr, NULL, "//error-tag")) != NULL &&
(xb = xml_body_get(xe))){
if (xml_value_set(xb, "operation-failed") < 0)
goto done;
}
if ((xe = xpath_first(xerr, NULL, "//error-message")) != NULL &&
(xb = xml_body_get(xe))){
if (xml_value_append(xb, " Internal error, state callback returned invalid XML") < 0)
goto done;
} }
cprintf(cberr, "Internal error: state callback returned invalid XML: ");
if (netconf_err2cb(xpath_first(xerr, NULL, "rpc-error"), cberr) < 0)
goto done;
if (*xret){ if (*xret){
xml_free(*xret); xml_free(*xret);
*xret = NULL; *xret = NULL;
} }
if (netconf_operation_failed_xml(xret, "application", cbuf_get(cberr))< 0) *xret = xerr;
goto done; xerr = NULL;
goto fail; goto fail;
} }
#if 1 #if 1

View file

@ -953,7 +953,7 @@ netconf_operation_not_supported(cbuf *cb,
* some reason not covered by any other error condition. * some reason not covered by any other error condition.
* @param[out] cb CLIgen buf. Error XML is written in this buffer * @param[out] cb CLIgen buf. Error XML is written in this buffer
* @param[in] type Error type: "rpc", "application" or "protocol" * @param[in] type Error type: "rpc", "application" or "protocol"
* @param[in] message Error message * @param[in] message Error message (will be XML encoded)
* @see netconf_operation_failed_xml Same but returns XML tree * @see netconf_operation_failed_xml Same but returns XML tree
*/ */
int int
@ -994,6 +994,7 @@ int
netconf_operation_failed_xml(cxobj **xret, netconf_operation_failed_xml(cxobj **xret,
char *type, char *type,
char *message) char *message)
{ {
int retval =-1; int retval =-1;
cxobj *xerr; cxobj *xerr;
@ -1009,7 +1010,8 @@ netconf_operation_failed_xml(cxobj **xret,
goto done; goto done;
if (xml_parse_va(&xerr, NULL, "<error-type>%s</error-type>" if (xml_parse_va(&xerr, NULL, "<error-type>%s</error-type>"
"<error-tag>operation-failed</error-tag>" "<error-tag>operation-failed</error-tag>"
"<error-severity>error</error-severity>", type) < 0) "<error-severity>error</error-severity>",
type) < 0)
goto done; goto done;
if (message){ if (message){
if (xml_chardata_encode(&encstr, "%s", message) < 0) if (xml_chardata_encode(&encstr, "%s", message) < 0)

View file

@ -1274,13 +1274,27 @@ xml_yang_validate_all(clicon_handle h,
int nr; int nr;
int ret; int ret;
cxobj *x; cxobj *x;
char *namespace = NULL;
cbuf *cb = NULL;
/* if not given by argument (overide) use default link /* if not given by argument (overide) use default link
and !Node has a config sub-statement and it is false */ and !Node has a config sub-statement and it is false */
ys=xml_spec(xt); ys=xml_spec(xt);
if (ys==NULL){ if (ys==NULL){
if (netconf_unknown_element_xml(xret, "application", xml_name(xt), NULL) < 0) if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
}
if (xml2ns(xt, xml_prefix(xt), &namespace) < 0)
goto done;
if (namespace){
cprintf(cb, "namespace is: %s", namespace);
if (netconf_unknown_element_xml(xret, "application", xml_name(xt), cbuf_get(cb)) < 0)
goto done;
}
else
if (netconf_unknown_element_xml(xret, "application", xml_name(xt), NULL) < 0)
goto done;
goto fail; goto fail;
} }
if (yang_config(ys) != 0){ if (yang_config(ys) != 0){
@ -1363,6 +1377,8 @@ xml_yang_validate_all(clicon_handle h,
ok: ok:
retval = 1; retval = 1;
done: done:
if (cb)
cbuf_free(cb);
return retval; return retval;
fail: fail:
retval = 0; retval = 0;