From 250ead517c6c315566464bab2bebc2c749a16be8 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Mon, 2 Mar 2020 10:59:46 +0100 Subject: [PATCH] CHanged back xvec API to use cxobj ** instead if clixon_xvec since it may be easier for the an end-user. --- CHANGELOG.md | 1 - README.md | 9 ++--- lib/clixon/clixon_path.h | 8 ++--- lib/clixon/clixon_xml_vec.h | 2 +- lib/src/clixon_path.c | 58 ++++++++++++++++++++++----------- lib/src/clixon_xml_sort.c | 2 +- lib/src/clixon_xml_vec.c | 29 ++++++----------- lib/src/clixon_xpath_optimize.c | 2 +- test/test_api.sh | 28 ++++++++-------- util/clixon_util_path.c | 13 ++++---- 10 files changed, 82 insertions(+), 70 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 93ec183f..8c28e602 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 ` 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 diff --git a/README.md b/README.md index fbdf47c9..44fe2550 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/lib/clixon/clixon_path.h b/lib/clixon/clixon_path.h index 496e4a12..8d725314 100644 --- a/lib/clixon/clixon_path.h +++ b/lib/clixon/clixon_path.h @@ -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, ...); diff --git a/lib/clixon/clixon_xml_vec.h b/lib/clixon/clixon_xml_vec.h index 4b6d25d4..043b6bb1 100644 --- a/lib/clixon/clixon_xml_vec.h +++ b/lib/clixon/clixon_xml_vec.h @@ -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); diff --git a/lib/src/clixon_path.c b/lib/src/clixon_path.c index 65bf1412..6fb4d635 100644 --- a/lib/src/clixon_path.c +++ b/lib/src/clixon_path.c @@ -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; ixv_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; } diff --git a/lib/src/clixon_xpath_optimize.c b/lib/src/clixon_xpath_optimize.c index 85dbb543..d5231e9e 100644 --- a/lib/src/clixon_xpath_optimize.c +++ b/lib/src/clixon_xpath_optimize.c @@ -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++; diff --git a/test/test_api.sh b/test/test_api.sh index 762bb9ba..066f0437 100755 --- a/test/test_api.sh +++ b/test/test_api.sh @@ -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; } diff --git a/util/clixon_util_path.c b/util/clixon_util_path.c index 60da8484..730185cc 100644 --- a/util/clixon_util_path.c +++ b/util/clixon_util_path.c @@ -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