diff --git a/apps/backend/backend_client.c b/apps/backend/backend_client.c index 6a8b5943..a141f09f 100644 --- a/apps/backend/backend_client.c +++ b/apps/backend/backend_client.c @@ -965,6 +965,7 @@ from_client_msg(clicon_handle h, clicon_debug(1, "%s", __FUNCTION__); pid = ce->ce_pid; + yspec = clicon_dbspec_yang(h); /* Return netconf message. Should be filled in by the dispatch(sub) functions * 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"); 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) goto done; 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 (netconf_malformed_message(cbret, "rpc keyword expected")< 0) goto done; 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) - goto done; + goto done; if ((ret = xml_yang_validate_rpc(x, cbret)) < 0) goto done; if (ret == 0) diff --git a/apps/cli/cli_common.c b/apps/cli/cli_common.c index ebab38a7..8a52207e 100644 --- a/apps/cli/cli_common.c +++ b/apps/cli/cli_common.c @@ -959,7 +959,7 @@ cli_notification_cb(int s, event_unreg_fd(s, cli_notification_cb); goto done; } - if (clicon_msg_decode(reply, &xt) < 0) + if (clicon_msg_decode(reply, NULL, &xt) < 0) /* XXX pass yang_spec */ goto done; if ((xe = xpath_first(xt, "//event")) != NULL){ x = NULL; diff --git a/apps/netconf/netconf_rpc.c b/apps/netconf/netconf_rpc.c index f2bbb605..0770a0b9 100644 --- a/apps/netconf/netconf_rpc.c +++ b/apps/netconf/netconf_rpc.c @@ -754,6 +754,8 @@ netconf_notification_cb(int s, cbuf *cb; cxobj *xn = NULL; /* event xml */ cxobj *xt = NULL; /* top xml */ + clicon_handle h = (clicon_handle)arg; + yang_spec *yspec = NULL; clicon_debug(1, "%s", __FUNCTION__); /* 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); goto done; } - if (clicon_msg_decode(reply, &xt) < 0) + yspec = clicon_dbspec_yang(h); + if (clicon_msg_decode(reply, yspec, &xt) < 0) goto done; if ((xn = xpath_first(xt, "notification")) == NULL) goto ok; @@ -839,7 +842,7 @@ netconf_create_subscription(clicon_handle h, goto ok; if (event_reg_fd(s, netconf_notification_cb, - NULL, + h, "notification socket") < 0) goto done; ok: diff --git a/apps/restconf/restconf_stream.c b/apps/restconf/restconf_stream.c index 667db0ad..3d34c798 100644 --- a/apps/restconf/restconf_stream.c +++ b/apps/restconf/restconf_stream.c @@ -180,7 +180,7 @@ restconf_stream_cb(int s, clicon_exit_set(); goto done; } - if (clicon_msg_decode(reply, &xtop) < 0) + if (clicon_msg_decode(reply, NULL, &xtop) < 0) /* XXX pass yang_spec */ goto done; /* create event */ if ((cb = cbuf_new()) == NULL){ diff --git a/lib/clixon/clixon_proto.h b/lib/clixon/clixon_proto.h index 3d9e6603..e5457685 100644 --- a/lib/clixon/clixon_proto.h +++ b/lib/clixon/clixon_proto.h @@ -66,7 +66,7 @@ struct clicon_msg *clicon_msg_encode(char *format, ...) __attribute__ ((format ( #else struct clicon_msg *clicon_msg_encode(char *format, ...); #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); diff --git a/lib/src/clixon_proto.c b/lib/src/clixon_proto.c index 30da4e59..76c7816e 100644 --- a/lib/src/clixon_proto.c +++ b/lib/src/clixon_proto.c @@ -160,10 +160,12 @@ clicon_msg_encode(char *format, ...) /*! Decode a clicon netconf message * @param[in] msg CLICON msg + * @param[in] yspec Yang specification, (can be NULL) * @param[out] xml XML parse tree */ int clicon_msg_decode(struct clicon_msg *msg, + yang_spec *yspec, cxobj **xml) { int retval = -1; @@ -172,7 +174,7 @@ clicon_msg_decode(struct clicon_msg *msg, /* body */ xmlstr = msg->op_body; 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; retval = 0; done: diff --git a/lib/src/clixon_xml_map.c b/lib/src/clixon_xml_map.c index d3585ee4..660c4849 100644 --- a/lib/src/clixon_xml_map.c +++ b/lib/src/clixon_xml_map.c @@ -1623,7 +1623,7 @@ xml_spec_populate_rpc(clicon_handle h, yang_stmt *ymod=NULL; /* yang module */ yang_stmt *yi = NULL; /* input */ cxobj *x; - int i; + // int i; if ((strcmp(xml_name(xrpc), "rpc"))!=0){ clicon_err(OE_UNIX, EINVAL, "RPC expected"); @@ -1635,15 +1635,12 @@ xml_spec_populate_rpc(clicon_handle h, goto done; if (ymod != NULL) 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 && !clicon_option_bool(h, "CLICON_XML_NS_STRICT")){ - for (i=0; iyp_len; i++){ - ymod = yspec->yp_stmt[i]; - if ((y = yang_find((yang_node*)ymod, Y_RPC, xml_name(x))) != NULL) - break; - } + if (xml_yang_find_non_strict(x, yspec, &y) < 0) /* find rpc */ + goto done; } if (y){ xml_spec_set(x, y); @@ -1696,9 +1693,8 @@ xml_spec_populate(cxobj *x, if (ys_module_by_xml(yspec, x, &ymod) < 0) goto done; 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 - * XXX clicon_option_bool(h, "CLICON_XML_NS_STRICT") */ if (y == NULL && !_CLICON_XML_NS_STRICT){ if (xml_yang_find_non_strict(x, yspec, &y) < 0)