Netconf error callback resilient to prefixes
Reformat json code
This commit is contained in:
parent
e619632ac7
commit
7713e79dc2
3 changed files with 47 additions and 47 deletions
|
|
@ -249,20 +249,20 @@ example_cli_errmsg(clicon_handle h,
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
cxobj *x;
|
cxobj *x;
|
||||||
|
|
||||||
if ((x=xpath_first(xerr, NULL, "//error-type"))!=NULL)
|
if ((x = xml_find_type(xerr, NULL, "error-type", CX_ELMNT)) != NULL)
|
||||||
cprintf(cberr, "%s ", xml_body(x));
|
cprintf(cberr, "%s ", xml_body(x));
|
||||||
if ((x=xpath_first(xerr, NULL, "//error-tag"))!=NULL)
|
if ((x = xml_find_type(xerr, NULL, "error-tag", CX_ELMNT)) != NULL)
|
||||||
cprintf(cberr, "%s ", xml_body(x));
|
cprintf(cberr, "%s ", xml_body(x));
|
||||||
if ((x=xpath_first(xerr, NULL, "//error-message"))!=NULL)
|
if ((x = xml_find_type(xerr, NULL, "error-message", CX_ELMNT)) != NULL)
|
||||||
cprintf(cberr, "%s ", xml_body(x));
|
cprintf(cberr, "%s ", xml_body(x));
|
||||||
if ((x=xpath_first(xerr, NULL, "//error-info")) != NULL &&
|
if ((x = xml_find_type(xerr, NULL, "error-info", CX_ELMNT)) != NULL &&
|
||||||
xml_child_nr(x) > 0){
|
xml_child_nr(x) > 0){
|
||||||
if (clixon_xml2cbuf(cberr, xml_child_i(x, 0), 0, 0, NULL, -1, 0) < 0)
|
if (clixon_xml2cbuf(cberr, xml_child_i(x, 0), 0, 0, NULL, -1, 0) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
if ((x=xpath_first(xerr, NULL, "//error-app-tag"))!=NULL)
|
if ((x = xml_find_type(xerr, NULL, "error-app-tag", CX_ELMNT)) != NULL)
|
||||||
cprintf(cberr, ": %s ", xml_body(x));
|
cprintf(cberr, ": %s ", xml_body(x));
|
||||||
if ((x=xpath_first(xerr, NULL, "//error-path"))!=NULL)
|
if ((x = xml_find_type(xerr, NULL, "error-path", CX_ELMNT)) != NULL)
|
||||||
cprintf(cberr, ": %s ", xml_body(x));
|
cprintf(cberr, ": %s ", xml_body(x));
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
|
|
|
||||||
|
|
@ -368,8 +368,8 @@ json2xml_decode_identityref(cxobj *x,
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
if (xerr && netconf_unknown_namespace_xml(xerr, "application",
|
if (xerr && netconf_unknown_namespace_xml(xerr, "application",
|
||||||
prefix,
|
prefix,
|
||||||
"No module corresponding to prefix") < 0)
|
"No module corresponding to prefix") < 0)
|
||||||
goto done;
|
goto done;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
@ -483,10 +483,10 @@ xml2json_encode_identityref(cxobj *xb,
|
||||||
// clixon_debug(CLIXON_DBG_DEFAULT, "%s body:%s prefix:%s namespace:%s", __FUNCTION__, body, prefix, namespace);
|
// clixon_debug(CLIXON_DBG_DEFAULT, "%s body:%s prefix:%s namespace:%s", __FUNCTION__, body, prefix, namespace);
|
||||||
#ifdef IDENTITYREF_KLUDGE
|
#ifdef IDENTITYREF_KLUDGE
|
||||||
if (namespace == NULL){
|
if (namespace == NULL){
|
||||||
/* If we dont find namespace here, we assume it is because of a missing
|
/* If we dont find namespace here, we assume it is because of a missing
|
||||||
* xmlns that should be there, as a kludge we search for its (own)
|
* xmlns that should be there, as a kludge we search for its (own)
|
||||||
* prefix in mymodule.
|
* prefix in mymodule.
|
||||||
*/
|
*/
|
||||||
if ((ymod = yang_find_module_by_prefix_yspec(yspec, prefix)) != NULL)
|
if ((ymod = yang_find_module_by_prefix_yspec(yspec, prefix)) != NULL)
|
||||||
cprintf(cb, "%s:%s", yang_argument_get(ymod), id);
|
cprintf(cb, "%s:%s", yang_argument_get(ymod), id);
|
||||||
else
|
else
|
||||||
|
|
@ -495,15 +495,15 @@ xml2json_encode_identityref(cxobj *xb,
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
if ((ymod = yang_find_module_by_namespace(yspec, namespace)) != NULL){
|
if ((ymod = yang_find_module_by_namespace(yspec, namespace)) != NULL){
|
||||||
if (ymod == my_ymod)
|
if (ymod == my_ymod)
|
||||||
cprintf(cb, "%s", id);
|
cprintf(cb, "%s", id);
|
||||||
else{
|
else{
|
||||||
cprintf(cb, "%s:%s", yang_argument_get(ymod), id);
|
cprintf(cb, "%s:%s", yang_argument_get(ymod), id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
cprintf(cb, "%s", id);
|
cprintf(cb, "%s", id);
|
||||||
}
|
}
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
|
|
@ -576,16 +576,16 @@ xml2json_encode_leafs(cxobj *xb,
|
||||||
case CGV_INT64:
|
case CGV_INT64:
|
||||||
case CGV_UINT64:
|
case CGV_UINT64:
|
||||||
case CGV_DEC64:
|
case CGV_DEC64:
|
||||||
// [RFC7951] JSON Encoding of YANG Data
|
// [RFC7951] JSON Encoding of YANG Data
|
||||||
// 6.1 Numeric Types - A value of the "int64", "uint64", or "decimal64" type is represented as a JSON string
|
// 6.1 Numeric Types - A value of the "int64", "uint64", or "decimal64" type is represented as a JSON string
|
||||||
if (yang_keyword_get(yp) == Y_LEAF_LIST && xml_child_nr_type(xml_parent(xp), CX_ELMNT) == 1) {
|
if (yang_keyword_get(yp) == Y_LEAF_LIST && xml_child_nr_type(xml_parent(xp), CX_ELMNT) == 1) {
|
||||||
cprintf(cb, "[%s]", body);
|
cprintf(cb, "[%s]", body);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
cprintf(cb, "%s", body);
|
cprintf(cb, "%s", body);
|
||||||
}
|
}
|
||||||
quote = 1;
|
quote = 1;
|
||||||
break;
|
break;
|
||||||
case CGV_INT8:
|
case CGV_INT8:
|
||||||
case CGV_INT16:
|
case CGV_INT16:
|
||||||
case CGV_INT32:
|
case CGV_INT32:
|
||||||
|
|
@ -970,8 +970,8 @@ xml2json1_cbuf(cbuf *cb,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
xc_arraytype = array_eval(i?xml_child_i(x,i-1):NULL,
|
xc_arraytype = array_eval(i?xml_child_i(x,i-1):NULL,
|
||||||
xc,
|
xc,
|
||||||
xml_child_i(x, i+1));
|
xml_child_i(x, i+1));
|
||||||
if (xml2json1_cbuf(cb,
|
if (xml2json1_cbuf(cb,
|
||||||
xc,
|
xc,
|
||||||
xc_arraytype,
|
xc_arraytype,
|
||||||
|
|
@ -1216,11 +1216,11 @@ xml2json_cbuf_vec(cbuf *cb,
|
||||||
cvec_free(nsc);
|
cvec_free(nsc);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if ((xc = xml_dup(xc0)) == NULL)
|
if ((xc = xml_dup(xc0)) == NULL)
|
||||||
goto done;
|
goto done;
|
||||||
xml_addsub(xp, xc);
|
xml_addsub(xp, xc);
|
||||||
nscache_replace(xc, nsc);
|
nscache_replace(xc, nsc);
|
||||||
}
|
}
|
||||||
nsc = NULL; /* nsc consumed */
|
nsc = NULL; /* nsc consumed */
|
||||||
}
|
}
|
||||||
if (0){
|
if (0){
|
||||||
|
|
@ -1238,8 +1238,8 @@ xml2json_cbuf_vec(cbuf *cb,
|
||||||
if (0){
|
if (0){
|
||||||
level--;
|
level--;
|
||||||
cprintf(cb, "%s]%s",
|
cprintf(cb, "%s]%s",
|
||||||
pretty?"\n":"",
|
pretty?"\n":"",
|
||||||
pretty?"\n":""); /* top object */
|
pretty?"\n":""); /* top object */
|
||||||
}
|
}
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
|
|
@ -1495,7 +1495,7 @@ _json_parse(char *str,
|
||||||
switch (yb){
|
switch (yb){
|
||||||
case YB_PARENT:
|
case YB_PARENT:
|
||||||
if ((ret = xml_bind_yang0(NULL, x, yb, yspec, xerr)) < 0)
|
if ((ret = xml_bind_yang0(NULL, x, yb, yspec, xerr)) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
failed++;
|
failed++;
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -1778,20 +1778,20 @@ netconf_err2cb(clicon_handle h,
|
||||||
if (clixon_plugin_netconf_errmsg_all(h, xerr, cberr) < 0)
|
if (clixon_plugin_netconf_errmsg_all(h, xerr, cberr) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if (cbuf_len(cberr) == len){ /* Same as on-entry, use default */
|
if (cbuf_len(cberr) == len){ /* Same as on-entry, use default */
|
||||||
if ((x=xpath_first(xerr, NULL, "//error-type"))!=NULL)
|
if ((x = xml_find_type(xerr, NULL, "error-type", CX_ELMNT)) != NULL)
|
||||||
cprintf(cberr, "%s ", xml_body(x));
|
cprintf(cberr, "%s ", xml_body(x));
|
||||||
if ((x=xpath_first(xerr, NULL, "//error-tag"))!=NULL)
|
if ((x = xml_find_type(xerr, NULL, "error-tag", CX_ELMNT)) != NULL)
|
||||||
cprintf(cberr, "%s ", xml_body(x));
|
cprintf(cberr, "%s ", xml_body(x));
|
||||||
if ((x=xpath_first(xerr, NULL, "//error-message"))!=NULL)
|
if ((x = xml_find_type(xerr, NULL, "error-message", CX_ELMNT)) != NULL)
|
||||||
cprintf(cberr, "%s ", xml_body(x));
|
cprintf(cberr, "%s ", xml_body(x));
|
||||||
if ((x=xpath_first(xerr, NULL, "//error-info")) != NULL &&
|
if ((x = xml_find_type(xerr, NULL, "error-info", CX_ELMNT)) != NULL &&
|
||||||
xml_child_nr(x) > 0){
|
xml_child_nr(x) > 0){
|
||||||
if (clixon_xml2cbuf(cberr, xml_child_i(x, 0), 0, 0, NULL, -1, 0) < 0)
|
if (clixon_xml2cbuf(cberr, xml_child_i(x, 0), 0, 0, NULL, -1, 0) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
if ((x=xpath_first(xerr, NULL, "//error-app-tag"))!=NULL)
|
if ((x = xml_find_type(xerr, NULL, "error-app-tag", CX_ELMNT)) != NULL)
|
||||||
cprintf(cberr, ": %s ", xml_body(x));
|
cprintf(cberr, ": %s ", xml_body(x));
|
||||||
if ((x=xpath_first(xerr, NULL, "//error-path"))!=NULL)
|
if ((x = xml_find_type(xerr, NULL, "error-path", CX_ELMNT)) != NULL)
|
||||||
cprintf(cberr, ": %s ", xml_body(x));
|
cprintf(cberr, ": %s ", xml_body(x));
|
||||||
}
|
}
|
||||||
retval = 0;
|
retval = 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue