diff --git a/lib/clixon/clixon_proto_encode.h b/lib/clixon/clixon_proto_encode.h index 5c7332a5..497d0a61 100644 --- a/lib/clixon/clixon_proto_encode.h +++ b/lib/clixon/clixon_proto_encode.h @@ -19,7 +19,7 @@ . * - * Protocol to communicate between clients (eg clicon_cli, clicon_netconf) + * Protocol to communicate between clients (eg clixon_cli, clixon_netconf) * and server (clicon_backend) */ diff --git a/lib/clixon/clixon_xml.h b/lib/clixon/clixon_xml.h index 5a9b5233..decd677b 100644 --- a/lib/clixon/clixon_xml.h +++ b/lib/clixon/clixon_xml.h @@ -77,6 +77,9 @@ int xml_type_set(cxobj *xn, enum cxobj_type type); int xml_index(cxobj *xn); int xml_index_set(cxobj *xn, int index); +cg_var *xml_cv_get(cxobj *xn); +int xml_cv_set(cxobj *xn, cg_var *cv); + int xml_child_nr(cxobj *xn); cxobj *xml_child_i(cxobj *xn, int i); cxobj *xml_child_i_set(cxobj *xt, int i, cxobj *xc); diff --git a/lib/src/clixon_proto.c b/lib/src/clixon_proto.c index d4057ceb..49ff93b3 100644 --- a/lib/src/clixon_proto.c +++ b/lib/src/clixon_proto.c @@ -19,7 +19,7 @@ . * - * Protocol to communicate between clients (eg clicon_cli, clicon_netconf) + * Protocol to communicate between clients (eg clixon_cli, clixon_netconf) * and server (clicon_backend) */ diff --git a/lib/src/clixon_xml.c b/lib/src/clixon_xml.c index 16299753..a993e9c3 100644 --- a/lib/src/clixon_xml.c +++ b/lib/src/clixon_xml.c @@ -68,6 +68,7 @@ struct xml{ int x_flags; /* Flags according to XML_FLAG_* above */ void *x_spec; /* Pointer to specification, eg yang, by reference, dont free */ + cg_var *x_cv; /* If body this contains the typed value */ }; /* @@ -307,6 +308,35 @@ xml_index_set(cxobj *xn, return old; } +/*! Get cligen variable associated with node + * @param[in] xn xml node + * @retval cv Cligen variable if set + * @retval NULL If not set, or not applicable + */ +cg_var * +xml_cv_get(cxobj *xn) +{ + if (xn->x_cv) + return xn->x_cv; + else + return NULL; +} + +/*! Set cligen variable associated with node + * @param[in] xn xml node + * @param[in] cv Cligen variable or NULL + * @retval 0 if OK + */ +int +xml_cv_set(cxobj *xn, + cg_var *cv) +{ + if (xn->x_cv) + free(xn->x_cv); + xn->x_cv = cv; + return 0; +} + /*! Get number of children * @param[in] xn xml node * @retval number of children in XML tree @@ -425,7 +455,7 @@ xml_childvec_set(cxobj *x, * @retval NULL if error and clicon_err() called */ cxobj * -xml_new(char *name, +xml_new(char *name, cxobj *xp) { cxobj *xn; @@ -547,13 +577,12 @@ xml_insert(cxobj *xp, } /*! Remove and free an xml node child from xml parent - * @param[in] xparent xml parent node - * @param[in] xchild xml child node (to be renmoved and freed) + * @param[in] xch xml child node (to be removed and freed) * @retval 0 OK * @retval -1 * @note you cannot remove xchild in the loop (unless yoy keep track of xprev) * - * @see xml_free Free, dont remove from parent + * @see xml_free Free, dont remove from parent * @see xml_child_rm Only remove dont free * Differs from xml_free it is removed from parent. */ @@ -724,6 +753,8 @@ xml_free(cxobj *x) free(x->x_value); if (x->x_namespace) free(x->x_namespace); + if (x->x_cv) + cv_free(x->x_cv); for (i=0; ix_childvec_len; i++){ xc = x->x_childvec[i]; xml_free(xc); @@ -998,6 +1029,8 @@ static int copy_one(cxobj *xn0, cxobj *xn1) { + cg_var *cv1; + xml_type_set(xn1, xml_type(xn0)); if (xml_value(xn0)){ /* malloced string */ if ((xn1->x_value = strdup(xn0->x_value)) == NULL){ @@ -1008,10 +1041,18 @@ copy_one(cxobj *xn0, if (xml_name(xn0)) /* malloced string */ if ((xml_name_set(xn1, xml_name(xn0))) < 0) return -1; + if (xml_cv_get(xn0)){ + if ((cv1 = cv_dup(xml_cv_get(xn0))) == NULL){ + clicon_err(OE_XML, errno, "%s: cv_dup", __FUNCTION__); + return -1; + } + if ((xml_cv_set(xn1, cv1)) < 0) + return -1; + } return 0; } -/*! Copy xml tree to other existing tree +/*! Copy xml tree x0 to other existing tree x1 * * x1 should be a created placeholder. If x1 is non-empty, * the copied tree is appended to the existing tree. diff --git a/lib/src/clixon_xml_db.c b/lib/src/clixon_xml_db.c index 4e42d0eb..ac9a11b9 100644 --- a/lib/src/clixon_xml_db.c +++ b/lib/src/clixon_xml_db.c @@ -421,7 +421,6 @@ db2file(clicon_handle h, } if (strcmp(db, "running") != 0 && strcmp(db, "candidate") != 0 && - strcmp(db, "result") != 0 && strcmp(db, "tmp") != 0){ clicon_err(OE_XML, 0, "Unexpected database: %s", db); goto done; diff --git a/lib/src/clixon_yang.c b/lib/src/clixon_yang.c index 3e26f64c..66753e19 100644 --- a/lib/src/clixon_yang.c +++ b/lib/src/clixon_yang.c @@ -1703,7 +1703,7 @@ clicon_strsplit_malloc(char *string, nvec++; /* alloc vector and append copy of string */ if ((vec = (char**)malloc(nvec* sizeof(char*) + strlen(string)+1)) == NULL){ - clicon_err(OE_YANG, errno, "calloc"); + clicon_err(OE_YANG, errno, "malloc"); goto err; } ptr = (char*)vec + nvec* sizeof(char*); /* this is where ptr starts */