RESTCONF JSON identity had wrong namespace in sub-objetcs

This commit is contained in:
Olof hagsand 2019-08-09 14:39:38 +02:00
parent a57dbfc6f0
commit f319c18374
4 changed files with 39 additions and 3 deletions

View file

@ -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.

View file

@ -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);

View file

@ -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; i<veclen; i++){
xc = xml_dup(vec[i]);
if (xml_nsctx_node(vec[i], &nsc) < 0)
goto done;
if ((xc = xml_dup(vec[i])) == NULL)
goto done;
xml_addsub(xp, xc);
nscache_replace(xc, nsc);
nsc = NULL; /* nsc consumed */
}
if (0){
cprintf(cb, "[%s", pretty?"\n":" ");
@ -944,6 +951,8 @@ xml2json_cbuf_vec(cbuf *cb,
}
retval = 0;
done:
if (nsc)
xml_nsctx_free(nsc);
if (xp)
xml_free(xp);
return retval;

View file

@ -246,12 +246,13 @@ nscache_get(cxobj *x,
return NULL;
}
/*! Set cached namespace. Replace if necessary
/*! Set cached namespace for specific namespace. Replace if necessary
* @param[in] x XML node
* @param[in] prefix Namespace prefix, or NULL for default
* @param[in] namespace Cached namespace to set (assume non-null?)
* @retval 0 OK
* @retval -1 Error
* @see nscache_replace to replace the whole context
*/
static int
nscache_set(cxobj *x,
@ -271,6 +272,29 @@ nscache_set(cxobj *x,
return retval;
}
/*! Set complete cached namespace context
* @param[in] x XML node
* @param[in] nsc Namespace context (note consumed, dont free)
* @retval 0 OK
* @retval -1 Error
* @see nscache_set set a single cache line
*/
int
nscache_replace(cxobj *x,
cvec *nsc)
{
int retval = -1;
if (x->x_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