Length of xml vector in many structs changed from to since it is a vector size, not byte size. This includes transaction_data_t

This commit is contained in:
Olof hagsand 2020-04-21 10:16:55 +02:00
parent 5be5b02a84
commit 04017c97ba
23 changed files with 57 additions and 54 deletions

View file

@ -35,6 +35,7 @@ Expected: May 2020
### C-API changes on existing features (you may need to change your plugin C-code) ### C-API changes on existing features (you may need to change your plugin C-code)
* Length of xml vector in many structs changed from `size_t` to `int`since it is a vector size, not byte size. This includes `transaction_data_t`
* `xml_merge()` changed to use 3-value return: 1:OK, 0:Yang failed, -1: Error * `xml_merge()` changed to use 3-value return: 1:OK, 0:Yang failed, -1: Error
* `clixon_netconf_error(category, xerr, msg, arg)` removed first argument -> `clixon_netconf_error(xerr, msg, arg)` * `clixon_netconf_error(category, xerr, msg, arg)` removed first argument -> `clixon_netconf_error(xerr, msg, arg)`
* CLI * CLI

View file

@ -56,12 +56,12 @@ typedef struct {
cxobj *td_src; /* Source database xml tree */ cxobj *td_src; /* Source database xml tree */
cxobj *td_target; /* Target database xml tree */ cxobj *td_target; /* Target database xml tree */
cxobj **td_dvec; /* Delete xml vector */ cxobj **td_dvec; /* Delete xml vector */
size_t td_dlen; /* Delete xml vector length */ int td_dlen; /* Delete xml vector length */
cxobj **td_avec; /* Add xml vector */ cxobj **td_avec; /* Add xml vector */
size_t td_alen; /* Add xml vector length */ int td_alen; /* Add xml vector length */
cxobj **td_scvec; /* Source changed xml vector */ cxobj **td_scvec; /* Source changed xml vector */
cxobj **td_tcvec; /* Target changed xml vector */ cxobj **td_tcvec; /* Target changed xml vector */
size_t td_clen; /* Changed xml vector length */ int td_clen; /* Changed xml vector length */
} transaction_data_t; } transaction_data_t;
/* /*

View file

@ -135,7 +135,7 @@ main_commit(clicon_handle h,
cxobj *target = transaction_target(td); /* wanted XML tree */ cxobj *target = transaction_target(td); /* wanted XML tree */
cxobj **vec = NULL; cxobj **vec = NULL;
int i; int i;
size_t len; int len;
cvec *nsc = NULL; cvec *nsc = NULL;
if (_transaction_log) if (_transaction_log)

View file

@ -85,13 +85,13 @@ 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, cxobj ***xvec, size_t *xlen, char *format, int clixon_xml_find_api_path(cxobj *xt, yang_stmt *yt, cxobj ***xvec, int *xlen, char *format,
...) __attribute__ ((format (printf, 5, 6)));; ...) __attribute__ ((format (printf, 5, 6)));;
int clixon_xml_find_instance_id(cxobj *xt, yang_stmt *yt, cxobj ***xvec, size_t *xlen, char *format, int clixon_xml_find_instance_id(cxobj *xt, yang_stmt *yt, cxobj ***xvec, int *xlen, char *format,
...) __attribute__ ((format (printf, 5, 6)));; ...) __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, cxobj ***xvec, int *xlen, 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, cxobj ***xvec, int *xlen, char *format, ...);
#endif #endif
#endif /* _CLIXON_PATH_H_ */ #endif /* _CLIXON_PATH_H_ */

View file

@ -226,9 +226,9 @@ int xml_copy_one(cxobj *xn0, cxobj *xn1);
int xml_copy(cxobj *x0, cxobj *x1); int xml_copy(cxobj *x0, cxobj *x1);
cxobj *xml_dup(cxobj *x0); cxobj *xml_dup(cxobj *x0);
int cxvec_dup(cxobj **vec0, size_t len0, cxobj ***vec1, size_t *len1); int cxvec_dup(cxobj **vec0, int len0, cxobj ***vec1, int *len1);
int cxvec_append(cxobj *x, cxobj ***vec, size_t *len); int cxvec_append(cxobj *x, cxobj ***vec, int *len);
int cxvec_prepend(cxobj *x, cxobj ***vec, size_t *len); int cxvec_prepend(cxobj *x, cxobj ***vec, int *len);
int xml_apply(cxobj *xn, enum cxobj_type type, xml_applyfn_t fn, void *arg); int xml_apply(cxobj *xn, enum cxobj_type type, xml_applyfn_t fn, void *arg);
int xml_apply0(cxobj *xn, enum cxobj_type type, xml_applyfn_t fn, void *arg); int xml_apply0(cxobj *xn, enum cxobj_type type, xml_applyfn_t fn, void *arg);
int xml_apply_ancestor(cxobj *xn, xml_applyfn_t fn, void *arg); int xml_apply_ancestor(cxobj *xn, xml_applyfn_t fn, void *arg);

View file

@ -53,9 +53,9 @@ int xmlns_assign(cxobj *x);
int xml2cvec(cxobj *xt, yang_stmt *ys, cvec **cvv0); int xml2cvec(cxobj *xt, yang_stmt *ys, cvec **cvv0);
int cvec2xml_1(cvec *cvv, char *toptag, cxobj *xp, cxobj **xt0); int cvec2xml_1(cvec *cvv, char *toptag, cxobj *xp, cxobj **xt0);
int xml_diff(yang_stmt *yspec, cxobj *x0, cxobj *x1, int xml_diff(yang_stmt *yspec, cxobj *x0, cxobj *x1,
cxobj ***first, size_t *firstlen, cxobj ***first, int *firstlen,
cxobj ***second, size_t *secondlen, cxobj ***second, int *secondlen,
cxobj ***changed_x0, cxobj ***changed_x1, size_t *changedlen); cxobj ***changed_x0, cxobj ***changed_x1, int *changedlen);
int xml_tree_prune_flagged_sub(cxobj *xt, int flag, int test, int *upmark); int xml_tree_prune_flagged_sub(cxobj *xt, int flag, int test, int *upmark);
int xml_tree_prune_flagged(cxobj *xt, int flag, int test); int xml_tree_prune_flagged(cxobj *xt, int flag, int test);
int xml_namespace_change(cxobj *x, char *namespace, char *prefix); int xml_namespace_change(cxobj *x, char *namespace, char *prefix);

View file

@ -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_extract(clixon_xvec *xv, cxobj ***xvec, size_t *xlen); int clixon_xvec_extract(clixon_xvec *xv, cxobj ***xvec, int *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);

View file

@ -135,12 +135,12 @@ int xpath_vec_ctx(cxobj *xcur, cvec *nsc, char *xpath, int localonly, xp_ctx
#if defined(__GNUC__) && __GNUC__ >= 3 #if defined(__GNUC__) && __GNUC__ >= 3
int xpath_vec_bool(cxobj *xcur, cvec *nsc, char *xpformat, ...) __attribute__ ((format (printf, 3, 4))); int xpath_vec_bool(cxobj *xcur, cvec *nsc, char *xpformat, ...) __attribute__ ((format (printf, 3, 4)));
int xpath_vec_flag(cxobj *xcur, cvec *nsc, char *xpformat, uint16_t flags, int xpath_vec_flag(cxobj *xcur, cvec *nsc, char *xpformat, uint16_t flags,
cxobj ***vec, size_t *veclen, ...) __attribute__ ((format (printf, 3, 7))); cxobj ***vec, int *veclen, ...) __attribute__ ((format (printf, 3, 7)));
#else #else
int xpath_vec_bool(cxobj *xcur, cvec *nsc, char *xpformat, ...); int xpath_vec_bool(cxobj *xcur, cvec *nsc, char *xpformat, ...);
int xpath_vec_flag(cxobj *xcur, cvec *nsc, char *xpformat, uint16_t flags, int xpath_vec_flag(cxobj *xcur, cvec *nsc, char *xpformat, uint16_t flags,
cxobj ***vec, size_t *veclen, ...); cxobj ***vec, int *veclen, ...);
#endif #endif
/* Functions with explicit namespace context (nsc) set. If you do not need /* Functions with explicit namespace context (nsc) set. If you do not need

View file

@ -75,7 +75,7 @@ enum xp_objtype{
struct xp_ctx{ struct xp_ctx{
enum xp_objtype xc_type; enum xp_objtype xc_type;
cxobj **xc_nodeset; /* if type XT_NODESET */ cxobj **xc_nodeset; /* if type XT_NODESET */
size_t xc_size; /* Length of nodeset */ int xc_size; /* Length of nodeset */
int xc_bool; /* if xc_type XT_BOOL */ int xc_bool; /* if xc_type XT_BOOL */
double xc_number; /* if xc_type XT_NUMBER */ double xc_number; /* if xc_type XT_NUMBER */
char *xc_string; /* if xc_type XT_STRING */ char *xc_string; /* if xc_type XT_STRING */

View file

@ -41,7 +41,10 @@
int xpath_list_optimize_stats(int *hits); int xpath_list_optimize_stats(int *hits);
int xpath_list_optimize_set(int enable); int xpath_list_optimize_set(int enable);
void xpath_optimize_exit(void); void xpath_optimize_exit(void);
//int xpath_optimize_check(xpath_tree *xs, cxobj *xv, cxobj ***xvec0, size_t *xlen0); #if 0 /* XXX kludge for include file dependencies */
int xpath_optimize_check(xpath_tree *xs, cxobj *xv, cxobj ***xvec0, int *xlen0);
#else
int xpath_optimize_check(); int xpath_optimize_check();
#endif
#endif /* _CLIXON_XPATH_OPTIMIZE_H */ #endif /* _CLIXON_XPATH_OPTIMIZE_H */

View file

@ -225,11 +225,7 @@ keyval_pos(char *uint)
goto done; goto done;
} }
cv = cvec_i(cvv, 0); cv = cvec_i(cvv, 0);
if (cv_type_set(cv, CGV_UINT32) < 0){ cv_type_set(cv, CGV_UINT32);
clicon_err(OE_UNIX, errno, "cv_type_set");
cvv = NULL;
goto done;
}
if ((ret = cv_parse1(uint, cv, &reason)) < 0){ if ((ret = cv_parse1(uint, cv, &reason)) < 0){
clicon_err(OE_UNIX, errno, "cv_parse1"); clicon_err(OE_UNIX, errno, "cv_parse1");
cvv = NULL; cvv = NULL;

View file

@ -47,7 +47,7 @@ struct clixon_json_yacc {
cxobj *jy_xtop; /* cxobj top element (fixed) */ cxobj *jy_xtop; /* cxobj top element (fixed) */
cxobj *jy_current; /* cxobj active element (changes with parse context) */ cxobj *jy_current; /* cxobj active element (changes with parse context) */
cxobj **jy_xvec; /* Vector of created top-level nodes (to know which are created) */ cxobj **jy_xvec; /* Vector of created top-level nodes (to know which are created) */
size_t jy_xlen; /* Length of jy_xvec */ int jy_xlen; /* Length of jy_xvec */
}; };
typedef struct clixon_json_yacc clixon_json_yacc; typedef struct clixon_json_yacc clixon_json_yacc;

View file

@ -344,7 +344,7 @@ nacm_datanode_prepare(clicon_handle h,
cvec *nsc0 = NULL; /* Non-canonical namespace context */ cvec *nsc0 = NULL; /* Non-canonical namespace context */
yang_stmt *yspec; yang_stmt *yspec;
cxobj **xvec = NULL; cxobj **xvec = NULL;
size_t xlen = 0; int xlen = 0;
int ret; int ret;
yspec = clicon_dbspec_yang(h); yspec = clicon_dbspec_yang(h);
@ -422,7 +422,7 @@ nacm_datanode_prepare(clicon_handle h,
if (ret == 0) if (ret == 0)
continue; continue;
if (xlen > 1) if (xlen > 1)
clicon_log(LOG_WARNING, "%s path:%s Clixon only supports single returns, this had: %lu", __FUNCTION__, path, xlen); clicon_log(LOG_WARNING, "%s path:%s Clixon only supports single returns, this had: %d", __FUNCTION__, path, xlen);
if (clixon_xvec_append(xpathvec, xvec?xvec[0]:NULL) < 0) /* XXX: vector of vectors? */ if (clixon_xvec_append(xpathvec, xvec?xvec[0]:NULL) < 0) /* XXX: vector of vectors? */
goto done; goto done;
if (xvec){ if (xvec){

View file

@ -1507,7 +1507,7 @@ int
clixon_xml_find_api_path(cxobj *xt, clixon_xml_find_api_path(cxobj *xt,
yang_stmt *yt, yang_stmt *yt,
cxobj ***xvec, cxobj ***xvec,
size_t *xlen, int *xlen,
char *format, char *format,
...) ...)
{ {
@ -1584,7 +1584,7 @@ clixon_xml_find_api_path(cxobj *xt,
* - 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
* cxobj **vec = NULL; * cxobj **vec = NULL;
* size_t len = 0; * int len = 0;
* if (clixon_xml_find_instance_id(x, yspec, &vec, &len, "/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<len; i++){ * for (i=0; i<len; i++){
@ -1601,7 +1601,7 @@ int
clixon_xml_find_instance_id(cxobj *xt, clixon_xml_find_instance_id(cxobj *xt,
yang_stmt *yt, yang_stmt *yt,
cxobj ***xvec, cxobj ***xvec,
size_t *xlen, int *xlen,
char *format, char *format,
...) ...)
{ {

View file

@ -279,7 +279,7 @@ xml_stats_one(cxobj *x,
} }
if (szp) if (szp)
*szp = sz; *szp = sz;
clicon_debug(1, "%s %" PRIu64, __FUNCTION__, sz); clicon_debug(1, "%s %zu", __FUNCTION__, sz);
return 0; return 0;
} }
@ -307,7 +307,7 @@ xml_stats(cxobj *xt,
if (szp) if (szp)
*szp += sz; *szp += sz;
} }
clicon_debug(1, "%s %" PRIu64, __FUNCTION__, *szp); clicon_debug(1, "%s %zu", __FUNCTION__, *szp);
return 0; return 0;
} }
@ -1911,9 +1911,9 @@ xml_dup(cxobj *x0)
*/ */
int int
cxvec_dup(cxobj **vec0, cxvec_dup(cxobj **vec0,
size_t len0, int len0,
cxobj ***vec1, cxobj ***vec1,
size_t *len1) int *len1)
{ {
int retval = -1; int retval = -1;
@ -1934,7 +1934,7 @@ cxvec_dup(cxobj **vec0,
* @retval -1 Error * @retval -1 Error
* @code * @code
* cxobj **xvec = NULL; * cxobj **xvec = NULL;
* size_t xlen = 0; * int xlen = 0;
* cxobj *x; * cxobj *x;
* *
* if (cxvec_append(x, &xvec, &xlen) < 0) * if (cxvec_append(x, &xvec, &xlen) < 0)
@ -1943,11 +1943,12 @@ cxvec_dup(cxobj **vec0,
* free(xvec); * free(xvec);
* @endcode * @endcode
* @see cxvec_prepend * @see cxvec_prepend
* @see clixon_cxvec_append which is its own encapsulated xml vector datatype
*/ */
int int
cxvec_append(cxobj *x, cxvec_append(cxobj *x,
cxobj ***vec, cxobj ***vec,
size_t *len) int *len)
{ {
int retval = -1; int retval = -1;
@ -1978,11 +1979,12 @@ cxvec_append(cxobj *x,
* free(xvec); * free(xvec);
* @endcode * @endcode
* @see cxvec_prepend * @see cxvec_prepend
* @see clixon_cxvec_prepend which is its own encapsulated xml vector datatype
*/ */
int int
cxvec_prepend(cxobj *x, cxvec_prepend(cxobj *x,
cxobj ***vec, cxobj ***vec,
size_t *len) int *len)
{ {
int retval = -1; int retval = -1;

View file

@ -443,12 +443,12 @@ xml_diff1(yang_stmt *ys,
cxobj *x0, cxobj *x0,
cxobj *x1, cxobj *x1,
cxobj ***x0vec, cxobj ***x0vec,
size_t *x0veclen, int *x0veclen,
cxobj ***x1vec, cxobj ***x1vec,
size_t *x1veclen, int *x1veclen,
cxobj ***changed_x0, cxobj ***changed_x0,
cxobj ***changed_x1, cxobj ***changed_x1,
size_t *changedlen) int *changedlen)
{ {
int retval = -1; int retval = -1;
cxobj *x0c = NULL; /* x0 child */ cxobj *x0c = NULL; /* x0 child */
@ -551,12 +551,12 @@ xml_diff(yang_stmt *yspec,
cxobj *x0, cxobj *x0,
cxobj *x1, cxobj *x1,
cxobj ***first, cxobj ***first,
size_t *firstlen, int *firstlen,
cxobj ***second, cxobj ***second,
size_t *secondlen, int *secondlen,
cxobj ***changed_x0, cxobj ***changed_x0,
cxobj ***changed_x1, cxobj ***changed_x1,
size_t *changedlen) int *changedlen)
{ {
int retval = -1; int retval = -1;

View file

@ -54,7 +54,7 @@ struct clixon_xml_parse_yacc {
yang_stmt *xy_yspec; /* If set, top-level yang-spec */ yang_stmt *xy_yspec; /* If set, top-level yang-spec */
int xy_lex_state; /* lex return state */ int xy_lex_state; /* lex return state */
cxobj **xy_xvec; /* Vector of created top-level nodes (to know which are created) */ cxobj **xy_xvec; /* Vector of created top-level nodes (to know which are created) */
size_t xy_xlen; /* Length of xy_xvec */ int xy_xlen; /* Length of xy_xvec */
}; };
typedef struct clixon_xml_parse_yacc clixon_xml_yacc; typedef struct clixon_xml_parse_yacc clixon_xml_yacc;

View file

@ -209,7 +209,7 @@ clixon_xvec_i(clixon_xvec *xv,
int int
clixon_xvec_extract(clixon_xvec *xv, clixon_xvec_extract(clixon_xvec *xv,
cxobj ***xvec, cxobj ***xvec,
size_t *xlen) int *xlen)
{ {
int retval = -1; int retval = -1;

View file

@ -770,7 +770,7 @@ xpath_vec(cxobj *xcur,
* @retval -1 error. * @retval -1 error.
* @code * @code
* cxobj **vec; * cxobj **vec;
* size_t veclen; * int veclen;
* cvec *nsc; // namespace context (not NULL) * cvec *nsc; // namespace context (not NULL)
* if (xpath_vec_flag(xcur, nsc, "//symbol/foo", XML_FLAG_ADD, &vec, &veclen) < 0) * if (xpath_vec_flag(xcur, nsc, "//symbol/foo", XML_FLAG_ADD, &vec, &veclen) < 0)
* goto err; * goto err;
@ -789,7 +789,7 @@ xpath_vec_flag(cxobj *xcur,
char *xpformat, char *xpformat,
uint16_t flags, uint16_t flags,
cxobj ***vec, cxobj ***vec,
size_t *veclen, int *veclen,
...) ...)
{ {
int retval = -1; int retval = -1;

View file

@ -253,12 +253,12 @@ nodetest_recursive(cxobj *xn,
cvec *nsc, cvec *nsc,
int localonly, int localonly,
cxobj ***vec0, cxobj ***vec0,
size_t *vec0len) int *vec0len)
{ {
int retval = -1; int retval = -1;
cxobj *xsub; cxobj *xsub;
cxobj **vec = *vec0; cxobj **vec = *vec0;
size_t veclen = *vec0len; int veclen = *vec0len;
xsub = NULL; xsub = NULL;
while ((xsub = xml_child_each(xn, xsub, node_type)) != NULL) { while ((xsub = xml_child_each(xn, xsub, node_type)) != NULL) {
@ -306,7 +306,7 @@ xp_eval_step(xp_ctx *xc0,
cxobj *xv; cxobj *xv;
cxobj *xp; cxobj *xp;
cxobj **vec = NULL; cxobj **vec = NULL;
size_t veclen = 0; int veclen = 0;
xpath_tree *nodetest = xs->xs_c0; xpath_tree *nodetest = xs->xs_c0;
xp_ctx *xc = NULL; xp_ctx *xc = NULL;
int ret; int ret;

View file

@ -321,7 +321,7 @@ int
xpath_optimize_check(xpath_tree *xs, xpath_optimize_check(xpath_tree *xs,
cxobj *xv, cxobj *xv,
cxobj ***xvec0, cxobj ***xvec0,
size_t *xlen0) int *xlen0)
{ {
#ifdef XPATH_LIST_OPTIMIZE #ifdef XPATH_LIST_OPTIMIZE
int ret; int ret;

View file

@ -92,7 +92,7 @@ main(int argc,
cxobj *x = NULL; cxobj *x = NULL;
cxobj *xc; cxobj *xc;
cxobj **xvec = NULL; cxobj **xvec = NULL;
size_t xlen = 0; int xlen = 0;
int c; int c;
int len; int len;
char *buf = NULL; char *buf = NULL;

View file

@ -69,6 +69,7 @@
#define UTIL_XML_MOD_OPTS "hD:o:y:b:x:p:s" #define UTIL_XML_MOD_OPTS "hD:o:y:b:x:p:s"
enum opx{ enum opx{
OPX_ERROR = -1,
OPX_INSERT, OPX_INSERT,
OPX_MERGE, OPX_MERGE,
OPX_PARENT OPX_PARENT
@ -126,7 +127,7 @@ main(int argc, char **argv)
int sort = 0; int sort = 0;
int ret; int ret;
clicon_handle h; clicon_handle h;
enum opx opx = -1; enum opx opx = OPX_ERROR;
char *reason = NULL; char *reason = NULL;
clicon_log_init("clixon_insert", LOG_DEBUG, CLICON_LOG_STDERR); clicon_log_init("clixon_insert", LOG_DEBUG, CLICON_LOG_STDERR);
@ -168,7 +169,7 @@ main(int argc, char **argv)
/* Sanity check: check mandatory arguments */ /* Sanity check: check mandatory arguments */
if (x1str == NULL || x0str == NULL || yangfile == NULL) if (x1str == NULL || x0str == NULL || yangfile == NULL)
usage(argv0); usage(argv0);
if (opx == -1) if (opx == OPX_ERROR)
usage(argv0); usage(argv0);
if ((yspec = yspec_new()) == NULL) if ((yspec = yspec_new()) == NULL)
goto done; goto done;