* Fixed: [restconf patch method adds redundant namespaces #235](https://github.com/clicon/clixon/issues/235)
This commit is contained in:
parent
7d59ec1a3a
commit
a122efceff
7 changed files with 43 additions and 40 deletions
|
|
@ -487,7 +487,6 @@ text_modify(clicon_handle h,
|
|||
if (strcmp(restype, "enumeration") == 0 ||
|
||||
strcmp(restype, "bits") == 0)
|
||||
x1bstr = clixon_trim2(x1bstr, " \t\n");
|
||||
|
||||
/* If origin body has namespace definitions, copy them. The reason is that
|
||||
* some bodies rely on namespace prefixes, such as NACM path, but there is
|
||||
* no way we can know this here.
|
||||
|
|
@ -496,7 +495,7 @@ text_modify(clicon_handle h,
|
|||
* is for element symbols)
|
||||
* Oh well.
|
||||
*/
|
||||
if (assign_namespace_body(x1, x1bstr, x0) < 0)
|
||||
if (assign_namespace_body(x1, x0) < 0)
|
||||
goto done;
|
||||
}
|
||||
if ((x0b = xml_body_get(x0)) != NULL){
|
||||
|
|
|
|||
|
|
@ -933,7 +933,6 @@ add_namespace(cxobj *x,
|
|||
if (xml_value_set(xa, namespace) < 0)
|
||||
goto done;
|
||||
xml_sort(xp); /* Ensure attr is first / XXX xml_insert? */
|
||||
|
||||
retval = 0;
|
||||
done:
|
||||
return retval;
|
||||
|
|
@ -1798,47 +1797,53 @@ assign_namespace_element(cxobj *x0, /* source */
|
|||
return retval;
|
||||
}
|
||||
|
||||
/* If origin body has namespace definitions, copy them. The reason is that
|
||||
/*! Copy namespace declarations from source to target
|
||||
*
|
||||
* If origin body has namespace definitions, copy them. The reason is that
|
||||
* some bodies rely on namespace prefixes, such as NACM path, but there is
|
||||
* no way we can now this here.
|
||||
* However, this may lead to namespace collisions if these prefixes are not
|
||||
* canonical, and may collide with the assign_namespace_element() above (but that
|
||||
* is for element sysmbols)
|
||||
* is for element symbols)
|
||||
*
|
||||
* @param[in] x0 Source XML
|
||||
* @param[in] x1 Destination XML
|
||||
*/
|
||||
int
|
||||
assign_namespace_body(cxobj *x0, /* source */
|
||||
char *x0bstr,
|
||||
cxobj *x1) /* target */
|
||||
{
|
||||
int retval = -1;
|
||||
char *namespace = NULL;
|
||||
char *namespace1;
|
||||
char *name;
|
||||
char *prefix;
|
||||
char *prefix0 = NULL;;
|
||||
char *pexisting = NULL;;
|
||||
char *prefix0;
|
||||
char *prefix1 = NULL;
|
||||
cxobj *xa;
|
||||
|
||||
xa = NULL;
|
||||
while ((xa = xml_child_each(x0, xa, CX_ATTR)) != NULL) {
|
||||
prefix = xml_prefix(xa);
|
||||
prefix0 = xml_prefix(xa);
|
||||
name = xml_name(xa);
|
||||
namespace = xml_value(xa);
|
||||
if ((strcmp(name, "xmlns")==0 && prefix==NULL) ||
|
||||
(prefix != NULL && strcmp(prefix, "xmlns")==0)){
|
||||
if (prefix == NULL)
|
||||
prefix0 = NULL;
|
||||
if ((strcmp(name, "xmlns")==0 && prefix0==NULL) ||
|
||||
(prefix0 != NULL && strcmp(prefix0, "xmlns")==0)){
|
||||
if (prefix0 == NULL)
|
||||
prefix1 = NULL;
|
||||
else
|
||||
prefix0 = name;
|
||||
prefix1 = name;
|
||||
/* prefix1 contains actual prefix or NULL, prefix0 can be xmlns */
|
||||
if (strcmp(namespace, NETCONF_BASE_NAMESPACE) ==0 ||
|
||||
strcmp(namespace, YANG_XML_NAMESPACE) ==0)
|
||||
continue;
|
||||
/* Detect if prefix:namespace is declared already? */
|
||||
if (xml2prefix(x1, namespace, &pexisting) == 1){
|
||||
/* Yes, and it has prefix pexist */
|
||||
if (clicon_strcmp(pexisting, prefix0) ==0)
|
||||
continue;
|
||||
}
|
||||
if (add_namespace(x1, x1, prefix0, namespace) < 0)
|
||||
if (xml2ns(x1, prefix1, &namespace1) == 1)
|
||||
continue;
|
||||
/* Does prefix already point at right namespace? */
|
||||
if (namespace1 && strcmp(namespace, namespace1)==0)
|
||||
continue;
|
||||
/* No, add entry */
|
||||
if (add_namespace(x1, x1, prefix1, namespace) < 0)
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -189,7 +189,7 @@ xml_nsctx_get_prefix(cvec *cvv,
|
|||
/*! Set or replace namespace in namespace context
|
||||
* @param[in] cvv Namespace context
|
||||
* @param[in] prefix Namespace prefix, or NULL for default
|
||||
* @param[in] ns Cached namespace to set (assume non-null?)
|
||||
* @param[in] ns Cached namespace to set (assume non-null?)
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
*/
|
||||
|
|
@ -604,6 +604,8 @@ xmlns_set(cxobj *x,
|
|||
* @retval -1 Error
|
||||
* @retval 0 No namespace found
|
||||
* @retval 1 Namespace found, prefix returned in prefixp
|
||||
* @note a namespace can have two or more prefixes, this just returns the first
|
||||
* @see xml2prefixexists to check a specific pair
|
||||
*/
|
||||
int
|
||||
xml2prefix(cxobj *xn,
|
||||
|
|
@ -660,3 +662,4 @@ xml2prefix(cxobj *xn,
|
|||
goto done;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue