add yang-spec as arg to decode clicon msg
This commit is contained in:
parent
b443471e7b
commit
11479f7ec3
7 changed files with 23 additions and 20 deletions
|
|
@ -965,6 +965,7 @@ from_client_msg(clicon_handle h,
|
||||||
|
|
||||||
clicon_debug(1, "%s", __FUNCTION__);
|
clicon_debug(1, "%s", __FUNCTION__);
|
||||||
pid = ce->ce_pid;
|
pid = ce->ce_pid;
|
||||||
|
yspec = clicon_dbspec_yang(h);
|
||||||
/* Return netconf message. Should be filled in by the dispatch(sub) functions
|
/* Return netconf message. Should be filled in by the dispatch(sub) functions
|
||||||
* as wither rpc-error or by positive response.
|
* as wither rpc-error or by positive response.
|
||||||
*/
|
*/
|
||||||
|
|
@ -972,21 +973,22 @@ from_client_msg(clicon_handle h,
|
||||||
clicon_err(OE_XML, errno, "cbuf_new");
|
clicon_err(OE_XML, errno, "cbuf_new");
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
if (clicon_msg_decode(msg, &xt) < 0){
|
if (clicon_msg_decode(msg, yspec, &xt) < 0){
|
||||||
if (netconf_malformed_message(cbret, "XML parse error")< 0)
|
if (netconf_malformed_message(cbret, "XML parse error")< 0)
|
||||||
goto done;
|
goto done;
|
||||||
goto reply;
|
goto reply;
|
||||||
}
|
}
|
||||||
/* Get yang spec */
|
|
||||||
yspec = clicon_dbspec_yang(h); /* XXX maybe move to clicon_msg_decode? */
|
|
||||||
if ((x = xpath_first(xt, "/rpc")) == NULL){
|
if ((x = xpath_first(xt, "/rpc")) == NULL){
|
||||||
if (netconf_malformed_message(cbret, "rpc keyword expected")< 0)
|
if (netconf_malformed_message(cbret, "rpc keyword expected")< 0)
|
||||||
goto done;
|
goto done;
|
||||||
goto reply;
|
goto reply;
|
||||||
}
|
}
|
||||||
/* Populate incoming XML tree with yang */
|
/* Populate incoming XML tree with yang -
|
||||||
|
* should really have been dealt with by decode above
|
||||||
|
* maybe not necessary since it should be */
|
||||||
if (xml_spec_populate_rpc(h, x, yspec) < 0)
|
if (xml_spec_populate_rpc(h, x, yspec) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if ((ret = xml_yang_validate_rpc(x, cbret)) < 0)
|
if ((ret = xml_yang_validate_rpc(x, cbret)) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
|
|
|
||||||
|
|
@ -959,7 +959,7 @@ cli_notification_cb(int s,
|
||||||
event_unreg_fd(s, cli_notification_cb);
|
event_unreg_fd(s, cli_notification_cb);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
if (clicon_msg_decode(reply, &xt) < 0)
|
if (clicon_msg_decode(reply, NULL, &xt) < 0) /* XXX pass yang_spec */
|
||||||
goto done;
|
goto done;
|
||||||
if ((xe = xpath_first(xt, "//event")) != NULL){
|
if ((xe = xpath_first(xt, "//event")) != NULL){
|
||||||
x = NULL;
|
x = NULL;
|
||||||
|
|
|
||||||
|
|
@ -754,6 +754,8 @@ netconf_notification_cb(int s,
|
||||||
cbuf *cb;
|
cbuf *cb;
|
||||||
cxobj *xn = NULL; /* event xml */
|
cxobj *xn = NULL; /* event xml */
|
||||||
cxobj *xt = NULL; /* top xml */
|
cxobj *xt = NULL; /* top xml */
|
||||||
|
clicon_handle h = (clicon_handle)arg;
|
||||||
|
yang_spec *yspec = NULL;
|
||||||
|
|
||||||
clicon_debug(1, "%s", __FUNCTION__);
|
clicon_debug(1, "%s", __FUNCTION__);
|
||||||
/* get msg (this is the reason this function is called) */
|
/* get msg (this is the reason this function is called) */
|
||||||
|
|
@ -767,7 +769,8 @@ netconf_notification_cb(int s,
|
||||||
event_unreg_fd(s, netconf_notification_cb);
|
event_unreg_fd(s, netconf_notification_cb);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
if (clicon_msg_decode(reply, &xt) < 0)
|
yspec = clicon_dbspec_yang(h);
|
||||||
|
if (clicon_msg_decode(reply, yspec, &xt) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if ((xn = xpath_first(xt, "notification")) == NULL)
|
if ((xn = xpath_first(xt, "notification")) == NULL)
|
||||||
goto ok;
|
goto ok;
|
||||||
|
|
@ -839,7 +842,7 @@ netconf_create_subscription(clicon_handle h,
|
||||||
goto ok;
|
goto ok;
|
||||||
if (event_reg_fd(s,
|
if (event_reg_fd(s,
|
||||||
netconf_notification_cb,
|
netconf_notification_cb,
|
||||||
NULL,
|
h,
|
||||||
"notification socket") < 0)
|
"notification socket") < 0)
|
||||||
goto done;
|
goto done;
|
||||||
ok:
|
ok:
|
||||||
|
|
|
||||||
|
|
@ -180,7 +180,7 @@ restconf_stream_cb(int s,
|
||||||
clicon_exit_set();
|
clicon_exit_set();
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
if (clicon_msg_decode(reply, &xtop) < 0)
|
if (clicon_msg_decode(reply, NULL, &xtop) < 0) /* XXX pass yang_spec */
|
||||||
goto done;
|
goto done;
|
||||||
/* create event */
|
/* create event */
|
||||||
if ((cb = cbuf_new()) == NULL){
|
if ((cb = cbuf_new()) == NULL){
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ struct clicon_msg *clicon_msg_encode(char *format, ...) __attribute__ ((format (
|
||||||
#else
|
#else
|
||||||
struct clicon_msg *clicon_msg_encode(char *format, ...);
|
struct clicon_msg *clicon_msg_encode(char *format, ...);
|
||||||
#endif
|
#endif
|
||||||
int clicon_msg_decode(struct clicon_msg *msg, cxobj **xml);
|
int clicon_msg_decode(struct clicon_msg *msg, yang_spec *yspec, cxobj **xml);
|
||||||
|
|
||||||
int clicon_connect_unix(char *sockpath);
|
int clicon_connect_unix(char *sockpath);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -160,10 +160,12 @@ clicon_msg_encode(char *format, ...)
|
||||||
|
|
||||||
/*! Decode a clicon netconf message
|
/*! Decode a clicon netconf message
|
||||||
* @param[in] msg CLICON msg
|
* @param[in] msg CLICON msg
|
||||||
|
* @param[in] yspec Yang specification, (can be NULL)
|
||||||
* @param[out] xml XML parse tree
|
* @param[out] xml XML parse tree
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
clicon_msg_decode(struct clicon_msg *msg,
|
clicon_msg_decode(struct clicon_msg *msg,
|
||||||
|
yang_spec *yspec,
|
||||||
cxobj **xml)
|
cxobj **xml)
|
||||||
{
|
{
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
|
|
@ -172,7 +174,7 @@ clicon_msg_decode(struct clicon_msg *msg,
|
||||||
/* body */
|
/* body */
|
||||||
xmlstr = msg->op_body;
|
xmlstr = msg->op_body;
|
||||||
clicon_debug(1, "%s %s", __FUNCTION__, xmlstr);
|
clicon_debug(1, "%s %s", __FUNCTION__, xmlstr);
|
||||||
if (xml_parse_string(xmlstr, NULL, xml) < 0)
|
if (xml_parse_string(xmlstr, yspec, xml) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
|
|
|
||||||
|
|
@ -1623,7 +1623,7 @@ xml_spec_populate_rpc(clicon_handle h,
|
||||||
yang_stmt *ymod=NULL; /* yang module */
|
yang_stmt *ymod=NULL; /* yang module */
|
||||||
yang_stmt *yi = NULL; /* input */
|
yang_stmt *yi = NULL; /* input */
|
||||||
cxobj *x;
|
cxobj *x;
|
||||||
int i;
|
// int i;
|
||||||
|
|
||||||
if ((strcmp(xml_name(xrpc), "rpc"))!=0){
|
if ((strcmp(xml_name(xrpc), "rpc"))!=0){
|
||||||
clicon_err(OE_UNIX, EINVAL, "RPC expected");
|
clicon_err(OE_UNIX, EINVAL, "RPC expected");
|
||||||
|
|
@ -1635,15 +1635,12 @@ xml_spec_populate_rpc(clicon_handle h,
|
||||||
goto done;
|
goto done;
|
||||||
if (ymod != NULL)
|
if (ymod != NULL)
|
||||||
y = yang_find((yang_node*)ymod, Y_RPC, xml_name(x));
|
y = yang_find((yang_node*)ymod, Y_RPC, xml_name(x));
|
||||||
/* Loose semantics: loop through all modules to find the node
|
/* Non-strict semantics: loop through all modules to find the node
|
||||||
*/
|
*/
|
||||||
if (y == NULL &&
|
if (y == NULL &&
|
||||||
!clicon_option_bool(h, "CLICON_XML_NS_STRICT")){
|
!clicon_option_bool(h, "CLICON_XML_NS_STRICT")){
|
||||||
for (i=0; i<yspec->yp_len; i++){
|
if (xml_yang_find_non_strict(x, yspec, &y) < 0) /* find rpc */
|
||||||
ymod = yspec->yp_stmt[i];
|
goto done;
|
||||||
if ((y = yang_find((yang_node*)ymod, Y_RPC, xml_name(x))) != NULL)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (y){
|
if (y){
|
||||||
xml_spec_set(x, y);
|
xml_spec_set(x, y);
|
||||||
|
|
@ -1696,9 +1693,8 @@ xml_spec_populate(cxobj *x,
|
||||||
if (ys_module_by_xml(yspec, x, &ymod) < 0)
|
if (ys_module_by_xml(yspec, x, &ymod) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if (ymod != NULL)
|
if (ymod != NULL)
|
||||||
y = yang_find_datanode((yang_node*)ymod, name);
|
y = yang_find_schemanode((yang_node*)ymod, name);
|
||||||
/* Non-strict semantics: loop through all modules to find the node
|
/* Non-strict semantics: loop through all modules to find the node
|
||||||
* XXX clicon_option_bool(h, "CLICON_XML_NS_STRICT")
|
|
||||||
*/
|
*/
|
||||||
if (y == NULL && !_CLICON_XML_NS_STRICT){
|
if (y == NULL && !_CLICON_XML_NS_STRICT){
|
||||||
if (xml_yang_find_non_strict(x, yspec, &y) < 0)
|
if (xml_yang_find_non_strict(x, yspec, &y) < 0)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue