Skip to content

Commit

Permalink
* Fixed: [namespace prefix nc is not supported in full #154](#154)
Browse files Browse the repository at this point in the history
  * edit-config "config" parameter did not work with prefix other than null
  • Loading branch information
olofhagsand committed Dec 2, 2020
1 parent 2b9f19a commit d045e8a
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 17 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ Developers may need to change their code

### Corrected Bugs

* Fixed: [namespace prefix nc is not supported in full #154](https://github.com/clicon/clixon/issues/154)
* edit-config "config" parameter did not work with prefix other than null
* Fixed [YANG: key statement in rpc/notification list #148](https://github.com/clicon/clixon/issues/148)
* Do not check uniqueness among lists without keys

* Fixed typo: [False Header Content_type in restconf error #152](https://github.com/clicon/clixon/issues/152)
* 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)
Expand Down
28 changes: 24 additions & 4 deletions apps/backend/backend_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ from_client_get_config(clicon_handle h,
goto done;
goto ok;
}
/* XXX should use prefix cf edit_config */
if ((xfilter = xml_find(xe, "filter")) != NULL){
if ((xpath0 = xml_find_value(xfilter, "select"))==NULL)
xpath0="/";
Expand Down Expand Up @@ -587,6 +588,8 @@ from_client_edit_config(clicon_handle h,
char *attr;
int autocommit = 0;
char *val = NULL;
cvec *nsc = NULL;
char *prefix = NULL;

username = clicon_username_get(h);
if ((yspec = clicon_dbspec_yang(h)) == NULL){
Expand Down Expand Up @@ -616,15 +619,28 @@ from_client_edit_config(clicon_handle h,
goto done;
goto ok;
}
if ((x = xpath_first(xn, NULL, "default-operation")) != NULL){
if (xml_nsctx_node(xn, &nsc) < 0)
goto done;
/* Get prefix of netconf base namespace in the incoming message */
if (xml_nsctx_get_prefix(nsc, NETCONF_BASE_NAMESPACE, &prefix) == 0){
cprintf(cbx, "No appropriate prefix exists for: %s", NETCONF_BASE_NAMESPACE);
if (netconf_unknown_namespace(cbret, "protocol", xml_name(xn), cbuf_get(cbx)) < 0)
goto done;
goto ok;
}
/* Get default-operation element */
if ((x = xpath_first(xn, nsc, "%s%sdefault-operation", prefix?prefix:"", prefix?":":"")) != NULL){
if (xml_operation(xml_body(x), &operation) < 0){
if (netconf_invalid_value(cbret, "protocol", "Wrong operation")< 0)
goto done;
goto ok;
}
}
if ((xc = xpath_first(xn, NULL, "config")) == NULL){
if (netconf_missing_element(cbret, "protocol", "config", NULL) < 0)
/* Get config element */
if ((xc = xpath_first(xn, nsc, "%s%sconfig", prefix?prefix:"", prefix?":":"")) == NULL){
cprintf(cbx, "Element not found, or mismatching prefix %s for namespace %s",
prefix?prefix:"null", NETCONF_BASE_NAMESPACE);
if (netconf_missing_element(cbret, "protocol", "config", cbuf_get(cbx)) < 0)
goto done;
goto ok;
}
Expand Down Expand Up @@ -713,6 +729,8 @@ from_client_edit_config(clicon_handle h,
ok:
retval = 0;
done:
if (nsc)
cvec_free(nsc);
if (xret)
xml_free(xret);
if (cbx)
Expand Down Expand Up @@ -822,6 +840,7 @@ from_client_delete_config(clicon_handle h,
uint32_t myid = ce->ce_id;
cbuf *cbx = NULL; /* Assist cbuf */

/* XXX should use prefix cf edit_config */
if ((target = netconf_db_find(xe, "target")) == NULL ||
strcmp(target, "running")==0){
if (netconf_missing_element(cbret, "protocol", "target", NULL) < 0)
Expand Down Expand Up @@ -1340,6 +1359,7 @@ from_client_create_subscription(clicon_handle h,
struct timeval stop;
cvec *nsc = NULL;

/* XXX should use prefix cf edit_config */
if ((nsc = xml_nsctx_init(NULL, EVENT_RFC5277_NAMESPACE)) == NULL)
goto done;
if ((x = xpath_first(xe, nsc, "//stream")) != NULL)
Expand Down Expand Up @@ -1654,7 +1674,7 @@ from_client_msg(clicon_handle h,
goto reply;
}
else if (strcmp(namespace, NETCONF_BASE_NAMESPACE) != 0){
cbuf *cbmsg;
cbuf *cbmsg = NULL;
if ((cbmsg = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new");
goto done;
Expand Down
1 change: 1 addition & 0 deletions lib/src/clixon_netconf_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1406,6 +1406,7 @@ netconf_db_find(cxobj *xn,
cxobj *xi;
char *db = NULL;

/* XXX should use prefix cf edit_config */
if ((xs = xml_find(xn, name)) == NULL)
goto done;
if ((xi = xml_child_i(xs, 0)) == NULL)
Expand Down
2 changes: 1 addition & 1 deletion lib/src/clixon_xml.c
Original file line number Diff line number Diff line change
Expand Up @@ -1697,7 +1697,7 @@ xml_find_type_value(cxobj *xt,
*
* The value can be of an attribute only
* @param[in] xt xml tree node
* @param[in] prefix Prefix (namespace local name) or NULL
* @param[in] prefix Prefix (namespace local name) or NULL (any prefix)
* @param[in] name name of xml tree node (eg attr name or "body")
* @param[in] type Matching type or -1 for any
* @retval val Pointer to the name string
Expand Down
20 changes: 10 additions & 10 deletions lib/src/clixon_xpath.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,24 @@
* Clixon XML XPATH 1.0 according to https://www.w3.org/TR/xpath-10
*
* Some notes on namespace extensions in Netconf/Yang
* RFC6241 8.9.1
* The set of namespace declarations are those in scope on the <filter> element.
* 1) The xpath is not "namespace-aware" in the sense that if you look for a path, eg
* "n:a/n:b", those must match the XML, so they need to match prefixes AND name in the xml
* such as <n:a><n:b>. An xml with <m:a><m:b> (or <a><b>) will NOT match EVEN IF they have the
* same namespace given by xmlns settings.
* 2) RFC6241 8.9.1
* In the scope of get-.config, the set of namespace declarations are those in scope on the
* <filter> element.
* <rpc message-id="101" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
* <get-config>
* <filter xmlns:t="http://example.com/schema/1.2/config"
* type="xpath"
* select="/t:top/t:users/t:user[t:name='fred']"/>
* </get-config>
* We need to add namespace context to the cpath tree, typically in eval. How do
* we do that?
* One observation is that the namespace context is static, so it can not be a part
* of the xpath-tree, which is context-dependent.
* Best is to send it as a (read-only) parameter to the xp_eval family of functions
* as an exlicit namespace context.
* For that you need an API to get/set namespaces: clixon_xml_nscache.c?
* Then you need to fix API functions and this is the real work:
* - Replace all existing functions or create new?
* - Expose explicit namespace parameter, or xml object, or default namespace?
*
* @see README.md#xml-and-xpath for description of xpath implementation
*/
#ifdef HAVE_CONFIG_H
#include "clixon_config.h" /* generated by config & autoconf */
Expand Down Expand Up @@ -587,7 +585,9 @@ xpath_vec_ctx(cxobj *xcur,
*
* @code
* cxobj *x;
* cvec *nsc; // namespace context
* cvec *nsc = NULL; // namespace context
* if (xml_nsctx_node(xtop, &nsc) < 0)
* err;
* if ((x = xpath_first(xtop, nsc, "//symbol/foo")) != NULL) {
* ...
* }
Expand Down
Loading

0 comments on commit d045e8a

Please sign in to comment.