Added "canonical" global namespace context: nsctx_global
This commit is contained in:
parent
06c2793e79
commit
52629d7b35
11 changed files with 149 additions and 14 deletions
|
|
@ -75,6 +75,8 @@
|
|||
|
||||
/*! Get YANG specification for application
|
||||
* Must use hash functions directly since they are not strings.
|
||||
* @param[in] h Clicon handle
|
||||
* @retval yspec Yang spec
|
||||
*/
|
||||
yang_stmt *
|
||||
clicon_dbspec_yang(clicon_handle h)
|
||||
|
|
@ -90,6 +92,8 @@ clicon_dbspec_yang(clicon_handle h)
|
|||
|
||||
/*! Set yang specification for application
|
||||
* ys must be a malloced pointer
|
||||
* @param[in] h Clicon handle
|
||||
* @param[in] yspec Yang spec
|
||||
*/
|
||||
int
|
||||
clicon_dbspec_yang_set(clicon_handle h,
|
||||
|
|
@ -105,6 +109,42 @@ clicon_dbspec_yang_set(clicon_handle h,
|
|||
return 0;
|
||||
}
|
||||
|
||||
/*! Get Global "canonical" namespace context
|
||||
* Canonical: use prefix and namespace specified in the yang modules.
|
||||
* @param[in] h Clicon handle
|
||||
* @retval nsctx Namespace context (malloced)
|
||||
*/
|
||||
cvec *
|
||||
clicon_nsctx_global_get(clicon_handle h)
|
||||
{
|
||||
clicon_hash_t *cdat = clicon_data(h);
|
||||
size_t len;
|
||||
void *p;
|
||||
|
||||
if ((p = clicon_hash_value(cdat, "nsctx_global", &len)) != NULL)
|
||||
return *(cvec **)p;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*! Set global "canonical" namespace context
|
||||
* Canonical: use prefix and namespace specified in the yang modules.
|
||||
* @param[in] h Clicon handle
|
||||
* @param[in] nsctx Namespace context (malloced)
|
||||
*/
|
||||
int
|
||||
clicon_nsctx_global_set(clicon_handle h,
|
||||
cvec *nsctx)
|
||||
{
|
||||
clicon_hash_t *cdat = clicon_data(h);
|
||||
|
||||
/* It is the pointer to cvec that should be copied by hash,
|
||||
so we send a ptr to the ptr to indicate what to copy.
|
||||
*/
|
||||
if (clicon_hash_add(cdat, "nsctx_global", &nsctx, sizeof(nsctx)) == NULL)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*! Get NACM (rfc 8341) XML parse tree if external not in std xml config
|
||||
* @param[in] h Clicon handle
|
||||
* @retval xn XML NACM tree, or NULL
|
||||
|
|
|
|||
|
|
@ -182,7 +182,6 @@ xml_nsctx_add(cvec *cvv,
|
|||
return retval;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
xml_nsctx_node1(cxobj *xn,
|
||||
cvec *nsc)
|
||||
|
|
@ -268,10 +267,10 @@ xml_nsctx_node(cxobj *xn,
|
|||
return retval;
|
||||
}
|
||||
|
||||
/*! Create and initialize XML namespace from Yang node
|
||||
/*! Create and initialize XML namespace context from Yang node
|
||||
* Primary use is Yang path statements, eg leafrefs and others
|
||||
* Fully explore all prefix:namespace pairs from context of one node
|
||||
* @param[in] xn XML node
|
||||
* @param[in] yn Yang statement in module tree (or module itself)
|
||||
* @param[out] ncp XML namespace context
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
|
|
@ -354,3 +353,44 @@ xml_nsctx_yang(yang_stmt *yn,
|
|||
return retval;
|
||||
}
|
||||
|
||||
/*! Create and initialize XML namespace context from Yang spec
|
||||
*
|
||||
* That is, create a "canonical" XML namespace mapping from all loaded yang
|
||||
* modules which are children of the yang specification.
|
||||
* ALso add netconf base namespace: nc , urn:ietf:params:xml:ns:netconf:base:1.0
|
||||
* Fully explore all prefix:namespace pairs of all yang modules
|
||||
* @param[in] yspec Yang spec
|
||||
* @param[out] ncp XML namespace context
|
||||
*/
|
||||
int
|
||||
xml_nsctx_yangspec(yang_stmt *yspec,
|
||||
cvec **ncp)
|
||||
{
|
||||
int retval = -1;
|
||||
cvec *nc = NULL;
|
||||
yang_stmt *ymod = NULL;
|
||||
yang_stmt *yprefix;
|
||||
yang_stmt *ynamespace;
|
||||
|
||||
if ((nc = cvec_new(0)) == NULL){
|
||||
clicon_err(OE_XML, errno, "cvec_new");
|
||||
goto done;
|
||||
}
|
||||
ymod = NULL;
|
||||
while ((ymod = yn_each(yspec, ymod)) != NULL){
|
||||
if (yang_keyword_get(ymod) != Y_MODULE)
|
||||
continue;
|
||||
if ((yprefix = yang_find(ymod, Y_PREFIX, NULL)) == NULL)
|
||||
continue;
|
||||
if ((ynamespace = yang_find(ymod, Y_NAMESPACE, NULL)) == NULL)
|
||||
continue;
|
||||
if (xml_nsctx_add(nc, yang_argument_get(yprefix), yang_argument_get(ynamespace)) < 0)
|
||||
goto done;
|
||||
}
|
||||
if (xml_nsctx_add(nc, NETCONF_BASE_PREFIX, NETCONF_BASE_NAMESPACE) < 0)
|
||||
goto done;
|
||||
*ncp = nc;
|
||||
retval = 0;
|
||||
done:
|
||||
return retval;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -766,7 +766,7 @@ yang_find_myprefix(yang_stmt *ys)
|
|||
}
|
||||
if ((yprefix = yang_find(ymod, Y_PREFIX, NULL)) == NULL)
|
||||
goto done;
|
||||
prefix = yprefix->ys_argument;
|
||||
prefix = yang_argument_get(yprefix);
|
||||
done:
|
||||
return prefix;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue