Refactoring search code using clixon_xvec data structures
This commit is contained in:
parent
bac2089a04
commit
f1ceec689a
10 changed files with 211 additions and 175 deletions
|
|
@ -86,13 +86,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, clixon_xvec **xvec, char *format,
|
||||||
...) __attribute__ ((format (printf, 5, 6)));;
|
...) __attribute__ ((format (printf, 4, 5)));;
|
||||||
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, clixon_xvec **xvec, char *format,
|
||||||
...) __attribute__ ((format (printf, 5, 6)));;
|
...) __attribute__ ((format (printf, 4, 5)));;
|
||||||
#else
|
#else
|
||||||
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, clixon_xvec **xvec, char *format, ...);
|
||||||
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, clixon_xvec **xvec, char *format, ...);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* _CLIXON_PATH_H_ */
|
#endif /* _CLIXON_PATH_H_ */
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ int xml_search_indexvar_binary_pos(cxobj *xp, char *indexvar, clixon_xvec *xvec,
|
||||||
#endif
|
#endif
|
||||||
int match_base_child(cxobj *x0, cxobj *x1c, yang_stmt *yc, cxobj **x0cp);
|
int match_base_child(cxobj *x0, cxobj *x1c, yang_stmt *yc, cxobj **x0cp);
|
||||||
int clixon_xml_find_index(cxobj *xp, yang_stmt *yp, char *namespace, char *name,
|
int clixon_xml_find_index(cxobj *xp, yang_stmt *yp, char *namespace, char *name,
|
||||||
cvec *cvk, cxobj ***xvec, size_t *xlen);
|
cvec *cvk, clixon_xvec **xvec);
|
||||||
int clixon_xml_find_pos(cxobj *xp, yang_stmt *yc, uint32_t pos, cxobj ***xvec, size_t *xlen);
|
int clixon_xml_find_pos(cxobj *xp, yang_stmt *yc, uint32_t pos, clixon_xvec **xvec);
|
||||||
|
|
||||||
#endif /* _CLIXON_XML_SORT_H */
|
#endif /* _CLIXON_XML_SORT_H */
|
||||||
|
|
|
||||||
|
|
@ -51,6 +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_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);
|
||||||
|
|
|
||||||
|
|
@ -38,9 +38,10 @@
|
||||||
#define _CLIXON_XPATH_OPTIMIZE_H
|
#define _CLIXON_XPATH_OPTIMIZE_H
|
||||||
|
|
||||||
|
|
||||||
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();
|
//int xpath_optimize_check(xpath_tree *xs, cxobj *xv, cxobj ***xvec0, size_t *xlen0);
|
||||||
|
int xpath_optimize_check();
|
||||||
|
|
||||||
#endif /* _CLIXON_XPATH_OPTIMIZE_H */
|
#endif /* _CLIXON_XPATH_OPTIMIZE_H */
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,7 @@
|
||||||
#include "clixon_yang.h"
|
#include "clixon_yang.h"
|
||||||
#include "clixon_xml.h"
|
#include "clixon_xml.h"
|
||||||
#include "clixon_xml_nsctx.h"
|
#include "clixon_xml_nsctx.h"
|
||||||
|
#include "clixon_xml_vec.h"
|
||||||
#include "clixon_xml_sort.h"
|
#include "clixon_xml_sort.h"
|
||||||
#include "clixon_netconf_lib.h"
|
#include "clixon_netconf_lib.h"
|
||||||
#include "clixon_xml_map.h"
|
#include "clixon_xml_map.h"
|
||||||
|
|
@ -1401,7 +1402,6 @@ instance_id_resolve(clixon_path *cplist,
|
||||||
* @param[in] yt Yang statement of top symbol (can be yang-spec if top-level)
|
* @param[in] yt Yang statement of top symbol (can be yang-spec if top-level)
|
||||||
* @param[in] cplist Lisp of clixon-path
|
* @param[in] cplist Lisp of clixon-path
|
||||||
* @param[out] xvec Vector of xml-trees. Vector must be free():d after use
|
* @param[out] xvec Vector of xml-trees. Vector must be free():d after use
|
||||||
* @param[out] xlen Returns length of vector in return value
|
|
||||||
* @retval -1 Error
|
* @retval -1 Error
|
||||||
* @retval 0 Fail fail: eg no yang
|
* @retval 0 Fail fail: eg no yang
|
||||||
* @retval 1 OK with found xml nodes in xvec (if any)
|
* @retval 1 OK with found xml nodes in xvec (if any)
|
||||||
|
|
@ -1410,61 +1410,61 @@ static int
|
||||||
clixon_path_search(cxobj *xt,
|
clixon_path_search(cxobj *xt,
|
||||||
yang_stmt *yt,
|
yang_stmt *yt,
|
||||||
clixon_path *cplist,
|
clixon_path *cplist,
|
||||||
cxobj ***xvec0,
|
clixon_xvec **xvec0)
|
||||||
size_t *xlen0)
|
|
||||||
{
|
{
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
char *modns; /* Module namespace of api-path */
|
char *modns; /* Module namespace of api-path */
|
||||||
clixon_path *cp;
|
clixon_path *cp;
|
||||||
cxobj **xvecp = NULL; /* parent set */
|
clixon_xvec *xvecp = NULL;
|
||||||
size_t xlenp = 0;
|
clixon_xvec *xvecc = NULL;
|
||||||
cxobj **xvecc = NULL; /* child set */
|
|
||||||
size_t xlenc = 0;
|
|
||||||
yang_stmt *yc;
|
yang_stmt *yc;
|
||||||
cxobj *xp;
|
cxobj *xp;
|
||||||
int i;
|
int i;
|
||||||
cg_var *cv;
|
cg_var *cv;
|
||||||
|
|
||||||
|
if ((xvecp = clixon_xvec_new()) == NULL)
|
||||||
|
goto done;
|
||||||
modns = NULL;
|
modns = NULL;
|
||||||
if ((cp = cplist) != NULL){
|
if ((cp = cplist) != NULL){
|
||||||
cxvec_append(xt, &xvecp, &xlenp); /* Initialize parent xml set */
|
if (clixon_xvec_append(xvecp, xt) < 0)
|
||||||
|
goto done;
|
||||||
do {
|
do {
|
||||||
yc = cp->cp_yang;
|
yc = cp->cp_yang;
|
||||||
if ((modns = yang_find_mynamespace(yc)) == NULL)
|
if ((modns = yang_find_mynamespace(yc)) == NULL)
|
||||||
goto fail;
|
goto fail;
|
||||||
for (i=0; i<xlenp; i++){
|
for (i=0; i<clixon_xvec_len(xvecp); i++){
|
||||||
xp = xvecp[i]; /* Iterate over parent set */
|
xp = clixon_xvec_i(xvecp, i); /* Iterate over parent set */
|
||||||
|
xvecc = NULL;
|
||||||
if (cp->cp_cvk && /* cornercase for instance-id [<pos>] special case */
|
if (cp->cp_cvk && /* cornercase for instance-id [<pos>] special case */
|
||||||
(yang_keyword_get(yc) == Y_LIST || yang_keyword_get(yc) == Y_LEAF_LIST) &&
|
(yang_keyword_get(yc) == Y_LIST || yang_keyword_get(yc) == Y_LEAF_LIST) &&
|
||||||
cvec_len(cp->cp_cvk) == 1 && (cv = cvec_i(cp->cp_cvk,0)) &&
|
cvec_len(cp->cp_cvk) == 1 && (cv = cvec_i(cp->cp_cvk,0)) &&
|
||||||
(cv_type_get(cv) == CGV_UINT32)){
|
(cv_type_get(cv) == CGV_UINT32)){
|
||||||
if (clixon_xml_find_pos(xp, yc, cv_uint32_get(cv), &xvecc, &xlenc) < 0)
|
if (clixon_xml_find_pos(xp, yc, cv_uint32_get(cv), &xvecc) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
else if (clixon_xml_find_index(xp, yang_parent_get(yc),
|
else if (clixon_xml_find_index(xp, yang_parent_get(yc),
|
||||||
modns, yang_argument_get(yc),
|
modns, yang_argument_get(yc),
|
||||||
cp->cp_cvk, &xvecc, &xlenc) < 0)
|
cp->cp_cvk, &xvecc) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
} /* for */
|
||||||
if (xvecp)
|
if (xvecp)
|
||||||
free(xvecp);
|
clixon_xvec_free(xvecp);
|
||||||
xvecp = xvecc; xlenp = xlenc;
|
xvecp = xvecc;
|
||||||
xvecc = NULL, xlenc = 0;
|
xvecc = NULL;
|
||||||
cp = NEXTQ(clixon_path *, cp);
|
cp = NEXTQ(clixon_path *, cp);
|
||||||
} while (cp && cp != cplist);
|
} while (cp && cp != cplist);
|
||||||
*xvec0 = xvecp; xvecp = NULL;
|
*xvec0 = xvecp;
|
||||||
*xlen0 = xlenp;
|
xvecp = NULL;
|
||||||
}
|
} /* if */
|
||||||
retval = 1;
|
retval = 1;
|
||||||
done:
|
done:
|
||||||
if (xvecp)
|
if (xvecp)
|
||||||
free(xvecp);
|
clixon_xvec_free(xvecp);
|
||||||
if (xvecc)
|
if (xvecc)
|
||||||
free(xvecc);
|
clixon_xvec_free(xvecc);
|
||||||
return retval;
|
return retval;
|
||||||
fail: /* eg no yang for api-path, no match */
|
fail: /* eg no yang for api-path, no match */
|
||||||
*xvec0 = NULL;
|
*xvec0 = NULL;
|
||||||
*xlen0 = 0;
|
|
||||||
retval = 0;
|
retval = 0;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
@ -1474,7 +1474,6 @@ clixon_path_search(cxobj *xt,
|
||||||
* @param[in] xt Top xml-tree where to search
|
* @param[in] xt Top xml-tree where to search
|
||||||
* @param[in] yt Yang statement of top symbol (can be yang-spec if top-level)
|
* @param[in] yt Yang statement of top symbol (can be yang-spec if top-level)
|
||||||
* @param[out] xvec Vector of xml-trees. Vector must be free():d after use
|
* @param[out] xvec Vector of xml-trees. Vector must be free():d after use
|
||||||
* @param[out] xlen Returns length of vector in return value
|
|
||||||
* @param[in] format Format string for api-path syntax
|
* @param[in] format Format string for api-path syntax
|
||||||
* @retval -1 Error
|
* @retval -1 Error
|
||||||
* @retval 0 Nomatch
|
* @retval 0 Nomatch
|
||||||
|
|
@ -1484,24 +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
|
||||||
* cxobj **xvec = NULL;
|
* clixon_xvec *xvec = NULL;
|
||||||
* size_t xlen;
|
* cxobj *x;
|
||||||
* if (clixon_xml_find_api_path(x, yspec, &xvec, &xlen, "/symbol/%s", "foo") < 0)
|
* if (clixon_xml_find_api_path(x, yspec, &xvec, "/symbol/%s", "foo") < 0)
|
||||||
* err;
|
* err;
|
||||||
* for (i=0; i<xlen; i++){
|
* for (i=0; i<clixon_xpath_len(xvec); i++){
|
||||||
* xn = xvec[i];
|
* x = clixon_xpath_i(xvec, i);
|
||||||
* ...
|
* ...
|
||||||
* }
|
* }
|
||||||
* free(xvec);
|
* clixon_xvec_free(xvec);
|
||||||
* @endcode
|
* @endcode
|
||||||
* @see xpath_vec
|
* @see xpath_vec1
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
clixon_xml_find_api_path(cxobj *xt,
|
clixon_xml_find_api_path(cxobj *xt,
|
||||||
yang_stmt *yt,
|
yang_stmt *yt,
|
||||||
cxobj ***xvec,
|
clixon_xvec **xvec,
|
||||||
size_t *xlen,
|
char *format,
|
||||||
char *format,
|
|
||||||
...)
|
...)
|
||||||
{
|
{
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
|
|
@ -1537,7 +1535,7 @@ 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, xlen);
|
retval = clixon_path_search(xt, yt, cplist, xvec);
|
||||||
done:
|
done:
|
||||||
if (cplist)
|
if (cplist)
|
||||||
clixon_path_free(cplist);
|
clixon_path_free(cplist);
|
||||||
|
|
@ -1565,15 +1563,15 @@ 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
|
||||||
* cxobj **xvec = NULL;
|
* clixon_xvec *xvec = NULL;
|
||||||
* size_t xlen;
|
* cxobj *x;
|
||||||
* if (clixon_xml_find_instance_id(x, &xvec, &xlen, "/symbol/%s", "foo") < 0)
|
* if (clixon_xml_find_instance_id(x, &xvec, "/symbol/%s", "foo") < 0)
|
||||||
* goto err;
|
* goto err;
|
||||||
* for (i=0; i<xlen; i++){
|
* for (i=0; i<clixon_xpath_len(xvec); i++){
|
||||||
* xn = xvec[i];
|
* xn = clixon_xpath_i(xvec, i);
|
||||||
* ...
|
* ...
|
||||||
* }
|
* }
|
||||||
* free(xvec);
|
* clixon_xvec_free(xvec);
|
||||||
* @endcode
|
* @endcode
|
||||||
* @see xpath_vec for full XML XPaths
|
* @see xpath_vec for full XML XPaths
|
||||||
* @see api_path_search for RESTCONF api-paths
|
* @see api_path_search for RESTCONF api-paths
|
||||||
|
|
@ -1582,8 +1580,7 @@ clixon_xml_find_api_path(cxobj *xt,
|
||||||
int
|
int
|
||||||
clixon_xml_find_instance_id(cxobj *xt,
|
clixon_xml_find_instance_id(cxobj *xt,
|
||||||
yang_stmt *yt,
|
yang_stmt *yt,
|
||||||
cxobj ***xvec,
|
clixon_xvec **xvec,
|
||||||
size_t *xlen,
|
|
||||||
char *format,
|
char *format,
|
||||||
...)
|
...)
|
||||||
{
|
{
|
||||||
|
|
@ -1619,7 +1616,7 @@ 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, xlen)) < 0)
|
if ((retval = clixon_path_search(xt, yt, cplist, xvec)) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
done:
|
done:
|
||||||
if (cplist)
|
if (cplist)
|
||||||
|
|
|
||||||
|
|
@ -402,7 +402,6 @@ xml_sort(cxobj *x,
|
||||||
* @param[in] yangi Yang order number (according to spec)
|
* @param[in] yangi Yang order number (according to spec)
|
||||||
* @param[in] mid Where to start from (may be in middle of interval)
|
* @param[in] mid Where to start from (may be in middle of interval)
|
||||||
* @param[out] xvec Vector of matching XML return objects (can be empty)
|
* @param[out] xvec Vector of matching XML return objects (can be empty)
|
||||||
* @param[out] xlen Length of xvec
|
|
||||||
* @retval 0 OK, see xvec (may be empty)
|
* @retval 0 OK, see xvec (may be empty)
|
||||||
* @retval -1 Error
|
* @retval -1 Error
|
||||||
* XXX: only first match
|
* XXX: only first match
|
||||||
|
|
@ -413,8 +412,7 @@ xml_find_keys_notsorted(cxobj *xp,
|
||||||
int yangi,
|
int yangi,
|
||||||
int mid,
|
int mid,
|
||||||
int skip1,
|
int skip1,
|
||||||
cxobj ***xvec,
|
clixon_xvec *xvec)
|
||||||
size_t *xlen)
|
|
||||||
{
|
{
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
int i;
|
int i;
|
||||||
|
|
@ -427,7 +425,7 @@ xml_find_keys_notsorted(cxobj *xp,
|
||||||
if (yangi != yang_order(yc)) /* wrong yang */
|
if (yangi != yang_order(yc)) /* wrong yang */
|
||||||
break;
|
break;
|
||||||
if (xml_cmp(xc, x1, 0, skip1, NULL) == 0){
|
if (xml_cmp(xc, x1, 0, skip1, NULL) == 0){
|
||||||
if (cxvec_append(xc, xvec, xlen) < 0)
|
if (clixon_xvec_append(xvec, xc) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
goto ok; /* found */
|
goto ok; /* found */
|
||||||
}
|
}
|
||||||
|
|
@ -438,7 +436,7 @@ xml_find_keys_notsorted(cxobj *xp,
|
||||||
if (yangi != yang_order(yc)) /* wrong yang */
|
if (yangi != yang_order(yc)) /* wrong yang */
|
||||||
break;
|
break;
|
||||||
if (xml_cmp(xc, x1, 0, skip1, NULL) == 0){
|
if (xml_cmp(xc, x1, 0, skip1, NULL) == 0){
|
||||||
if (cxvec_append(xc, xvec, xlen) < 0)
|
if (clixon_xvec_append(xvec, xc) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
goto ok; /* found */
|
goto ok; /* found */
|
||||||
}
|
}
|
||||||
|
|
@ -456,7 +454,6 @@ xml_find_keys_notsorted(cxobj *xp,
|
||||||
* @param[in] yangi Yang order number (according to spec)
|
* @param[in] yangi Yang order number (according to spec)
|
||||||
* @param[in] mid Where to start from (may be in middle of interval)
|
* @param[in] mid Where to start from (may be in middle of interval)
|
||||||
* @param[out] xvec Vector of matching XML return objects (can be empty)
|
* @param[out] xvec Vector of matching XML return objects (can be empty)
|
||||||
* @param[out] xlen Length of xvec
|
|
||||||
* @retval 0 OK, see xvec (may be empty)
|
* @retval 0 OK, see xvec (may be empty)
|
||||||
* @retval -1 Error
|
* @retval -1 Error
|
||||||
*/
|
*/
|
||||||
|
|
@ -467,8 +464,7 @@ search_multi_equals(cxobj **childvec,
|
||||||
int yangi,
|
int yangi,
|
||||||
int mid,
|
int mid,
|
||||||
int skip1,
|
int skip1,
|
||||||
cxobj ***xvec,
|
clixon_xvec *xvec)
|
||||||
size_t *xlen)
|
|
||||||
{
|
{
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
int i;
|
int i;
|
||||||
|
|
@ -482,7 +478,7 @@ search_multi_equals(cxobj **childvec,
|
||||||
break;
|
break;
|
||||||
if (xml_cmp(x1, xc, 0, skip1, NULL) != 0)
|
if (xml_cmp(x1, xc, 0, skip1, NULL) != 0)
|
||||||
break;
|
break;
|
||||||
if (cxvec_prepend(xc, xvec, xlen) < 0)
|
if (clixon_xvec_prepend(xvec, xc) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
for (i=mid+1; i<childlen; i++){ /* Then increment */
|
for (i=mid+1; i<childlen; i++){ /* Then increment */
|
||||||
|
|
@ -492,7 +488,7 @@ search_multi_equals(cxobj **childvec,
|
||||||
break;
|
break;
|
||||||
if (xml_cmp(x1, xc, 0, skip1, NULL) != 0)
|
if (xml_cmp(x1, xc, 0, skip1, NULL) != 0)
|
||||||
break;
|
break;
|
||||||
if (cxvec_append(xc, xvec, xlen) < 0)
|
if (clixon_xvec_append(xvec, xc) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -505,12 +501,11 @@ search_multi_equals(cxobj **childvec,
|
||||||
/* XXX unify with search_multi_equals */
|
/* XXX unify with search_multi_equals */
|
||||||
static int
|
static int
|
||||||
search_multi_equals_xvec(clixon_xvec *childvec,
|
search_multi_equals_xvec(clixon_xvec *childvec,
|
||||||
cxobj *x1,
|
cxobj *x1,
|
||||||
int yangi,
|
int yangi,
|
||||||
int mid,
|
int mid,
|
||||||
int skip1,
|
int skip1,
|
||||||
cxobj ***xvec,
|
clixon_xvec *xvec)
|
||||||
size_t *xlen)
|
|
||||||
{
|
{
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
int i;
|
int i;
|
||||||
|
|
@ -524,7 +519,7 @@ search_multi_equals_xvec(clixon_xvec *childvec,
|
||||||
break;
|
break;
|
||||||
if (xml_cmp(x1, xc, 0, skip1, NULL) != 0)
|
if (xml_cmp(x1, xc, 0, skip1, NULL) != 0)
|
||||||
break;
|
break;
|
||||||
if (cxvec_prepend(xc, xvec, xlen) < 0)
|
if (clixon_xvec_prepend(xvec, xc) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
for (i=mid+1; i<clixon_xvec_len(childvec); i++){ /* Then increment */
|
for (i=mid+1; i<clixon_xvec_len(childvec); i++){ /* Then increment */
|
||||||
|
|
@ -534,10 +529,9 @@ search_multi_equals_xvec(clixon_xvec *childvec,
|
||||||
break;
|
break;
|
||||||
if (xml_cmp(x1, xc, 0, skip1, NULL) != 0)
|
if (xml_cmp(x1, xc, 0, skip1, NULL) != 0)
|
||||||
break;
|
break;
|
||||||
if (cxvec_append(xc, xvec, xlen) < 0)
|
if (clixon_xvec_append(xvec, xc) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
return retval;
|
return retval;
|
||||||
|
|
@ -619,14 +613,14 @@ xml_search_indexvar(cxobj *xp,
|
||||||
int low,
|
int low,
|
||||||
int upper,
|
int upper,
|
||||||
char *indexvar,
|
char *indexvar,
|
||||||
cxobj ***xvec,
|
clixon_xvec *xvec)
|
||||||
size_t *xlen)
|
|
||||||
{
|
{
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
clixon_xvec *ivec = NULL;
|
clixon_xvec *ivec = NULL;
|
||||||
int ilen;
|
int ilen;
|
||||||
int pos;
|
int pos;
|
||||||
int eq = 0;
|
int eq = 0;
|
||||||
|
cxobj *xc;
|
||||||
|
|
||||||
/* Check if (exactly one) explicit indexes in cvk */
|
/* Check if (exactly one) explicit indexes in cvk */
|
||||||
if (xml_search_vector_get(xp, indexvar, &ivec) < 0)
|
if (xml_search_vector_get(xp, indexvar, &ivec) < 0)
|
||||||
|
|
@ -638,11 +632,12 @@ xml_search_indexvar(cxobj *xp,
|
||||||
ilen, ilen, &eq)) < 0)
|
ilen, ilen, &eq)) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if (eq){ /* Found */
|
if (eq){ /* Found */
|
||||||
if (cxvec_append(clixon_xvec_i(ivec,pos), xvec, xlen) < 0)
|
xc = clixon_xvec_i(ivec, pos);
|
||||||
|
if (clixon_xvec_append(xvec, xc) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
/* there may be more? */
|
/* there may be more? */
|
||||||
if (search_multi_equals_xvec(ivec, x1, yangi, pos,
|
if (search_multi_equals_xvec(ivec, x1, yangi, pos,
|
||||||
0, xvec, xlen) < 0)
|
0, xvec) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -650,7 +645,6 @@ xml_search_indexvar(cxobj *xp,
|
||||||
done:
|
done:
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* XML_EXPLICIT_INDEX */
|
#endif /* XML_EXPLICIT_INDEX */
|
||||||
|
|
||||||
/*! Find XML child under xp matching x1 using binary search
|
/*! Find XML child under xp matching x1 using binary search
|
||||||
|
|
@ -663,7 +657,6 @@ xml_search_indexvar(cxobj *xp,
|
||||||
* @param[in] skip1 Key matching skipped for keys not in x1
|
* @param[in] skip1 Key matching skipped for keys not in x1
|
||||||
* @param[in] indexvar Override list key value search with explicit search index of x1
|
* @param[in] indexvar Override list key value search with explicit search index of x1
|
||||||
* @param[out] xvec Vector of matching XML return objects (can be empty)
|
* @param[out] xvec Vector of matching XML return objects (can be empty)
|
||||||
* @param[out] xlen Length of xvec
|
|
||||||
* @retval 0 OK, see xvec (may be empty)
|
* @retval 0 OK, see xvec (may be empty)
|
||||||
* @retval -1 Error
|
* @retval -1 Error
|
||||||
*/
|
*/
|
||||||
|
|
@ -676,8 +669,7 @@ xml_search_binary(cxobj *xp,
|
||||||
int upper,
|
int upper,
|
||||||
int skip1,
|
int skip1,
|
||||||
char *indexvar,
|
char *indexvar,
|
||||||
cxobj ***xvec,
|
clixon_xvec *xvec)
|
||||||
size_t *xlen)
|
|
||||||
{
|
{
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
int mid;
|
int mid;
|
||||||
|
|
@ -698,7 +690,7 @@ xml_search_binary(cxobj *xp,
|
||||||
if (cmp == 0){
|
if (cmp == 0){
|
||||||
#ifdef XML_EXPLICIT_INDEX
|
#ifdef XML_EXPLICIT_INDEX
|
||||||
if (indexvar){
|
if (indexvar){
|
||||||
if (xml_search_indexvar(xp, x1, yangi, low, upper, indexvar, xvec, xlen) < 0)
|
if (xml_search_indexvar(xp, x1, yangi, low, upper, indexvar, xvec) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
goto ok;
|
goto ok;
|
||||||
}
|
}
|
||||||
|
|
@ -706,23 +698,22 @@ xml_search_binary(cxobj *xp,
|
||||||
/* >0 means search upper interval, <0 lower interval, = 0 is equal */
|
/* >0 means search upper interval, <0 lower interval, = 0 is equal */
|
||||||
cmp = xml_cmp(x1, xc, 0, skip1, NULL);
|
cmp = xml_cmp(x1, xc, 0, skip1, NULL);
|
||||||
if (cmp && !sorted){ /* Ordered by user (if not equal) */
|
if (cmp && !sorted){ /* Ordered by user (if not equal) */
|
||||||
retval = xml_find_keys_notsorted(xp, x1, yangi, mid, skip1, xvec, xlen);
|
retval = xml_find_keys_notsorted(xp, x1, yangi, mid, skip1, xvec);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (cmp == 0){
|
if (cmp == 0){
|
||||||
if (cxvec_append(xc, xvec, xlen) < 0)
|
if (clixon_xvec_append(xvec, xc) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
/* there may be more? */
|
/* there may be more? */
|
||||||
if (search_multi_equals(xml_childvec_get(xp), xml_child_nr(xp),
|
if (search_multi_equals(xml_childvec_get(xp), xml_child_nr(xp),
|
||||||
x1, yangi, mid,
|
x1, yangi, mid, skip1, xvec) < 0)
|
||||||
skip1, xvec, xlen) < 0)
|
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
else if (cmp < 0)
|
else if (cmp < 0)
|
||||||
xml_search_binary(xp, x1, sorted, yangi, low, mid-1, skip1, indexvar, xvec, xlen);
|
xml_search_binary(xp, x1, sorted, yangi, low, mid-1, skip1, indexvar, xvec);
|
||||||
else
|
else
|
||||||
xml_search_binary(xp, x1, sorted, yangi, mid+1, upper, skip1, indexvar, xvec, xlen);
|
xml_search_binary(xp, x1, sorted, yangi, mid+1, upper, skip1, indexvar, xvec);
|
||||||
ok:
|
ok:
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
|
|
@ -740,7 +731,6 @@ xml_search_binary(cxobj *xp,
|
||||||
* @param[in] skip1 Key matching skipped for keys not in x1
|
* @param[in] skip1 Key matching skipped for keys not in x1
|
||||||
* @param[in] indexvar Override list key value search with explicit search index var of x1
|
* @param[in] indexvar Override list key value search with explicit search index var of x1
|
||||||
* @param[out] xvec Vector of matching XML return objects (can be empty)
|
* @param[out] xvec Vector of matching XML return objects (can be empty)
|
||||||
* @param[out] xlen Length of xvec
|
|
||||||
* @retval 0 OK, see xvec (may be empty)
|
* @retval 0 OK, see xvec (may be empty)
|
||||||
* @retval -1 Error
|
* @retval -1 Error
|
||||||
* @see xml_find_index for a generic search function
|
* @see xml_find_index for a generic search function
|
||||||
|
|
@ -751,8 +741,7 @@ xml_search_yang(cxobj *xp,
|
||||||
yang_stmt *yc,
|
yang_stmt *yc,
|
||||||
int skip1,
|
int skip1,
|
||||||
char *indexvar,
|
char *indexvar,
|
||||||
cxobj ***xvec,
|
clixon_xvec *xvec)
|
||||||
size_t *xlen)
|
|
||||||
{
|
{
|
||||||
cxobj *xa;
|
cxobj *xa;
|
||||||
int low = 0;
|
int low = 0;
|
||||||
|
|
@ -771,7 +760,7 @@ xml_search_yang(cxobj *xp,
|
||||||
else if (yang_keyword_get(yc) == Y_LIST || yang_keyword_get(yc) == Y_LEAF_LIST)
|
else if (yang_keyword_get(yc) == Y_LIST || yang_keyword_get(yc) == Y_LEAF_LIST)
|
||||||
sorted = (yang_find(yc, Y_ORDERED_BY, "user") == NULL);
|
sorted = (yang_find(yc, Y_ORDERED_BY, "user") == NULL);
|
||||||
yangi = yang_order(yc);
|
yangi = yang_order(yc);
|
||||||
return xml_search_binary(xp, x1, sorted, yangi, low, upper, skip1, indexvar, xvec, xlen);
|
return xml_search_binary(xp, x1, sorted, yangi, low, upper, skip1, indexvar, xvec);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Insert xn in xp:s sorted child list (special case of ordered-by user)
|
/*! Insert xn in xp:s sorted child list (special case of ordered-by user)
|
||||||
|
|
@ -1080,8 +1069,7 @@ match_base_child(cxobj *x0,
|
||||||
yang_stmt *y0c;
|
yang_stmt *y0c;
|
||||||
yang_stmt *y0p;
|
yang_stmt *y0p;
|
||||||
yang_stmt *yp; /* yang parent */
|
yang_stmt *yp; /* yang parent */
|
||||||
cxobj **xvec = NULL;
|
clixon_xvec *xvec = NULL;
|
||||||
size_t xlen = 0;
|
|
||||||
|
|
||||||
*x0cp = NULL; /* init return value */
|
*x0cp = NULL; /* init return value */
|
||||||
/* Special case is if yc parent (yp) is choice/case
|
/* Special case is if yc parent (yp) is choice/case
|
||||||
|
|
@ -1118,27 +1106,28 @@ match_base_child(cxobj *x0,
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* Get match. */
|
if ((xvec = clixon_xvec_new()) == NULL)
|
||||||
if (xml_search_yang(x0, x1c, yc, 0, 0, &xvec, &xlen) < 0)
|
|
||||||
goto done;
|
goto done;
|
||||||
if (xlen)
|
/* Get match. */
|
||||||
*x0cp = xvec[0];
|
if (xml_search_yang(x0, x1c, yc, 0, 0, xvec) < 0)
|
||||||
|
goto done;
|
||||||
|
if (clixon_xvec_len(xvec))
|
||||||
|
*x0cp = clixon_xvec_i(xvec, 0);
|
||||||
ok:
|
ok:
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
if (xvec)
|
if (xvec)
|
||||||
free(xvec);
|
clixon_xvec_free(xvec);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! API for search in XML child list with non-indexed variables
|
/*! API for search in XML child list with non-indexed variables
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
xml_find_noyang_cvk(char *ns0,
|
xml_find_noyang_cvk(char *ns0,
|
||||||
cxobj *xc,
|
cxobj *xc,
|
||||||
cvec *cvk,
|
cvec *cvk,
|
||||||
cxobj ***xvec,
|
clixon_xvec *xvec)
|
||||||
size_t *xlen)
|
|
||||||
{
|
{
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
cg_var *cvi;
|
cg_var *cvi;
|
||||||
|
|
@ -1182,7 +1171,7 @@ xml_find_noyang_cvk(char *ns0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (cvi == NULL) /* means we iterated through all indexes without breaks */
|
if (cvi == NULL) /* means we iterated through all indexes without breaks */
|
||||||
if (cxvec_append(xc, xvec, xlen) < 0)
|
if (clixon_xvec_append(xvec, xc) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
|
|
@ -1193,12 +1182,12 @@ xml_find_noyang_cvk(char *ns0,
|
||||||
* Fallback if no yang available. Only linear search for matching name, and eventual index match
|
* Fallback if no yang available. Only linear search for matching name, and eventual index match
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
xml_find_noyang_name(cxobj *xp,
|
xml_find_noyang_name(cxobj *xp,
|
||||||
char *ns0,
|
char *ns0,
|
||||||
char *name,
|
char *name,
|
||||||
cvec *cvk,
|
cvec *cvk,
|
||||||
cxobj ***xvec,
|
clixon_xvec *xvec)
|
||||||
size_t *xlen)
|
|
||||||
{
|
{
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
cxobj *xc;
|
cxobj *xc;
|
||||||
|
|
@ -1221,11 +1210,11 @@ xml_find_noyang_name(cxobj *xp,
|
||||||
if (strcmp(name, xml_name(xc)) != 0) /* Namespace does not match, skip */
|
if (strcmp(name, xml_name(xc)) != 0) /* Namespace does not match, skip */
|
||||||
continue;
|
continue;
|
||||||
if (cvk){ /* Check indexes */
|
if (cvk){ /* Check indexes */
|
||||||
if (xml_find_noyang_cvk(ns0, xc, cvk, xvec, xlen) < 0)
|
if (xml_find_noyang_cvk(ns0, xc, cvk, xvec) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
else /* No index variables: just add node to found list */
|
else /* No index variables: just add node to found list */
|
||||||
if (cxvec_append(xc, xvec, xlen) < 0)
|
if (clixon_xvec_append(xvec, xc) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
retval = 0;
|
retval = 0;
|
||||||
|
|
@ -1246,17 +1235,15 @@ xml_find_noyang_name(cxobj *xp,
|
||||||
* @param[in] yc Yang spec of list child (preferred) See rule (2) above
|
* @param[in] yc Yang spec of list child (preferred) See rule (2) above
|
||||||
* @param[in] cvk List of keys and values as CLIgen vector on the form k1=foo, k2=bar
|
* @param[in] cvk List of keys and values as CLIgen vector on the form k1=foo, k2=bar
|
||||||
* @param[out] xvec Array of found nodes
|
* @param[out] xvec Array of found nodes
|
||||||
* @param[out] xlen Len of xvec
|
|
||||||
* @retval 1 OK
|
* @retval 1 OK
|
||||||
* @retval 0 Revert, try again with no-yang search
|
* @retval 0 Revert, try again with no-yang search
|
||||||
* @retval -1 Error
|
* @retval -1 Error
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
xml_find_index_yang(cxobj *xp,
|
xml_find_index_yang(cxobj *xp,
|
||||||
yang_stmt *yc,
|
yang_stmt *yc,
|
||||||
cvec *cvk,
|
cvec *cvk,
|
||||||
cxobj ***xvec,
|
clixon_xvec *xvec)
|
||||||
size_t *xlen)
|
|
||||||
{
|
{
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
cxobj *xc = NULL;
|
cxobj *xc = NULL;
|
||||||
|
|
@ -1348,7 +1335,7 @@ xml_find_index_yang(cxobj *xp,
|
||||||
if (xml_spec_set(xk, yk) < 0)
|
if (xml_spec_set(xk, yk) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
if (xml_search_yang(xp, xc, yc, 1, indexvar, xvec, xlen) < 0)
|
if (xml_search_yang(xp, xc, yc, 1, indexvar, xvec) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
retval = 1; /* OK */
|
retval = 1; /* OK */
|
||||||
done:
|
done:
|
||||||
|
|
@ -1393,16 +1380,20 @@ xml_find_index_yang(cxobj *xp,
|
||||||
* @param[in] name Name of child (not required if yc given)
|
* @param[in] name Name of child (not required if yc given)
|
||||||
* @param[in] cvk List of keys and values as CLIgen vector on the form k1=foo, k2=bar
|
* @param[in] cvk List of keys and values as CLIgen vector on the form k1=foo, k2=bar
|
||||||
* @param[out] xvec Array of found nodes
|
* @param[out] xvec Array of found nodes
|
||||||
* @param[out] xlen Len of xvec
|
|
||||||
* @retval 0 OK, see xret
|
* @retval 0 OK, see xret
|
||||||
* @retval -1 Error
|
* @retval -1 Error
|
||||||
* @code
|
* @code
|
||||||
* cxobj **xvec = NULL;
|
* clixon_xvec *xv = NULL;
|
||||||
* size_t xlen = 0;
|
* cvec *cvk = NULL; vector of index keys
|
||||||
* cvec *cvk = NULL; vector of index keys
|
* cxobj *x;
|
||||||
* ... 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, &xvec, &xlen) < 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++){
|
||||||
|
* x = clixon_xpath_i(xvec, i);
|
||||||
|
* ...
|
||||||
|
* }
|
||||||
|
* clixon_xvec_free(xvec);
|
||||||
* @endcode
|
* @endcode
|
||||||
* Discussion:
|
* Discussion:
|
||||||
* (1) Rule 2 on how to get the child name election seems unecessary complex. First, it would be
|
* (1) Rule 2 on how to get the child name election seems unecessary complex. First, it would be
|
||||||
|
|
@ -1410,13 +1401,12 @@ xml_find_index_yang(cxobj *xp,
|
||||||
* parsing, copy-buffers, or simply for XML nodes that do not have YANG.
|
* parsing, copy-buffers, or simply for XML nodes that do not have YANG.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
clixon_xml_find_index(cxobj *xp,
|
clixon_xml_find_index(cxobj *xp,
|
||||||
yang_stmt *yp,
|
yang_stmt *yp,
|
||||||
char *namespace,
|
char *namespace,
|
||||||
char *name,
|
char *name,
|
||||||
cvec *cvk,
|
cvec *cvk,
|
||||||
cxobj ***xvec,
|
clixon_xvec **xvec)
|
||||||
size_t *xlen)
|
|
||||||
{
|
{
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
@ -1434,21 +1424,27 @@ clixon_xml_find_index(cxobj *xp,
|
||||||
if (yp)
|
if (yp)
|
||||||
yc = yang_find_datanode(yp, name);
|
yc = yang_find_datanode(yp, name);
|
||||||
}
|
}
|
||||||
|
if ((*xvec = clixon_xvec_new()) == NULL)
|
||||||
|
goto done;
|
||||||
if (yc){
|
if (yc){
|
||||||
if ((ret = xml_find_index_yang(xp, yc, cvk, xvec, xlen)) < 0)
|
if ((ret = xml_find_index_yang(xp, yc, cvk, *xvec)) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if (ret == 0){ /* This means yang method did not work for some reason
|
if (ret == 0){ /* This means yang method did not work for some reason
|
||||||
* such as not being list key indexes in cvk, for example
|
* such as not being list key indexes in cvk, for example
|
||||||
*/
|
*/
|
||||||
if (xml_find_noyang_name(xp, namespace, name, cvk, xvec, xlen) < 0)
|
if (xml_find_noyang_name(xp, namespace, name, cvk, *xvec) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (xml_find_noyang_name(xp, namespace, name, cvk, xvec, xlen) < 0)
|
if (xml_find_noyang_name(xp, namespace, name, cvk, *xvec) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
|
if (retval < 0){
|
||||||
|
clixon_xvec_free(*xvec);
|
||||||
|
*xvec = NULL;
|
||||||
|
}
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1459,16 +1455,14 @@ clixon_xml_find_index(cxobj *xp,
|
||||||
* @param[in] yc Yang spec of list child
|
* @param[in] yc Yang spec of list child
|
||||||
* @param[in] pos Position
|
* @param[in] pos Position
|
||||||
* @param[out] xvec Array of found nodes
|
* @param[out] xvec Array of found nodes
|
||||||
* @param[out] xlen Len of xvec
|
|
||||||
* @retval 0 OK, see xret
|
* @retval 0 OK, see xret
|
||||||
* @retval -1 Error
|
* @retval -1 Error
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
clixon_xml_find_pos(cxobj *xp,
|
clixon_xml_find_pos(cxobj *xp,
|
||||||
yang_stmt *yc,
|
yang_stmt *yc,
|
||||||
uint32_t pos,
|
uint32_t pos,
|
||||||
cxobj ***xvec,
|
clixon_xvec **xvec)
|
||||||
size_t *xlen)
|
|
||||||
{
|
{
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
cxobj *xc = NULL;
|
cxobj *xc = NULL;
|
||||||
|
|
@ -1482,16 +1476,22 @@ clixon_xml_find_pos(cxobj *xp,
|
||||||
name = yang_argument_get(yc);
|
name = yang_argument_get(yc);
|
||||||
u = 0;
|
u = 0;
|
||||||
xc = NULL;
|
xc = NULL;
|
||||||
|
if ((*xvec = clixon_xvec_new()) == NULL)
|
||||||
|
goto done;
|
||||||
while ((xc = xml_child_each(xp, xc, CX_ELMNT)) != NULL) {
|
while ((xc = xml_child_each(xp, xc, CX_ELMNT)) != NULL) {
|
||||||
if (strcmp(name, xml_name(xc)))
|
if (strcmp(name, xml_name(xc)))
|
||||||
continue;
|
continue;
|
||||||
if (pos == u++){ /* Found */
|
if (pos == u++){ /* Found */
|
||||||
if (cxvec_append(xc, xvec, xlen) < 0)
|
if (clixon_xvec_append(*xvec, xc) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
|
if (retval < 0){
|
||||||
|
clixon_xvec_free(*xvec);
|
||||||
|
*xvec = NULL;
|
||||||
|
}
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -93,9 +93,9 @@ clixon_xvec_inc(clixon_xvec *xv)
|
||||||
|
|
||||||
xv->xv_len++;
|
xv->xv_len++;
|
||||||
if (xv->xv_len > xv->xv_max){
|
if (xv->xv_len > xv->xv_max){
|
||||||
if (xv->xv_max == 0)
|
if (xv->xv_max < XVEC_MAX_DEFAULT)
|
||||||
xv->xv_max = XVEC_MAX_DEFAULT;
|
xv->xv_max = XVEC_MAX_DEFAULT;
|
||||||
if (xv->xv_max < XVEC_MAX_THRESHOLD)
|
else if (xv->xv_max < XVEC_MAX_THRESHOLD)
|
||||||
xv->xv_max *= 2;
|
xv->xv_max *= 2;
|
||||||
else
|
else
|
||||||
xv->xv_max += XVEC_MAX_THRESHOLD;
|
xv->xv_max += XVEC_MAX_THRESHOLD;
|
||||||
|
|
@ -197,6 +197,37 @@ clixon_xvec_i(clixon_xvec *xv,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! Return whole XML object vector
|
||||||
|
*
|
||||||
|
* 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)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*! Append a new xml tree to an existing xml vector last in the list
|
/*! Append a new xml tree to an existing xml vector last in the list
|
||||||
*
|
*
|
||||||
* @param[in] xv XML tree vector
|
* @param[in] xv XML tree vector
|
||||||
|
|
@ -218,7 +249,7 @@ clixon_xvec_append(clixon_xvec *xv,
|
||||||
|
|
||||||
if (clixon_xvec_inc(xv) < 0)
|
if (clixon_xvec_inc(xv) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
xv->xv_vec[xv->xv_len] = x;
|
xv->xv_vec[xv->xv_len-1] = x;
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
return retval;
|
return retval;
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,7 @@
|
||||||
#include "clixon_handle.h"
|
#include "clixon_handle.h"
|
||||||
#include "clixon_yang.h"
|
#include "clixon_yang.h"
|
||||||
#include "clixon_xml.h"
|
#include "clixon_xml.h"
|
||||||
|
#include "clixon_xml_vec.h"
|
||||||
#include "clixon_xml_sort.h"
|
#include "clixon_xml_sort.h"
|
||||||
#include "clixon_xpath_ctx.h"
|
#include "clixon_xpath_ctx.h"
|
||||||
#include "clixon_xpath.h"
|
#include "clixon_xpath.h"
|
||||||
|
|
@ -227,8 +228,7 @@ loop_preds(xpath_tree *xt,
|
||||||
static int
|
static int
|
||||||
xpath_list_optimize_fn(xpath_tree *xt,
|
xpath_list_optimize_fn(xpath_tree *xt,
|
||||||
cxobj *xv,
|
cxobj *xv,
|
||||||
cxobj ***xvec,
|
clixon_xvec **xvec)
|
||||||
size_t *xlen)
|
|
||||||
{
|
{
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
xpath_tree *xm = NULL;
|
xpath_tree *xm = NULL;
|
||||||
|
|
@ -294,7 +294,7 @@ xpath_list_optimize_fn(xpath_tree *xt,
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
/* Use 2a form since yc allready given to compute cvk */
|
/* Use 2a form since yc allready given to compute cvk */
|
||||||
if (clixon_xml_find_index(xv, yp, NULL, name, cvk, xvec, xlen) < 0)
|
if (clixon_xml_find_index(xv, yp, NULL, name, cvk, xvec) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
retval = 1; /* match */
|
retval = 1; /* match */
|
||||||
done:
|
done:
|
||||||
|
|
@ -314,22 +314,27 @@ xpath_list_optimize_fn(xpath_tree *xt,
|
||||||
* @retval -1 Error
|
* @retval -1 Error
|
||||||
* @retval 0 Dont optimize: not special case, do normal processing
|
* @retval 0 Dont optimize: not special case, do normal processing
|
||||||
* @retval 1 Optimization made, special case, use x (found if != NULL)
|
* @retval 1 Optimization made, special case, use x (found if != NULL)
|
||||||
|
* XXX Contains glue code between cxobj ** and clixon_xvec code
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
xpath_optimize_check(xpath_tree *xs,
|
xpath_optimize_check(xpath_tree *xs,
|
||||||
cxobj *xv,
|
cxobj *xv,
|
||||||
cxobj ***xvec,
|
cxobj ***xvec0,
|
||||||
size_t *xlen)
|
size_t *xlen0)
|
||||||
|
|
||||||
{
|
{
|
||||||
#ifdef XPATH_LIST_OPTIMIZE
|
#ifdef XPATH_LIST_OPTIMIZE
|
||||||
int ret;
|
int ret;
|
||||||
|
clixon_xvec *xvec = NULL;
|
||||||
|
|
||||||
if (!_optimize_enable)
|
if (!_optimize_enable)
|
||||||
return 0; /* use regular code */
|
return 0; /* use regular code */
|
||||||
if ((ret = xpath_list_optimize_fn(xs, xv, xvec, xlen)) < 0)
|
/* Glue code since xpath code uses (old) cxobj ** and search code uses (new) clixon_xvec */
|
||||||
|
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)
|
||||||
|
return -1;
|
||||||
|
clixon_xvec_free(xvec);
|
||||||
_optimize_hits++;
|
_optimize_hits++;
|
||||||
return 1; /* Optimized */
|
return 1; /* Optimized */
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -117,8 +117,7 @@ trigger_rpc(clicon_handle h, /* Clicon handle */
|
||||||
char *val;
|
char *val;
|
||||||
cvec *cvk = NULL;
|
cvec *cvk = NULL;
|
||||||
cg_var *cv;
|
cg_var *cv;
|
||||||
cxobj **xvec = NULL;
|
clixon_xvec *xvec = NULL;
|
||||||
size_t xlen = 0;
|
|
||||||
|
|
||||||
if (xmldb_get(h, "running", NULL, "/c", &xret) < 0)
|
if (xmldb_get(h, "running", NULL, "/c", &xret) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
@ -158,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, &xlen) < 0)
|
if (clixon_xml_find_index(xc, NULL, NULL, "y3", cvk, &xvec) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if (xlen)
|
if (clixon_xvec_len(xvec))
|
||||||
val = xml_find_body(xvec[0], "val");
|
val = xml_find_body(clixon_xvec_i(xvec,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");
|
||||||
|
|
|
||||||
|
|
@ -90,8 +90,8 @@ main(int argc,
|
||||||
char *argv0 = argv[0];
|
char *argv0 = argv[0];
|
||||||
int i;
|
int i;
|
||||||
cxobj *x = NULL;
|
cxobj *x = NULL;
|
||||||
cxobj **xvec = NULL;
|
cxobj *xc;
|
||||||
size_t xlen = 0;
|
clixon_xvec *xvec = NULL;
|
||||||
int c;
|
int c;
|
||||||
int len;
|
int len;
|
||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
|
|
@ -244,13 +244,14 @@ main(int argc,
|
||||||
clicon_log(LOG_NOTICE, "%s: sort verify failed", __FUNCTION__);
|
clicon_log(LOG_NOTICE, "%s: sort verify failed", __FUNCTION__);
|
||||||
}
|
}
|
||||||
/* Repeat for profiling (default is nr = 1) */
|
/* Repeat for profiling (default is nr = 1) */
|
||||||
|
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, &xlen, "%s", path)) < 0)
|
if ((ret = clixon_xml_find_api_path(x, yspec, &xvec, "%s", path)) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
if ((ret = clixon_xml_find_instance_id(x, yspec, &xvec, &xlen, "%s", path)) < 0)
|
if ((ret = clixon_xml_find_instance_id(x, yspec, &xvec, "%s", path)) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
if (ret == 0){
|
if (ret == 0){
|
||||||
|
|
@ -259,9 +260,10 @@ main(int argc,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Print results */
|
/* Print results */
|
||||||
for (i=0; i<xlen; i++){
|
for (i=0; i<clixon_xvec_len(xvec); i++){
|
||||||
|
xc = clixon_xvec_i(xvec,i);
|
||||||
fprintf(stdout, "%d: ", i);
|
fprintf(stdout, "%d: ", i);
|
||||||
clicon_xml2file(stdout, xvec[i], 0, 0);
|
clicon_xml2file(stdout, xc, 0, 0);
|
||||||
fprintf(stdout, "\n");
|
fprintf(stdout, "\n");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
@ -272,7 +274,7 @@ main(int argc,
|
||||||
if (cb)
|
if (cb)
|
||||||
cbuf_free(cb);
|
cbuf_free(cb);
|
||||||
if (xvec)
|
if (xvec)
|
||||||
free(xvec);
|
clixon_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