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 object-based `clixon_xvec` as a new programming construct for contiguous XML object vectors.
|
||||
* See files: `clixon_xml_vec.[ch]`
|
||||
* Plan is to replace `cxobj **` with `clixon_xvec *` going forward.
|
||||
* Test framework
|
||||
* 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
|
||||
|
|
|
|||
|
|
@ -11,12 +11,13 @@ mechanism.
|
|||
|
||||
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
|
||||
General Public License Version 2; you choose.
|
||||
|
||||
See [LICENSE.md](LICENSE.md) for the license.
|
||||
|
||||
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).
|
||||
|
||||
[Netgate](https://www.netgate.com/) sponsors Clixon.
|
||||
|
|
|
|||
|
|
@ -86,10 +86,10 @@ int api_path2xml(char *api_path, yang_stmt *yspec, cxobj *xtop,
|
|||
cxobj **xpathp, yang_stmt **ypathp, cxobj **xerr);
|
||||
int xml2api_path_1(cxobj *x, cbuf *cb);
|
||||
#if defined(__GNUC__) && __GNUC__ >= 3
|
||||
int clixon_xml_find_api_path(cxobj *xt, yang_stmt *yt, clixon_xvec **xvec, char *format,
|
||||
...) __attribute__ ((format (printf, 4, 5)));;
|
||||
int clixon_xml_find_instance_id(cxobj *xt, yang_stmt *yt, clixon_xvec **xvec, char *format,
|
||||
...) __attribute__ ((format (printf, 4, 5)));;
|
||||
int clixon_xml_find_api_path(cxobj *xt, yang_stmt *yt, cxobj ***xvec, size_t *xlen, char *format,
|
||||
...) __attribute__ ((format (printf, 5, 6)));;
|
||||
int clixon_xml_find_instance_id(cxobj *xt, yang_stmt *yt, cxobj ***xvec, size_t *xlen, char *format,
|
||||
...) __attribute__ ((format (printf, 5, 6)));;
|
||||
#else
|
||||
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, ...);
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ clixon_xvec *clixon_xvec_dup(clixon_xvec *xv0);
|
|||
int clixon_xvec_free(clixon_xvec *xv);
|
||||
int clixon_xvec_len(clixon_xvec *xv);
|
||||
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_prepend(clixon_xvec *xv, cxobj *x);
|
||||
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.
|
||||
* - Number of keys in key-value list does not match Yang list
|
||||
* @code
|
||||
* clixon_xvec *xvec = NULL;
|
||||
* cxobj *x;
|
||||
* if (clixon_xml_find_api_path(x, yspec, &xvec, "/symbol/%s", "foo") < 0)
|
||||
* cxobj **vec = NULL;
|
||||
* size_t len = 0;
|
||||
* if (clixon_xml_find_api_path(x, yspec, &vec, &len, "/symbol/%s", "foo") < 0)
|
||||
* err;
|
||||
* for (i=0; i<clixon_xpath_len(xvec); i++){
|
||||
* x = clixon_xpath_i(xvec, i);
|
||||
* for (i=0; i<len; i++){
|
||||
* x = vec[i];
|
||||
* ...
|
||||
* }
|
||||
* clixon_xvec_free(xvec);
|
||||
* free(xvec);
|
||||
* @endcode
|
||||
* @see xpath_vec1
|
||||
* @see clixon_xml_find_instance_id
|
||||
*/
|
||||
int
|
||||
clixon_xml_find_api_path(cxobj *xt,
|
||||
yang_stmt *yt,
|
||||
clixon_xvec **xvec,
|
||||
cxobj ***xvec,
|
||||
size_t *xlen,
|
||||
char *format,
|
||||
...)
|
||||
{
|
||||
|
|
@ -1508,6 +1509,7 @@ clixon_xml_find_api_path(cxobj *xt,
|
|||
char *api_path = NULL;
|
||||
clixon_path *cplist = NULL;
|
||||
int ret;
|
||||
clixon_xvec *xv = NULL;
|
||||
|
||||
va_start(ap, format);
|
||||
len = vsnprintf(NULL, 0, format, ap);
|
||||
|
|
@ -1535,8 +1537,17 @@ clixon_xml_find_api_path(cxobj *xt,
|
|||
goto done;
|
||||
if (ret == 0)
|
||||
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:
|
||||
if (xv)
|
||||
clixon_xvec_free(xv);
|
||||
if (cplist)
|
||||
clixon_path_free(cplist);
|
||||
if (api_path)
|
||||
|
|
@ -1563,24 +1574,24 @@ clixon_xml_find_api_path(cxobj *xt,
|
|||
* - Modulename not defined for top-level id.
|
||||
* - Number of keys in key-value list does not match Yang list
|
||||
* @code
|
||||
* clixon_xvec *xvec = NULL;
|
||||
* cxobj *x;
|
||||
* if (clixon_xml_find_instance_id(x, &xvec, "/symbol/%s", "foo") < 0)
|
||||
* cxobj **vec = NULL;
|
||||
* size_t len = 0;
|
||||
* if (clixon_xml_find_instance_id(x, yspec, &vec, &len, "/symbol/%s", "foo") < 0)
|
||||
* goto err;
|
||||
* for (i=0; i<clixon_xpath_len(xvec); i++){
|
||||
* xn = clixon_xpath_i(xvec, i);
|
||||
* for (i=0; i<len; i++){
|
||||
* x = vec[i];
|
||||
* ...
|
||||
* }
|
||||
* clixon_xvec_free(xvec);
|
||||
* @endcode
|
||||
* @see xpath_vec for full XML XPaths
|
||||
* @see api_path_search for RESTCONF api-paths
|
||||
* @see clixon_xml_find_api_path for RESTCONF api-paths
|
||||
* @see RFC7950 Sec 9.13
|
||||
*/
|
||||
int
|
||||
clixon_xml_find_instance_id(cxobj *xt,
|
||||
yang_stmt *yt,
|
||||
clixon_xvec **xvec,
|
||||
cxobj ***xvec,
|
||||
size_t *xlen,
|
||||
char *format,
|
||||
...)
|
||||
{
|
||||
|
|
@ -1590,6 +1601,7 @@ clixon_xml_find_instance_id(cxobj *xt,
|
|||
char *path = NULL;
|
||||
clixon_path *cplist = NULL;
|
||||
int ret;
|
||||
clixon_xvec *xv = NULL;
|
||||
|
||||
va_start(ap, format);
|
||||
len = vsnprintf(NULL, 0, format, ap);
|
||||
|
|
@ -1616,9 +1628,17 @@ clixon_xml_find_instance_id(cxobj *xt,
|
|||
goto done;
|
||||
if (ret == 0)
|
||||
goto fail;
|
||||
if ((retval = clixon_path_search(xt, yt, cplist, xvec)) < 0)
|
||||
goto done;
|
||||
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:
|
||||
if (xv)
|
||||
clixon_xvec_free(xv);
|
||||
if (cplist)
|
||||
clixon_path_free(cplist);
|
||||
if (path)
|
||||
|
|
|
|||
|
|
@ -1391,7 +1391,7 @@ xml_find_index_yang(cxobj *xp,
|
|||
* ... Populate cvk with key/values eg a:5 b:6
|
||||
* if (clixon_xml_find_index(xp, yp, NULL, "a", ns, cvk, &xv) < 0)
|
||||
* 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);
|
||||
* ...
|
||||
* }
|
||||
|
|
|
|||
|
|
@ -198,33 +198,24 @@ clixon_xvec_i(clixon_xvec *xv,
|
|||
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?
|
||||
* @param[in] xv XML tree vector
|
||||
* @param[out] xvec XML object vector
|
||||
* @retval 0
|
||||
* @retval -1
|
||||
*/
|
||||
int
|
||||
clixon_xvec_vec(clixon_xvec *xv,
|
||||
cxobj ***xvec,
|
||||
size_t *xlen)
|
||||
clixon_xvec_extract(clixon_xvec *xv,
|
||||
cxobj ***xvec,
|
||||
size_t *xlen)
|
||||
{
|
||||
size_t sz;
|
||||
|
||||
if (xv->xv_len == 0){
|
||||
*xvec = NULL;
|
||||
*xlen = 0;
|
||||
}
|
||||
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;
|
||||
*xvec = xv->xv_vec;
|
||||
*xlen = xv->xv_len;
|
||||
if (xv->xv_vec != NULL){
|
||||
xv->xv_len = 0;
|
||||
xv->xv_max = 0;
|
||||
xv->xv_vec = NULL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -333,7 +333,7 @@ xpath_optimize_check(xpath_tree *xs,
|
|||
if ((ret = xpath_list_optimize_fn(xs, xv, &xvec)) < 0)
|
||||
return -1;
|
||||
if (ret == 1){
|
||||
if (clixon_xvec_vec(xvec, xvec0, xlen0) < 0)
|
||||
if (clixon_xvec_extract(xvec, xvec0, xlen0) < 0)
|
||||
return -1;
|
||||
clixon_xvec_free(xvec);
|
||||
_optimize_hits++;
|
||||
|
|
|
|||
|
|
@ -109,15 +109,15 @@ trigger_rpc(clicon_handle h, /* Clicon handle */
|
|||
void *arg, /* client_entry */
|
||||
void *regarg) /* Argument given at register */
|
||||
{
|
||||
int retval = -1;
|
||||
cxobj *xret = NULL;
|
||||
cxobj *xc = NULL;
|
||||
cxobj *x = NULL;
|
||||
char *k;
|
||||
char *val;
|
||||
cvec *cvk = NULL;
|
||||
cg_var *cv;
|
||||
clixon_xvec *xvec = NULL;
|
||||
int retval = -1;
|
||||
cxobj *xret = NULL;
|
||||
cxobj *xc = NULL;
|
||||
cxobj *x = NULL;
|
||||
char *k;
|
||||
char *val;
|
||||
cvec *cvk = NULL;
|
||||
cg_var *cv;
|
||||
clixon_xvec *xv = NULL;
|
||||
|
||||
if (xmldb_get(h, "running", NULL, "/c", &xret) < 0)
|
||||
goto done;
|
||||
|
|
@ -157,10 +157,10 @@ trigger_rpc(clicon_handle h, /* Clicon handle */
|
|||
cv_name_set(cv, "k");
|
||||
cv_string_set(cv, "5");
|
||||
/* 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;
|
||||
if (clixon_xvec_len(xvec))
|
||||
val = xml_find_body(clixon_xvec_i(xvec,0), "val");
|
||||
if (clixon_xvec_len(xv))
|
||||
val = xml_find_body(clixon_xvec_i(xv,0), "val");
|
||||
else
|
||||
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);
|
||||
if (xret)
|
||||
xml_free(xret);
|
||||
if (xvec)
|
||||
free(xvec);
|
||||
if (xv)
|
||||
clixon_xvec_free(xv);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -91,7 +91,8 @@ main(int argc,
|
|||
int i;
|
||||
cxobj *x = NULL;
|
||||
cxobj *xc;
|
||||
clixon_xvec *xvec = NULL;
|
||||
cxobj **xvec = NULL;
|
||||
size_t xlen = 0;
|
||||
int c;
|
||||
int len;
|
||||
char *buf = NULL;
|
||||
|
|
@ -247,11 +248,11 @@ main(int argc,
|
|||
xvec = NULL;
|
||||
for (i=0; i<nr; i++){
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
if (ret == 0){
|
||||
|
|
@ -260,8 +261,8 @@ main(int argc,
|
|||
}
|
||||
}
|
||||
/* Print results */
|
||||
for (i=0; i<clixon_xvec_len(xvec); i++){
|
||||
xc = clixon_xvec_i(xvec,i);
|
||||
for (i = 0; i < xlen; i++){
|
||||
xc = xvec[i];
|
||||
fprintf(stdout, "%d: ", i);
|
||||
clicon_xml2file(stdout, xc, 0, 0);
|
||||
fprintf(stdout, "\n");
|
||||
|
|
@ -274,7 +275,7 @@ main(int argc,
|
|||
if (cb)
|
||||
cbuf_free(cb);
|
||||
if (xvec)
|
||||
clixon_xvec_free(xvec);
|
||||
free(xvec);
|
||||
if (buf)
|
||||
free(buf);
|
||||
if (x)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue