changed netconf_err2cb
This commit is contained in:
parent
70caeaa783
commit
6b9a9d46f9
5 changed files with 29 additions and 31 deletions
|
|
@ -115,6 +115,7 @@ clixon_plugin_statedata(clicon_handle h,
|
|||
cxobj *x = NULL;
|
||||
clixon_plugin *cp = NULL;
|
||||
plgstatedata_t *fn; /* Plugin statedata fn */
|
||||
cbuf *cberr = NULL;
|
||||
|
||||
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
|
||||
if ((fn = cp->cp_api.ca_statedata) == NULL)
|
||||
|
|
@ -133,21 +134,11 @@ clixon_plugin_statedata(clicon_handle h,
|
|||
if (ret > 0 && (ret = xml_yang_validate_add(h, x, &xerr)) < 0)
|
||||
goto done;
|
||||
if (ret == 0){
|
||||
cbuf *cberr = NULL; /* XXX Cumbersome, try to fold into one cb */
|
||||
cbuf *cberr2 = NULL;
|
||||
if (netconf_err2cb(xpath_first(xerr, "rpc-error"), &cberr) < 0)
|
||||
cprintf(cberr, "Internal error: state callback returned invalid XML: ");
|
||||
if (netconf_err2cb(xpath_first(xerr, "rpc-error"), cberr) < 0)
|
||||
goto done;
|
||||
if ((cberr2 = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
if (netconf_operation_failed_xml(xret, "application", cbuf_get(cberr))< 0)
|
||||
goto done;
|
||||
}
|
||||
cprintf(cberr2, "Internal error: state callback returned invalid XML: %s", cbuf_get(cberr));
|
||||
if (netconf_operation_failed_xml(xret, "application", cbuf_get(cberr2))< 0)
|
||||
goto done;
|
||||
if (cberr)
|
||||
cbuf_free(cberr);
|
||||
if (cberr2)
|
||||
cbuf_free(cberr2);
|
||||
goto fail;
|
||||
}
|
||||
if ((ret = netconf_trymerge(x, yspec, xret)) < 0)
|
||||
|
|
@ -161,6 +152,8 @@ clixon_plugin_statedata(clicon_handle h,
|
|||
}
|
||||
retval = 1;
|
||||
done:
|
||||
if (cberr)
|
||||
cbuf_free(cberr);
|
||||
if (x)
|
||||
xml_free(x);
|
||||
if (xerr)
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ int netconf_trymerge(cxobj *x, yang_stmt *yspec, cxobj **xret);
|
|||
int netconf_module_features(clicon_handle h);
|
||||
int netconf_module_load(clicon_handle h);
|
||||
char *netconf_db_find(cxobj *xn, char *name);
|
||||
int netconf_err2cb(cxobj *xerr, cbuf **cberr);
|
||||
int netconf_err2cb(cxobj *xerr, cbuf *cberr);
|
||||
const netconf_content netconf_content_str2int(char *str);
|
||||
const char *netconf_content_int2str(netconf_content nr);
|
||||
int netconf_hello_server(clicon_handle h, cbuf *cb, uint32_t session_id);
|
||||
|
|
|
|||
|
|
@ -1339,38 +1339,35 @@ netconf_db_find(cxobj *xn,
|
|||
|
||||
/*! Generate netconf error msg to cbuf to use in string printout or logs
|
||||
* @param[in] xerr Netconf error message on the level: <rpc-error>
|
||||
* @param[out] cberr Translation from netconf err to cbuf. Free with cbuf_free.
|
||||
* @param[in,out] cberr Translation from netconf err to cbuf.
|
||||
* @retval 0 OK, with cberr set
|
||||
* @retval -1 Error
|
||||
* @code
|
||||
* cbuf *cb = NULL;
|
||||
* if (netconf_err2cb(xerr, &cb) < 0)
|
||||
* if ((cb = cbuf_new()) ==NULL){
|
||||
* err;
|
||||
* if (netconf_err2cb(xerr, cb) < 0)
|
||||
* err;
|
||||
* printf("%s", cbuf_get(cb));
|
||||
* cbuf_free(cb);
|
||||
* @endcode
|
||||
* @see clicon_rpc_generate_error
|
||||
*/
|
||||
int
|
||||
netconf_err2cb(cxobj *xerr,
|
||||
cbuf **cberr)
|
||||
cbuf *cberr)
|
||||
{
|
||||
int retval = -1;
|
||||
cbuf *cb = NULL;
|
||||
cxobj *x;
|
||||
|
||||
if ((cb = cbuf_new()) ==NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if ((x=xpath_first(xerr, "error-type"))!=NULL)
|
||||
cprintf(cb, "%s ", xml_body(x));
|
||||
cprintf(cberr, "%s ", xml_body(x));
|
||||
if ((x=xpath_first(xerr, "error-tag"))!=NULL)
|
||||
cprintf(cb, "%s ", xml_body(x));
|
||||
cprintf(cberr, "%s ", xml_body(x));
|
||||
if ((x=xpath_first(xerr, "error-message"))!=NULL)
|
||||
cprintf(cb, "%s ", xml_body(x));
|
||||
cprintf(cberr, "%s ", xml_body(x));
|
||||
if ((x=xpath_first(xerr, "error-info"))!=NULL)
|
||||
clicon_xml2cbuf(cb, xml_child_i(x,0), 0, 0, -1);
|
||||
*cberr = cb;
|
||||
clicon_xml2cbuf(cberr, xml_child_i(x,0), 0, 0, -1);
|
||||
retval = 0;
|
||||
done:
|
||||
return retval;
|
||||
|
|
|
|||
|
|
@ -236,7 +236,11 @@ clicon_rpc_generate_error(const char *prefix,
|
|||
int retval = -1;
|
||||
cbuf *cb = NULL;
|
||||
|
||||
if (netconf_err2cb(xerr, &cb) < 0)
|
||||
if ((cb = cbuf_new()) ==NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if (netconf_err2cb(xerr, cb) < 0)
|
||||
goto done;
|
||||
if (prefix)
|
||||
clicon_log(LOG_ERR, "%s: %s", prefix, cbuf_get(cb));
|
||||
|
|
|
|||
|
|
@ -234,7 +234,11 @@ main(int argc,
|
|||
if (ret > 0 && (ret = xml_yang_validate_add(h, xc, &xerr)) < 0)
|
||||
goto done;
|
||||
if (ret == 0){
|
||||
if (netconf_err2cb(xerr, &cbret) < 0)
|
||||
if ((cbret = cbuf_new()) ==NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if (netconf_err2cb(xerr, cbret) < 0)
|
||||
goto done;
|
||||
fprintf(stderr, "xml validation error: %s\n", cbuf_get(cbret));
|
||||
goto done;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue