CHanged back xvec API to use cxobj ** instead if clixon_xvec since it may be easier for the an end-user.
This commit is contained in:
parent
75b20936d3
commit
250ead517c
10 changed files with 82 additions and 70 deletions
|
|
@ -68,7 +68,6 @@ Expected: Early March 2020
|
||||||
* Added instrumentation: `xml_stats` and `xml_stats_global`.
|
* Added instrumentation: `xml_stats` and `xml_stats_global`.
|
||||||
* Added object-based `clixon_xvec` as a new programming construct for contiguous XML object vectors.
|
* Added object-based `clixon_xvec` as a new programming construct for contiguous XML object vectors.
|
||||||
* See files: `clixon_xml_vec.[ch]`
|
* See files: `clixon_xml_vec.[ch]`
|
||||||
* Plan is to replace `cxobj **` with `clixon_xvec *` going forward.
|
|
||||||
* Test framework
|
* Test framework
|
||||||
* Added `-- -S <file>` command-line to main example to be able to return any state to main example.
|
* Added `-- -S <file>` command-line to main example to be able to return any state to main example.
|
||||||
* Added `test/cicd` test scripts for running on a set of other hosts
|
* Added `test/cicd` test scripts for running on a set of other hosts
|
||||||
|
|
|
||||||
|
|
@ -11,12 +11,13 @@ mechanism.
|
||||||
|
|
||||||
See [main documentation](https://clixon-docs.readthedocs.io) and [project page](https://www.clicon.org).
|
See [main documentation](https://clixon-docs.readthedocs.io) and [project page](https://www.clicon.org).
|
||||||
|
|
||||||
|
Clixon interaction is best done posting issues, pull requests, or joining the
|
||||||
|
[slack channel](https://clixondev.slack.com).
|
||||||
|
[Slack invite](https://join.slack.com/t/clixondev/shared_invite/enQtMzI3OTM4MzA3Nzk3LTA3NWM4OWYwYWMxZDhiYTNhNjRkNjQ1NWI1Zjk5M2JjMDk4MTUzMTljYTZiYmNhODkwMDI2ZTkyNWU3ZWMyN2U).
|
||||||
|
|
||||||
Clixon is open-source and dual licensed. Either Apache License, Version 2.0 or GNU
|
Clixon is open-source and dual licensed. Either Apache License, Version 2.0 or GNU
|
||||||
General Public License Version 2; you choose.
|
General Public License Version 2; you choose.
|
||||||
|
|
||||||
See [LICENSE.md](LICENSE.md) for the license.
|
See [LICENSE.md](LICENSE.md) for the license.
|
||||||
|
|
||||||
Clixon interaction is best done posting issues, pull requests, or joining the
|
[Netgate](https://www.netgate.com/) sponsors Clixon.
|
||||||
[slack channel](https://clixondev.slack.com).
|
|
||||||
[Slack invite](https://join.slack.com/t/clixondev/shared_invite/enQtMzI3OTM4MzA3Nzk3LTA3NWM4OWYwYWMxZDhiYTNhNjRkNjQ1NWI1Zjk5M2JjMDk4MTUzMTljYTZiYmNhODkwMDI2ZTkyNWU3ZWMyN2U).
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -86,10 +86,10 @@ int api_path2xml(char *api_path, yang_stmt *yspec, cxobj *xtop,
|
||||||
cxobj **xpathp, yang_stmt **ypathp, cxobj **xerr);
|
cxobj **xpathp, yang_stmt **ypathp, cxobj **xerr);
|
||||||
int xml2api_path_1(cxobj *x, cbuf *cb);
|
int xml2api_path_1(cxobj *x, cbuf *cb);
|
||||||
#if defined(__GNUC__) && __GNUC__ >= 3
|
#if defined(__GNUC__) && __GNUC__ >= 3
|
||||||
int clixon_xml_find_api_path(cxobj *xt, yang_stmt *yt, clixon_xvec **xvec, char *format,
|
int clixon_xml_find_api_path(cxobj *xt, yang_stmt *yt, cxobj ***xvec, size_t *xlen, char *format,
|
||||||
...) __attribute__ ((format (printf, 4, 5)));;
|
...) __attribute__ ((format (printf, 5, 6)));;
|
||||||
int clixon_xml_find_instance_id(cxobj *xt, yang_stmt *yt, clixon_xvec **xvec, char *format,
|
int clixon_xml_find_instance_id(cxobj *xt, yang_stmt *yt, cxobj ***xvec, size_t *xlen, char *format,
|
||||||
...) __attribute__ ((format (printf, 4, 5)));;
|
...) __attribute__ ((format (printf, 5, 6)));;
|
||||||
#else
|
#else
|
||||||
int clixon_xml_find_api_path(cxobj *xt, yang_stmt *yt, clixon_xvec **xvec, char *format, ...);
|
int clixon_xml_find_api_path(cxobj *xt, yang_stmt *yt, clixon_xvec **xvec, char *format, ...);
|
||||||
int clixon_xml_find_instance_id(cxobj *xt, yang_stmt *yt, clixon_xvec **xvec, char *format, ...);
|
int clixon_xml_find_instance_id(cxobj *xt, yang_stmt *yt, clixon_xvec **xvec, char *format, ...);
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ clixon_xvec *clixon_xvec_dup(clixon_xvec *xv0);
|
||||||
int clixon_xvec_free(clixon_xvec *xv);
|
int clixon_xvec_free(clixon_xvec *xv);
|
||||||
int clixon_xvec_len(clixon_xvec *xv);
|
int clixon_xvec_len(clixon_xvec *xv);
|
||||||
cxobj *clixon_xvec_i(clixon_xvec *xv, int i);
|
cxobj *clixon_xvec_i(clixon_xvec *xv, int i);
|
||||||
int clixon_xvec_vec(clixon_xvec *xv, cxobj ***xvec, size_t *xlen);
|
int clixon_xvec_extract(clixon_xvec *xv, cxobj ***xvec, size_t *xlen);
|
||||||
int clixon_xvec_append(clixon_xvec *xv, cxobj *x);
|
int clixon_xvec_append(clixon_xvec *xv, cxobj *x);
|
||||||
int clixon_xvec_prepend(clixon_xvec *xv, cxobj *x);
|
int clixon_xvec_prepend(clixon_xvec *xv, cxobj *x);
|
||||||
int clixon_xvec_insert_pos(clixon_xvec *xv, cxobj *x, int i);
|
int clixon_xvec_insert_pos(clixon_xvec *xv, cxobj *x, int i);
|
||||||
|
|
|
||||||
|
|
@ -1483,22 +1483,23 @@ clixon_path_search(cxobj *xt,
|
||||||
* - Modulename not defined for top-level id.
|
* - Modulename not defined for top-level id.
|
||||||
* - Number of keys in key-value list does not match Yang list
|
* - Number of keys in key-value list does not match Yang list
|
||||||
* @code
|
* @code
|
||||||
* clixon_xvec *xvec = NULL;
|
* cxobj **vec = NULL;
|
||||||
* cxobj *x;
|
* size_t len = 0;
|
||||||
* if (clixon_xml_find_api_path(x, yspec, &xvec, "/symbol/%s", "foo") < 0)
|
* if (clixon_xml_find_api_path(x, yspec, &vec, &len, "/symbol/%s", "foo") < 0)
|
||||||
* err;
|
* err;
|
||||||
* for (i=0; i<clixon_xpath_len(xvec); i++){
|
* for (i=0; i<len; i++){
|
||||||
* x = clixon_xpath_i(xvec, i);
|
* x = vec[i];
|
||||||
* ...
|
* ...
|
||||||
* }
|
* }
|
||||||
* clixon_xvec_free(xvec);
|
* free(xvec);
|
||||||
* @endcode
|
* @endcode
|
||||||
* @see xpath_vec1
|
* @see clixon_xml_find_instance_id
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
clixon_xml_find_api_path(cxobj *xt,
|
clixon_xml_find_api_path(cxobj *xt,
|
||||||
yang_stmt *yt,
|
yang_stmt *yt,
|
||||||
clixon_xvec **xvec,
|
cxobj ***xvec,
|
||||||
|
size_t *xlen,
|
||||||
char *format,
|
char *format,
|
||||||
...)
|
...)
|
||||||
{
|
{
|
||||||
|
|
@ -1508,6 +1509,7 @@ clixon_xml_find_api_path(cxobj *xt,
|
||||||
char *api_path = NULL;
|
char *api_path = NULL;
|
||||||
clixon_path *cplist = NULL;
|
clixon_path *cplist = NULL;
|
||||||
int ret;
|
int ret;
|
||||||
|
clixon_xvec *xv = NULL;
|
||||||
|
|
||||||
va_start(ap, format);
|
va_start(ap, format);
|
||||||
len = vsnprintf(NULL, 0, format, ap);
|
len = vsnprintf(NULL, 0, format, ap);
|
||||||
|
|
@ -1535,8 +1537,17 @@ clixon_xml_find_api_path(cxobj *xt,
|
||||||
goto done;
|
goto done;
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
retval = clixon_path_search(xt, yt, cplist, xvec);
|
if ((ret = clixon_path_search(xt, yt, cplist, &xv)) < 0)
|
||||||
|
goto done;
|
||||||
|
if (ret == 0)
|
||||||
|
goto fail;
|
||||||
|
/* Convert to api xvec format */
|
||||||
|
if (clixon_xvec_extract(xv, xvec, xlen) < 0)
|
||||||
|
goto done;
|
||||||
|
retval = 1;
|
||||||
done:
|
done:
|
||||||
|
if (xv)
|
||||||
|
clixon_xvec_free(xv);
|
||||||
if (cplist)
|
if (cplist)
|
||||||
clixon_path_free(cplist);
|
clixon_path_free(cplist);
|
||||||
if (api_path)
|
if (api_path)
|
||||||
|
|
@ -1563,24 +1574,24 @@ clixon_xml_find_api_path(cxobj *xt,
|
||||||
* - Modulename not defined for top-level id.
|
* - Modulename not defined for top-level id.
|
||||||
* - Number of keys in key-value list does not match Yang list
|
* - Number of keys in key-value list does not match Yang list
|
||||||
* @code
|
* @code
|
||||||
* clixon_xvec *xvec = NULL;
|
* cxobj **vec = NULL;
|
||||||
* cxobj *x;
|
* size_t len = 0;
|
||||||
* if (clixon_xml_find_instance_id(x, &xvec, "/symbol/%s", "foo") < 0)
|
* if (clixon_xml_find_instance_id(x, yspec, &vec, &len, "/symbol/%s", "foo") < 0)
|
||||||
* goto err;
|
* goto err;
|
||||||
* for (i=0; i<clixon_xpath_len(xvec); i++){
|
* for (i=0; i<len; i++){
|
||||||
* xn = clixon_xpath_i(xvec, i);
|
* x = vec[i];
|
||||||
* ...
|
* ...
|
||||||
* }
|
* }
|
||||||
* clixon_xvec_free(xvec);
|
* clixon_xvec_free(xvec);
|
||||||
* @endcode
|
* @endcode
|
||||||
* @see xpath_vec for full XML XPaths
|
* @see clixon_xml_find_api_path for RESTCONF api-paths
|
||||||
* @see api_path_search for RESTCONF api-paths
|
|
||||||
* @see RFC7950 Sec 9.13
|
* @see RFC7950 Sec 9.13
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
clixon_xml_find_instance_id(cxobj *xt,
|
clixon_xml_find_instance_id(cxobj *xt,
|
||||||
yang_stmt *yt,
|
yang_stmt *yt,
|
||||||
clixon_xvec **xvec,
|
cxobj ***xvec,
|
||||||
|
size_t *xlen,
|
||||||
char *format,
|
char *format,
|
||||||
...)
|
...)
|
||||||
{
|
{
|
||||||
|
|
@ -1590,6 +1601,7 @@ clixon_xml_find_instance_id(cxobj *xt,
|
||||||
char *path = NULL;
|
char *path = NULL;
|
||||||
clixon_path *cplist = NULL;
|
clixon_path *cplist = NULL;
|
||||||
int ret;
|
int ret;
|
||||||
|
clixon_xvec *xv = NULL;
|
||||||
|
|
||||||
va_start(ap, format);
|
va_start(ap, format);
|
||||||
len = vsnprintf(NULL, 0, format, ap);
|
len = vsnprintf(NULL, 0, format, ap);
|
||||||
|
|
@ -1616,9 +1628,17 @@ clixon_xml_find_instance_id(cxobj *xt,
|
||||||
goto done;
|
goto done;
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
if ((retval = clixon_path_search(xt, yt, cplist, xvec)) < 0)
|
if ((ret = clixon_path_search(xt, yt, cplist, &xv)) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
if (ret == 0)
|
||||||
|
goto fail;
|
||||||
|
/* Convert to api xvec format */
|
||||||
|
if (clixon_xvec_extract(xv, xvec, xlen) < 0)
|
||||||
|
goto done;
|
||||||
|
retval = 1;
|
||||||
done:
|
done:
|
||||||
|
if (xv)
|
||||||
|
clixon_xvec_free(xv);
|
||||||
if (cplist)
|
if (cplist)
|
||||||
clixon_path_free(cplist);
|
clixon_path_free(cplist);
|
||||||
if (path)
|
if (path)
|
||||||
|
|
|
||||||
|
|
@ -1391,7 +1391,7 @@ xml_find_index_yang(cxobj *xp,
|
||||||
* ... Populate cvk with key/values eg a:5 b:6
|
* ... Populate cvk with key/values eg a:5 b:6
|
||||||
* if (clixon_xml_find_index(xp, yp, NULL, "a", ns, cvk, &xv) < 0)
|
* if (clixon_xml_find_index(xp, yp, NULL, "a", ns, cvk, &xv) < 0)
|
||||||
* err;
|
* err;
|
||||||
* for (i=0; i<clixon_xpath_len(xvec); i++){
|
* for (i=0; i<clixon_xvec_len(xvec); i++){
|
||||||
* x = clixon_xpath_i(xvec, i);
|
* x = clixon_xpath_i(xvec, i);
|
||||||
* ...
|
* ...
|
||||||
* }
|
* }
|
||||||
|
|
|
||||||
|
|
@ -198,33 +198,24 @@ clixon_xvec_i(clixon_xvec *xv,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Return whole XML object vector
|
/*! Return whole XML object vector and null it in original xvec, essentially moving it
|
||||||
*
|
*
|
||||||
* Used in glue code between clixon_xvec code and cxobj **, size_t code, may go AWAY?
|
* Used in glue code between clixon_xvec code and cxobj **, size_t code, may go AWAY?
|
||||||
* @param[in] xv XML tree vector
|
* @param[in] xv XML tree vector
|
||||||
* @param[out] xvec XML object vector
|
* @param[out] xvec XML object vector
|
||||||
* @retval 0
|
* @retval 0
|
||||||
* @retval -1
|
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
clixon_xvec_vec(clixon_xvec *xv,
|
clixon_xvec_extract(clixon_xvec *xv,
|
||||||
cxobj ***xvec,
|
cxobj ***xvec,
|
||||||
size_t *xlen)
|
size_t *xlen)
|
||||||
{
|
{
|
||||||
size_t sz;
|
*xvec = xv->xv_vec;
|
||||||
|
*xlen = xv->xv_len;
|
||||||
if (xv->xv_len == 0){
|
if (xv->xv_vec != NULL){
|
||||||
*xvec = NULL;
|
xv->xv_len = 0;
|
||||||
*xlen = 0;
|
xv->xv_max = 0;
|
||||||
}
|
xv->xv_vec = NULL;
|
||||||
else {
|
|
||||||
sz = xv->xv_len * sizeof(cxobj*);
|
|
||||||
if ((*xvec = malloc(sz)) == NULL){
|
|
||||||
clicon_err(OE_UNIX, errno, "memcpy");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
memcpy(*xvec, xv->xv_vec, sz);
|
|
||||||
*xlen = xv->xv_len;
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -333,7 +333,7 @@ xpath_optimize_check(xpath_tree *xs,
|
||||||
if ((ret = xpath_list_optimize_fn(xs, xv, &xvec)) < 0)
|
if ((ret = xpath_list_optimize_fn(xs, xv, &xvec)) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
if (ret == 1){
|
if (ret == 1){
|
||||||
if (clixon_xvec_vec(xvec, xvec0, xlen0) < 0)
|
if (clixon_xvec_extract(xvec, xvec0, xlen0) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
clixon_xvec_free(xvec);
|
clixon_xvec_free(xvec);
|
||||||
_optimize_hits++;
|
_optimize_hits++;
|
||||||
|
|
|
||||||
|
|
@ -109,15 +109,15 @@ trigger_rpc(clicon_handle h, /* Clicon handle */
|
||||||
void *arg, /* client_entry */
|
void *arg, /* client_entry */
|
||||||
void *regarg) /* Argument given at register */
|
void *regarg) /* Argument given at register */
|
||||||
{
|
{
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
cxobj *xret = NULL;
|
cxobj *xret = NULL;
|
||||||
cxobj *xc = NULL;
|
cxobj *xc = NULL;
|
||||||
cxobj *x = NULL;
|
cxobj *x = NULL;
|
||||||
char *k;
|
char *k;
|
||||||
char *val;
|
char *val;
|
||||||
cvec *cvk = NULL;
|
cvec *cvk = NULL;
|
||||||
cg_var *cv;
|
cg_var *cv;
|
||||||
clixon_xvec *xvec = NULL;
|
clixon_xvec *xv = NULL;
|
||||||
|
|
||||||
if (xmldb_get(h, "running", NULL, "/c", &xret) < 0)
|
if (xmldb_get(h, "running", NULL, "/c", &xret) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
@ -157,10 +157,10 @@ trigger_rpc(clicon_handle h, /* Clicon handle */
|
||||||
cv_name_set(cv, "k");
|
cv_name_set(cv, "k");
|
||||||
cv_string_set(cv, "5");
|
cv_string_set(cv, "5");
|
||||||
/* Use form 2c use spec of xc + name */
|
/* Use form 2c use spec of xc + name */
|
||||||
if (clixon_xml_find_index(xc, NULL, NULL, "y3", cvk, &xvec) < 0)
|
if (clixon_xml_find_index(xc, NULL, NULL, "y3", cvk, &xv) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if (clixon_xvec_len(xvec))
|
if (clixon_xvec_len(xv))
|
||||||
val = xml_find_body(clixon_xvec_i(xvec,0), "val");
|
val = xml_find_body(clixon_xvec_i(xv,0), "val");
|
||||||
else
|
else
|
||||||
val = NULL;
|
val = NULL;
|
||||||
clicon_debug(1, "%s Method 3: val:%s", __FUNCTION__, val?val:"null");
|
clicon_debug(1, "%s Method 3: val:%s", __FUNCTION__, val?val:"null");
|
||||||
|
|
@ -173,8 +173,8 @@ trigger_rpc(clicon_handle h, /* Clicon handle */
|
||||||
cvec_free(cvk);
|
cvec_free(cvk);
|
||||||
if (xret)
|
if (xret)
|
||||||
xml_free(xret);
|
xml_free(xret);
|
||||||
if (xvec)
|
if (xv)
|
||||||
free(xvec);
|
clixon_xvec_free(xv);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,8 @@ main(int argc,
|
||||||
int i;
|
int i;
|
||||||
cxobj *x = NULL;
|
cxobj *x = NULL;
|
||||||
cxobj *xc;
|
cxobj *xc;
|
||||||
clixon_xvec *xvec = NULL;
|
cxobj **xvec = NULL;
|
||||||
|
size_t xlen = 0;
|
||||||
int c;
|
int c;
|
||||||
int len;
|
int len;
|
||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
|
|
@ -247,11 +248,11 @@ main(int argc,
|
||||||
xvec = NULL;
|
xvec = NULL;
|
||||||
for (i=0; i<nr; i++){
|
for (i=0; i<nr; i++){
|
||||||
if (api_path_p){
|
if (api_path_p){
|
||||||
if ((ret = clixon_xml_find_api_path(x, yspec, &xvec, "%s", path)) < 0)
|
if ((ret = clixon_xml_find_api_path(x, yspec, &xvec, &xlen, "%s", path)) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
if ((ret = clixon_xml_find_instance_id(x, yspec, &xvec, "%s", path)) < 0)
|
if ((ret = clixon_xml_find_instance_id(x, yspec, &xvec, &xlen, "%s", path)) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
if (ret == 0){
|
if (ret == 0){
|
||||||
|
|
@ -260,8 +261,8 @@ main(int argc,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Print results */
|
/* Print results */
|
||||||
for (i=0; i<clixon_xvec_len(xvec); i++){
|
for (i = 0; i < xlen; i++){
|
||||||
xc = clixon_xvec_i(xvec,i);
|
xc = xvec[i];
|
||||||
fprintf(stdout, "%d: ", i);
|
fprintf(stdout, "%d: ", i);
|
||||||
clicon_xml2file(stdout, xc, 0, 0);
|
clicon_xml2file(stdout, xc, 0, 0);
|
||||||
fprintf(stdout, "\n");
|
fprintf(stdout, "\n");
|
||||||
|
|
@ -274,7 +275,7 @@ main(int argc,
|
||||||
if (cb)
|
if (cb)
|
||||||
cbuf_free(cb);
|
cbuf_free(cb);
|
||||||
if (xvec)
|
if (xvec)
|
||||||
clixon_xvec_free(xvec);
|
free(xvec);
|
||||||
if (buf)
|
if (buf)
|
||||||
free(buf);
|
free(buf);
|
||||||
if (x)
|
if (x)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue