- removed api_path extension from internal netconf

- Strings in xmldb_put not properly encoded, eg eth/0 became eth.00000
This commit is contained in:
Olof hagsand 2017-05-30 21:57:06 +02:00
parent 683376610c
commit 3453dae0db
36 changed files with 1048 additions and 1307 deletions

View file

@ -207,38 +207,64 @@ cli_dbxml(clicon_handle h,
{
int retval = -1;
char *str = NULL;
char *xkfmt; /* xml key format */
char *xk = NULL; /* xml key */
char *api_path_fmt; /* xml key format */
char *api_path = NULL; /* xml key */
cg_var *cval;
int len;
cg_var *arg;
cbuf *cb = NULL;
yang_spec *yspec;
cxobj *xbot = NULL; /* xpath, NULL if datastore */
yang_node *y = NULL; /* yang spec of xpath */
cxobj *xtop = NULL; /* xpath root */
cxobj *xa; /* attribute */
cxobj *xb; /* body */
if (cvec_len(argv) != 1){
clicon_err(OE_PLUGIN, 0, "%s: Requires one element to be xml key format string", __FUNCTION__);
goto done;
}
arg = cvec_i(argv, 0);
xkfmt = cv_string_get(arg);
if (xmlkeyfmt2key(xkfmt, cvv, &xk) < 0)
if ((yspec = clicon_dbspec_yang(h)) == NULL){
clicon_err(OE_FATAL, 0, "No DB_SPEC");
goto done;
len = cvec_len(cvv);
if (len > 1){
cval = cvec_i(cvv, len-1);
if ((str = cv2str_dup(cval)) == NULL){
clicon_err(OE_UNIX, errno, "cv2str_dup");
goto done;
}
arg = cvec_i(argv, 0);
api_path_fmt = cv_string_get(arg);
if (api_path_fmt2api_path(api_path_fmt, cvv, &api_path) < 0)
goto done;
/* Create config top-of-tree */
if ((xtop = xml_new("config", NULL)) == NULL)
goto done;
xbot = xtop;
if (api_path && api_path2xml(api_path, yspec, xtop, &xbot, &y) < 0)
goto done;
if ((xa = xml_new("operation", xbot)) == NULL)
goto done;
xml_type_set(xa, CX_ATTR);
if (xml_value_set(xa, xml_operation2str(op)) < 0)
goto done;
if (y->yn_keyword != Y_LIST){
len = cvec_len(cvv);
if (len > 1){
cval = cvec_i(cvv, len-1);
if ((str = cv2str_dup(cval)) == NULL){
clicon_err(OE_UNIX, errno, "cv2str_dup");
goto done;
}
if ((xb = xml_new("body", xbot)) == NULL)
goto done;
xml_type_set(xb, CX_BODY);
if (xml_value_set(xb, str) < 0)
goto done;
}
}
if ((cb = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new");
goto done;
}
if (str)
cprintf(cb, "<config>%s</config>", str);
else
cprintf(cb, "<config/>");
if (clicon_rpc_edit_config(h, "candidate", op, xk, cbuf_get(cb)) < 0)
if (clicon_xml2cbuf(cb, xtop, 0, 0) < 0)
goto done;
if (clicon_rpc_edit_config(h, "candidate", OP_NONE, cbuf_get(cb)) < 0)
goto done;
if (clicon_autocommit(h)) {
if (clicon_rpc_commit(h) < 0)
@ -250,8 +276,10 @@ cli_dbxml(clicon_handle h,
cbuf_free(cb);
if (str)
free(str);
if (xk)
free(xk);
if (api_path)
free(api_path);
if (xtop)
xml_free(xtop);
return retval;
}
@ -287,6 +315,31 @@ int cli_mergev(clicon_handle h, cvec *vars, cvec *argv)
return cli_merge(h, vars, argv);
}
int
cli_create(clicon_handle h, cvec *cvv, cvec *argv)
{
int retval = -1;
if (cli_dbxml(h, cvv, argv, OP_CREATE) < 0)
goto done;
retval = 0;
done:
return retval;
}
/*!
* @see cli_del
*/
int
cli_remove(clicon_handle h, cvec *cvv, cvec *argv)
{
int retval = -1;
if (cli_dbxml(h, cvv, argv, OP_REMOVE) < 0)
goto done;
retval = 0;
done:
return retval;
}
int
cli_del(clicon_handle h, cvec *cvv, cvec *argv)
@ -704,7 +757,6 @@ load_config_file(clicon_handle h,
}
if (clicon_rpc_edit_config(h, "candidate",
replace?OP_REPLACE:OP_MERGE,
"",
cbuf_get(cbxml)) < 0)
goto done;
cbuf_free(cbxml);
@ -1135,7 +1187,7 @@ cli_copy_config(clicon_handle h,
cbuf_reset(cb);
/* create xml copy tree and merge it with database configuration */
clicon_xml2cbuf(cb, x2, 0, 0);
if (clicon_rpc_edit_config(h, db, OP_MERGE, NULL, cbuf_get(cb)) < 0)
if (clicon_rpc_edit_config(h, db, OP_MERGE, cbuf_get(cb)) < 0)
goto done;
retval = 0;
done:

View file

@ -64,7 +64,7 @@
#include "cli_generate.h"
/* This is the default callback function. But this is typically overwritten */
#define GENERATE_CALLBACK "cli_set"
#define GENERATE_CALLBACK "overwrite_me"
/* variable expand function */
#define GENERATE_EXPAND_XMLDB "expand_dbvar"
@ -115,13 +115,12 @@ cli_expand_var_generate(clicon_handle h,
enum cv_type cvtype,
cbuf *cb0,
int options,
uint8_t fraction_digits
)
uint8_t fraction_digits)
{
int retval = -1;
char *xkfmt = NULL;
char *api_path_fmt = NULL;
if (yang2xmlkeyfmt(ys, 1, &xkfmt) < 0)
if (yang2api_path_fmt(ys, 1, &api_path_fmt) < 0)
goto done;
cprintf(cb0, "|<%s:%s", ys->ys_argument,
cv_type2str(cvtype));
@ -129,15 +128,15 @@ cli_expand_var_generate(clicon_handle h,
cprintf(cb0, " fraction-digits:%u", fraction_digits);
cprintf(cb0, " %s(\"candidate\",\"%s\")>",
GENERATE_EXPAND_XMLDB,
xkfmt);
api_path_fmt);
retval = 0;
done:
if (xkfmt)
free(xkfmt);
if (api_path_fmt)
free(api_path_fmt);
return retval;
}
/*! Create callback with xmlkey format string as argument
/*! Create callback with api_path format string as argument
* @param[in] h clicon handle
* @param[in] ys yang_stmt of the node at hand
* @param[in] cb0 The string where the result format string is inserted.
@ -149,15 +148,16 @@ cli_callback_generate(clicon_handle h,
cbuf *cb0)
{
int retval = -1;
char *xkfmt = NULL;
char *api_path_fmt = NULL;
if (yang2xmlkeyfmt(ys, 0, &xkfmt) < 0)
if (yang2api_path_fmt(ys, 0, &api_path_fmt) < 0)
goto done;
cprintf(cb0, ",%s(\"%s\")", GENERATE_CALLBACK, xkfmt);
cprintf(cb0, ",%s(\"%s\")", GENERATE_CALLBACK,
api_path_fmt);
retval = 0;
done:
if (xkfmt)
free(xkfmt);
if (api_path_fmt)
free(api_path_fmt);
return retval;
}
@ -166,8 +166,7 @@ static int yang2cli_stmt(clicon_handle h, yang_stmt *ys,
enum genmodel_type gt,
int level);
/*
* Check for completion (of already existent values), ranges (eg range[min:max]) and
/*! Check for completion (of already existent values), ranges (eg range[min:max]) and
* patterns, (eg regexp:"[0.9]*").
*/
static int
@ -403,7 +402,6 @@ yang2cli_leaf(clicon_handle h,
return retval;
}
static int
yang2cli_container(clicon_handle h,
yang_stmt *ys,

View file

@ -99,10 +99,10 @@ expand_dbvar(void *h,
cvec *helptexts)
{
int retval = -1;
char *xkfmt;
char *api_path;
char *dbstr;
cxobj *xt = NULL;
char *xkpath = NULL;
char *xpath = NULL;
cxobj **xvec = NULL;
size_t xlen = 0;
cxobj *x;
@ -129,23 +129,24 @@ expand_dbvar(void *h,
goto done;
}
if ((cv = cvec_i(argv, 1)) == NULL){
clicon_err(OE_PLUGIN, 0, "%s: Error when accessing argument <xkfmt>");
clicon_err(OE_PLUGIN, 0, "%s: Error when accessing argument <api_path>");
goto done;
}
xkfmt = cv_string_get(cv);
/* xkfmt = /interface/%s/address/%s
api_path = cv_string_get(cv);
/* api_path = /interface/%s/address/%s
--> ^/interface/eth0/address/.*$
--> /interface/[name=eth0]/address
*/
if (xmlkeyfmt2xpath(xkfmt, cvv, &xkpath) < 0)
if (api_path_fmt2xpath(api_path, cvv, &xpath) < 0)
goto done;
/* XXX read whole configuration, why not send xpath? */
if (clicon_rpc_get_config(h, dbstr, "/", &xt) < 0)
goto done;
/* One round to detect duplicates
* XXX The code below would benefit from some cleanup
*/
j = 0;
if (xpath_vec(xt, xkpath, &xvec, &xlen) < 0)
if (xpath_vec(xt, xpath, &xvec, &xlen) < 0)
goto done;
for (i = 0; i < xlen; i++) {
char *str;
@ -190,8 +191,8 @@ expand_dbvar(void *h,
free(xvec);
if (xt)
xml_free(xt);
if (xkpath)
free(xkpath);
if (xpath)
free(xpath);
return retval;
}
int

View file

@ -82,6 +82,9 @@ int cli_setv(clicon_handle h, cvec *vars, cvec *argv);
int cli_merge(clicon_handle h, cvec *vars, cvec *argv);
int cli_mergev(clicon_handle h, cvec *vars, cvec *argv);
int cli_create(clicon_handle h, cvec *vars, cvec *argv);
int cli_remove(clicon_handle h, cvec *vars, cvec *argv);
int cli_del(clicon_handle h, cvec *vars, cvec *argv);
int cli_delv(clicon_handle h, cvec *vars, cvec *argv);