From f319c183746c5f20c0e577d37676ab69a050f2cb Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Fri, 9 Aug 2019 14:39:38 +0200 Subject: [PATCH] RESTCONF JSON identity had wrong namespace in sub-objetcs --- CHANGELOG.md | 2 ++ lib/clixon/clixon_xml.h | 1 + lib/src/clixon_json.c | 13 +++++++++++-- lib/src/clixon_xml.c | 26 +++++++++++++++++++++++++- 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f009c151..5555f932 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,6 +49,8 @@ * pseudo-plugin added, to enable callbacks also for main programs. Useful for extensions ### Corrected Bugs +* RESTCONF JSON identity had wrong namespace in sub-objetcs + * Showed if you GET an object with JSON encoding that have identities * Fixed Segv in nacm write when MERGE and creating object * Should only be applicable on netconf MERGE and restconf PATCH * Corrected problem with namespace context cache, was not always cleared when adding new subtrees. diff --git a/lib/clixon/clixon_xml.h b/lib/clixon/clixon_xml.h index 5664a358..0784869a 100644 --- a/lib/clixon/clixon_xml.h +++ b/lib/clixon/clixon_xml.h @@ -109,6 +109,7 @@ 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 nscache_replace(cxobj *x, cvec *ns); 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_json.c b/lib/src/clixon_json.c index a89a4162..1ed29621 100644 --- a/lib/src/clixon_json.c +++ b/lib/src/clixon_json.c @@ -917,13 +917,20 @@ xml2json_cbuf_vec(cbuf *cb, cxobj *xp = NULL; int i; cxobj *xc; + cvec *nsc = NULL; if ((xp = xml_new("xml2json", NULL, NULL)) == NULL) goto done; - /* Some complexities in grafting namespace in existing trees to new */ + /* Make a copy of old and graft it into new top-object + * Also copy namespace context */ for (i=0; ix_ns_cache != NULL){ + xml_nsctx_free(x->x_ns_cache); + x->x_ns_cache = NULL; + } + x->x_ns_cache = nsc; + retval = 0; + // done: + return retval; +} + /*! Clear cached namespace context * Clear the whole namespace context, not just single cache lines * @param[in] x XML node