Pagination draft

This commit is contained in:
Olof hagsand 2020-11-05 15:26:11 +01:00
parent ab0bc0ea4b
commit 78f5a6983c
15 changed files with 1206 additions and 86 deletions

View file

@ -1527,7 +1527,7 @@ netconf_module_load(clicon_handle h)
xml_bind_netconf_message_id_optional(1);
#endif
/* Load restconf collection */
if (yang_spec_parse_module(h, "ietf-netconf-collection", NULL, yspec)< 0)
if (yang_spec_parse_module(h, "ietf-netconf-list-pagination", NULL, yspec)< 0)
goto done;
retval = 0;

View file

@ -196,7 +196,7 @@ instance_id_parse(char *path,
return retval;
}
static int
int
clixon_path_free(clixon_path *cplist)
{
clixon_path *cp;
@ -1765,7 +1765,7 @@ clixon_xml_find_instance_id(cxobj *xt,
* example.
* @param[in] yt Yang statement of top symbol (can be yang-spec if top-level)
* @param[out] nsctx Namespace context (should be created on entry)
* @param[in] format Format string for api-path syntax
* @param[in] format Format string for xpath syntax
* @retval -1 Error
* @retval 0 Non-fatal failure, yang bind failures, etc,
* @retval 1 OK with found xml nodes in xvec (if any)
@ -1850,3 +1850,68 @@ clixon_instance_id_bind(yang_stmt *yt,
retval = 0;
goto done;
}
/*! Given (instance-id) path and YANG, parse path, resolve YANG and return parse-tree
*
* Instance-identifier is a subset of XML XPaths and defined in Yang, used in NACM for
* example.
* @param[in] yt Yang statement of top symbol (can be yang-spec if top-level)
* @param[out] cplistp Path parse-tree
* @param[in] format Format string for xpath syntax
* @retval -1 Error
* @retval 0 Non-fatal failure, yang bind failures, etc,
* @retval 1 OK with found xml nodes in xvec (if any)
*/
int
clixon_instance_id_parse(yang_stmt *yt,
clixon_path **cplistp,
const char *format,
...)
{
int retval = -1;
va_list ap;
size_t len;
char *path = NULL;
clixon_path *cplist = NULL;
int ret;
va_start(ap, format);
len = vsnprintf(NULL, 0, format, ap);
va_end(ap);
/* allocate a path string exactly fitting the length */
if ((path = malloc(len+1)) == NULL){
clicon_err(OE_UNIX, errno, "malloc");
goto done;
}
/* second round: actually compute api-path string content */
va_start(ap, format);
if (vsnprintf(path, len+1, format, ap) < 0){
clicon_err(OE_UNIX, errno, "vsnprintf");
va_end(ap);
goto done;
}
va_end(ap);
if (instance_id_parse(path, &cplist) < 0)
goto done;
if (clicon_debug_get())
clixon_path_print(stderr, cplist);
/* Resolve module:name to pointer to yang-stmt, fail if not successful */
if ((ret = instance_id_resolve(cplist, yt)) < 0)
goto done;
if (ret == 0)
goto fail;
if (cplistp){
*cplistp = cplist;
cplist = NULL;
}
retval = 1;
done:
if (cplist)
clixon_path_free(cplist);
if (path)
free(path);
return retval;
fail:
retval = 0;
goto done;
}

View file

@ -1028,13 +1028,14 @@ xml_yang_validate_add(clicon_handle h,
cxobj *xt,
cxobj **xret)
{
int retval = -1;
cg_var *cv = NULL;
char *reason = NULL;
yang_stmt *yt; /* yang spec of xt going in */
char *body;
int ret;
cxobj *x;
int retval = -1;
cg_var *cv = NULL;
char *reason = NULL;
yang_stmt *yt; /* yang spec of xt going in */
char *body;
int ret;
cxobj *x;
cg_var *cv0;
enum cv_type cvtype;
/* if not given by argument (overide) use default link
@ -1054,7 +1055,9 @@ xml_yang_validate_add(clicon_handle h,
/* fall thru */
case Y_LEAF_LIST:
/* validate value against ranges, etc */
if ((cv = cv_dup(yang_cv_get(yt))) == NULL){
if ((cv0 = yang_cv_get(yt)) == NULL)
break;
if ((cv = cv_dup(cv0)) == NULL){
clicon_err(OE_UNIX, errno, "cv_dup");
goto done;
}

View file

@ -1834,15 +1834,13 @@ yang_deviation(yang_stmt *ys,
*/
static int
ys_populate_leaf(clicon_handle h,
yang_stmt *ys)
yang_stmt *ys)
{
int retval = -1;
cg_var *cv = NULL;
yang_stmt *yparent;
yang_stmt *ydef;
enum cv_type cvtype = CGV_ERR;
int cvret;
int ret;
char *reason = NULL;
yang_stmt *yrestype; /* resolved type */
char *restype; /* resolved type */
@ -1851,7 +1849,6 @@ ys_populate_leaf(clicon_handle h,
int options = 0x0;
yang_stmt *ytypedef; /* where type is define */
yparent = ys->ys_parent; /* Find parent: list/container */
/* 1. Find type specification and set cv type accordingly */
if (yang_type_get(ys, &origtype, &yrestype, &options, NULL, NULL, NULL, &fraction_digits) < 0)
goto done;