diff --git a/CHANGELOG.md b/CHANGELOG.md index 85e2065b..8e0a84d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,7 @@ * pseudo-plugin added, to enable callbacks also for main programs. Useful for extensions ### Corrected Bugs +* Corrected problem with namespace context cache, was not always cleared when adding new subtrees. * Corrected CLI bug with lists of multiple keys (netconf/restconf works). * Worked in 3.10, but broke in 4.0 * Example: `yang list x { key "a b";...}` diff --git a/lib/clixon/clixon_xml.h b/lib/clixon/clixon_xml.h index b9ef6d08..5664a358 100644 --- a/lib/clixon/clixon_xml.h +++ b/lib/clixon/clixon_xml.h @@ -108,6 +108,7 @@ char *xml_name(cxobj *xn); int xml_name_set(cxobj *xn, char *name); char *xml_prefix(cxobj *xn); int xml_prefix_set(cxobj *xn, char *name); +int nscache_clear(cxobj *x); int xml2ns(cxobj *x, char *localname, char **namespace); int xmlns_set(cxobj *x, char *prefix, char *namespace); cxobj *xml_parent(cxobj *xn); diff --git a/lib/src/clixon_xml.c b/lib/src/clixon_xml.c index ccb31ab6..af1fc5bd 100644 --- a/lib/src/clixon_xml.c +++ b/lib/src/clixon_xml.c @@ -271,6 +271,23 @@ nscache_set(cxobj *x, return retval; } +/*! Clear cached namespace context + * Clear the whole namespace context, not just single cache lines + * @param[in] x XML node + * @retval 0 OK + * @see nscache_set For setting specific namespace cache lines + * @see xml_addsub + */ +int +nscache_clear(cxobj *x) +{ + if (x->x_ns_cache != NULL){ + xml_nsctx_free(x->x_ns_cache); + x->x_ns_cache = NULL; + } + return 0; +} + /*! Given an xml tree return URI namespace recursively : default or localname given * * Given an XML tree and a prefix (or NULL) return URI namespace. @@ -934,6 +951,7 @@ xml_find(cxobj *x_up, * @retval 0 OK * @retval -1 Error * @see xml_wrap + * @see xml_insert * @note xc is not sorted correctly, need to call xml_sort on parent */ int @@ -973,6 +991,8 @@ xml_addsub(cxobj *xp, if (strcmp(pns, cns) == 0) xml_purge(xa); } + /* clear namespace context cache of child */ + nscache_clear(xp); } return 0; } diff --git a/lib/src/clixon_xml_sort.c b/lib/src/clixon_xml_sort.c index bd685164..56454667 100644 --- a/lib/src/clixon_xml_sort.c +++ b/lib/src/clixon_xml_sort.c @@ -710,6 +710,9 @@ xml_insert(cxobj *xp, if (xml_child_insert_pos(xp, xi, i) < 0) goto done; xml_parent_set(xi, xp); + /* clear namespace context cache of child */ + nscache_clear(xi); + retval = 0; done: return retval;