* Added message-id attributes in error and hello replies
* See [namespace prefix nc is not supported in full #154](https://github.com/clicon/clixon/issues/154) * Removed mandatory loading of clixon_restconf.yang
This commit is contained in:
parent
26a4b14060
commit
c32950c8a9
20 changed files with 119 additions and 56 deletions
|
|
@ -1379,9 +1379,6 @@ netconf_module_load(clicon_handle h)
|
|||
if (clicon_option_bool(h, "CLICON_XML_CHANGELOG"))
|
||||
if (yang_spec_parse_module(h, "clixon-xml-changelog", NULL, yspec)< 0)
|
||||
goto done;
|
||||
/* Clixon restconf daemon */
|
||||
if (yang_spec_parse_module(h, "clixon-restconf", NULL, yspec)< 0)
|
||||
goto done;
|
||||
retval = 0;
|
||||
done:
|
||||
return retval;
|
||||
|
|
@ -1538,7 +1535,7 @@ netconf_hello_server(clicon_handle h,
|
|||
|
||||
module_set_id = clicon_option_str(h, "CLICON_MODULE_SET_ID");
|
||||
|
||||
cprintf(cb, "<hello xmlns=\"%s\">", NETCONF_BASE_NAMESPACE);
|
||||
cprintf(cb, "<hello xmlns=\"%s\" message-id=\"%u\">", NETCONF_BASE_NAMESPACE, 42);
|
||||
cprintf(cb, "<capabilities>");
|
||||
cprintf(cb, "<capability>urn:ietf:params:netconf:base:1.0</capability>");
|
||||
/* Check if RFC7895 loaded and revision found */
|
||||
|
|
|
|||
|
|
@ -790,8 +790,8 @@ clicon_rpc_close_session(clicon_handle h)
|
|||
goto done;
|
||||
username = clicon_username_get(h);
|
||||
if ((msg = clicon_msg_encode(session_id,
|
||||
"<rpc xmlns=\"%s\" username=\"%s\"><close-session/></rpc>",
|
||||
NETCONF_BASE_NAMESPACE, username?username:"")) == NULL)
|
||||
"<rpc xmlns=\"%s\" username=\"%s\" message-id=\"%u\"><close-session/></rpc>",
|
||||
NETCONF_BASE_NAMESPACE, username?username:"", 42)) == NULL)
|
||||
goto done;
|
||||
if (clicon_rpc_msg(h, msg, &xret, NULL) < 0)
|
||||
goto done;
|
||||
|
|
@ -1084,7 +1084,7 @@ clicon_hello_req(clicon_handle h,
|
|||
int ret;
|
||||
|
||||
username = clicon_username_get(h);
|
||||
if ((msg = clicon_msg_encode(0, "<hello username=\"%s\" xmlns=\"%s\"><capabilities><capability>urn:ietf:params:netconf:base:1.0</capability></capabilities></hello>",
|
||||
if ((msg = clicon_msg_encode(0, "<hello username=\"%s\" xmlns=\"%s\" message-id=\"42\"><capabilities><capability>urn:ietf:params:netconf:base:1.0</capability></capabilities></hello>",
|
||||
username?username:"",
|
||||
NETCONF_BASE_NAMESPACE)) == NULL)
|
||||
goto done;
|
||||
|
|
@ -1111,5 +1111,3 @@ clicon_hello_req(clicon_handle h,
|
|||
xml_free(xret);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -72,6 +72,7 @@
|
|||
#include "clixon_netconf_lib.h"
|
||||
#include "clixon_options.h"
|
||||
#include "clixon_xml_nsctx.h"
|
||||
#include "clixon_xml_io.h"
|
||||
#include "clixon_xpath_ctx.h"
|
||||
#include "clixon_xpath.h"
|
||||
#include "clixon_yang_module.h"
|
||||
|
|
@ -332,6 +333,7 @@ xml_yang_validate_rpc(clicon_handle h,
|
|||
cxobj *xn; /* rpc name */
|
||||
char *rpcprefix;
|
||||
char *namespace = NULL;
|
||||
int ret;
|
||||
|
||||
if (strcmp(xml_name(xrpc), "rpc")){
|
||||
clicon_err(OE_XML, EINVAL, "Expected RPC");
|
||||
|
|
@ -357,10 +359,14 @@ xml_yang_validate_rpc(clicon_handle h,
|
|||
goto done;
|
||||
goto fail;
|
||||
}
|
||||
if ((retval = xml_yang_validate_all(h, xn, xret)) < 1)
|
||||
if ((ret = xml_yang_validate_all(h, xn, xret)) < 0)
|
||||
goto done; /* error or validation fail */
|
||||
if ((retval = xml_yang_validate_add(h, xn, xret)) < 1)
|
||||
if (ret == 0)
|
||||
goto fail;
|
||||
if ((ret = xml_yang_validate_add(h, xn, xret)) < 0)
|
||||
goto done; /* error or validation fail */
|
||||
if (ret == 0)
|
||||
goto fail;
|
||||
if (xml_default_recurse(xn, 0) < 0)
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -369,6 +375,8 @@ xml_yang_validate_rpc(clicon_handle h,
|
|||
done:
|
||||
return retval;
|
||||
fail:
|
||||
if (xret && *xret && clixon_xml_attr_copy(xrpc, *xret, "message-id") < 0)
|
||||
goto done;
|
||||
retval = 0;
|
||||
goto done;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -526,8 +526,11 @@ _xml_parse(const char *str,
|
|||
case YB_RPC:
|
||||
if ((ret = xml_bind_yang_rpc(x, yspec, xerr)) < 0)
|
||||
goto done;
|
||||
if (ret == 0)
|
||||
if (ret == 0){ /* Add message-id */
|
||||
if (*xerr && clixon_xml_attr_copy(x, *xerr, "message-id") < 0)
|
||||
goto done;
|
||||
failed++;
|
||||
}
|
||||
break;
|
||||
} /* switch */
|
||||
}
|
||||
|
|
@ -769,3 +772,38 @@ clixon_xml_parse_va(yang_bind yb,
|
|||
return retval;
|
||||
}
|
||||
|
||||
/*! Copy an attribute value(eg message-id) from one xml (eg rpc input) to another xml (eg rpc outgoing)
|
||||
* @param[in] xin Get attr value from this XML
|
||||
* @param[in] xout Set attr value to this XML
|
||||
* @param[in] name Attribute name
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
* Alternative is to use: char *val = xml_find_value(x, name);
|
||||
* @code
|
||||
* if (clixon_xml_attr_copy(xin, xout, "message-id") < 0)
|
||||
* err;
|
||||
* @endcode
|
||||
*/
|
||||
int
|
||||
clixon_xml_attr_copy(cxobj *xin,
|
||||
cxobj *xout,
|
||||
char *name)
|
||||
{
|
||||
int retval = -1;
|
||||
char *msgid;
|
||||
cxobj *xa;
|
||||
|
||||
if (xin == NULL || xout == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "xin or xout NULL");
|
||||
goto done;
|
||||
}
|
||||
if ((msgid = xml_find_value(xin, "message-id")) != NULL){
|
||||
if ((xa = xml_new("message-id", xout, CX_ATTR)) == NULL)
|
||||
goto done;
|
||||
if (xml_value_set(xa, msgid) < 0)
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
done:
|
||||
return retval;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue