Restructured error,debug anf log API
Renamed functions clicon->clixon, replaced global variables w access functions Unified clicon_netconf_error with clixon_err()
This commit is contained in:
parent
261469be16
commit
24a4991ec8
199 changed files with 4668 additions and 4158 deletions
|
|
@ -64,7 +64,7 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
/* clixon */
|
||||
#include <clixon/clixon.h>
|
||||
|
||||
#include "clixon_cli_api.h"
|
||||
|
|
@ -84,7 +84,7 @@
|
|||
* @note this calls cligen_regfd which may callback on cli command interpretator
|
||||
*/
|
||||
int
|
||||
cli_notification_register(clicon_handle h,
|
||||
cli_notification_register(clixon_handle h,
|
||||
char *stream,
|
||||
enum format_enum format,
|
||||
char *filter,
|
||||
|
|
@ -102,7 +102,7 @@ cli_notification_register(clicon_handle h,
|
|||
|
||||
len = strlen("log_socket_") + strlen(stream) + 1;
|
||||
if ((logname = malloc(len)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
snprintf(logname, len, "log_socket_%s", stream);
|
||||
|
|
@ -111,7 +111,7 @@ cli_notification_register(clicon_handle h,
|
|||
|
||||
if (status){ /* start */
|
||||
if (s_exist!=-1){
|
||||
clicon_err(OE_PLUGIN, 0, "Result log socket already exists");
|
||||
clixon_err(OE_PLUGIN, 0, "Result log socket already exists");
|
||||
goto done;
|
||||
}
|
||||
if (clicon_rpc_create_subscription(h, stream, filter, &s) < 0)
|
||||
|
|
@ -142,7 +142,7 @@ cli_notification_register(clicon_handle h,
|
|||
* This is for CLIgen to handle these signals, eg ^Ĉ means abort command, not program
|
||||
*/
|
||||
void
|
||||
cli_signal_block(clicon_handle h)
|
||||
cli_signal_block(clixon_handle h)
|
||||
{
|
||||
clicon_signal_block (SIGTSTP);
|
||||
clicon_signal_block (SIGQUIT);
|
||||
|
|
@ -152,7 +152,7 @@ cli_signal_block(clicon_handle h)
|
|||
}
|
||||
|
||||
void
|
||||
cli_signal_unblock(clicon_handle h)
|
||||
cli_signal_unblock(clixon_handle h)
|
||||
{
|
||||
clicon_signal_unblock (SIGTSTP);
|
||||
clicon_signal_unblock (SIGQUIT);
|
||||
|
|
@ -164,7 +164,7 @@ cli_signal_unblock(clicon_handle h)
|
|||
* Flush pending signals for a given signal type
|
||||
*/
|
||||
void
|
||||
cli_signal_flush(clicon_handle h)
|
||||
cli_signal_flush(clixon_handle h)
|
||||
{
|
||||
/* XXX A bit rough. Use sigpending() and more clever logic ?? */
|
||||
|
||||
|
|
@ -207,7 +207,7 @@ dbxml_body(cxobj *xbot,
|
|||
len = cvec_len(cvv);
|
||||
cval = cvec_i(cvv, len-1);
|
||||
if ((str = cv2str_dup(cval)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cv2str_dup");
|
||||
clixon_err(OE_UNIX, errno, "cv2str_dup");
|
||||
goto done;
|
||||
}
|
||||
if ((xb = xml_new("body", xbot, CX_BODY)) == NULL)
|
||||
|
|
@ -307,25 +307,25 @@ mtpoint_paths(yang_stmt *yspec0,
|
|||
yang_stmt *yspec1;
|
||||
|
||||
if (api_path_fmt01 == NULL){
|
||||
clicon_err(OE_FATAL, EINVAL, "arg is NULL");
|
||||
clixon_err(OE_FATAL, EINVAL, "arg is NULL");
|
||||
goto done;
|
||||
}
|
||||
if ((xtop0 = xml_new(NETCONF_INPUT_CONFIG, NULL, CX_ELMNT)) == NULL)
|
||||
goto done;
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if (yang_path_arg(yspec0, mtpoint, &yu) < 0)
|
||||
goto done;
|
||||
if (yu == NULL){
|
||||
clicon_err(OE_FATAL, 0, "yu not found");
|
||||
clixon_err(OE_FATAL, 0, "yu not found");
|
||||
goto done;
|
||||
}
|
||||
if (yang_mount_get(yu, mtpoint, &yspec1) < 0)
|
||||
goto done;
|
||||
if (yspec1 == NULL){
|
||||
clicon_err(OE_FATAL, 0, "yspec1 not found");
|
||||
clixon_err(OE_FATAL, 0, "yspec1 not found");
|
||||
goto done;
|
||||
}
|
||||
xbot0 = xtop0;
|
||||
|
|
@ -334,18 +334,18 @@ mtpoint_paths(yang_stmt *yspec0,
|
|||
if ((ret = xpath2xml(mtpoint, nsc0, xtop0, yspec0, &xbot0, &ybot0, NULL)) < 0)
|
||||
goto done;
|
||||
if (xbot0 == NULL){
|
||||
clicon_err(OE_YANG, 0, "No xbot");
|
||||
clixon_err(OE_YANG, 0, "No xbot");
|
||||
goto done;
|
||||
}
|
||||
if (yang2api_path_fmt(ybot0, 0, &api_path_fmt0) < 0)
|
||||
goto done;
|
||||
if (api_path_fmt0 == NULL){
|
||||
clicon_err(OE_YANG, 0, "No api_path_fmt0");
|
||||
clixon_err(OE_YANG, 0, "No api_path_fmt0");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "%s%s", api_path_fmt0, api_path_fmt1);
|
||||
if ((*api_path_fmt01 = strdup(cbuf_get(cb))) == NULL){
|
||||
clicon_err(OE_YANG, errno, "strdup");
|
||||
clixon_err(OE_YANG, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
@ -386,7 +386,7 @@ mtpoint_paths(yang_stmt *yspec0,
|
|||
* generated by a function such as clixon_instance_id_bind() or other programmatically.
|
||||
*/
|
||||
int
|
||||
cli_dbxml(clicon_handle h,
|
||||
cli_dbxml(clixon_handle h,
|
||||
cvec *cvv,
|
||||
cvec *argv,
|
||||
enum operation_type op,
|
||||
|
|
@ -412,11 +412,11 @@ cli_dbxml(clicon_handle h,
|
|||
|
||||
/* Top-level yspec */
|
||||
if ((yspec0 = clicon_dbspec_yang(h)) == NULL){
|
||||
clicon_err(OE_FATAL, 0, "No DB_SPEC");
|
||||
clixon_err(OE_FATAL, 0, "No DB_SPEC");
|
||||
goto done;
|
||||
}
|
||||
if ((api_path_fmt_cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
/* Concatenate all argv strings to a single string */
|
||||
|
|
@ -428,7 +428,7 @@ cli_dbxml(clicon_handle h,
|
|||
cv = cvec_i(argv, argc++);
|
||||
str = cv_string_get(cv);
|
||||
if (strncmp(str, "mtpoint:", strlen("mtpoint:")) != 0){
|
||||
clicon_err(OE_PLUGIN, 0, "mtpoint does not begin with 'mtpoint:'");
|
||||
clixon_err(OE_PLUGIN, 0, "mtpoint does not begin with 'mtpoint:'");
|
||||
goto done;
|
||||
}
|
||||
mtpoint = str + strlen("mtpoint:");
|
||||
|
|
@ -463,13 +463,12 @@ cli_dbxml(clicon_handle h,
|
|||
goto done;
|
||||
if (ret == 0){
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "api-path syntax error \"%s\": ", api_path_fmt);
|
||||
if (netconf_err2cb(h, xerr, cb) < 0)
|
||||
goto done;
|
||||
clicon_err(OE_CFG, EINVAL, "%s", cbuf_get(cb));
|
||||
clixon_err(OE_CFG, EINVAL, "api-path syntax error \"%s\": %s", api_path_fmt, cbuf_get(cb));
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -504,7 +503,7 @@ cli_dbxml(clicon_handle h,
|
|||
if ((ret = xml_apply0(xbot, CX_ELMNT, identityref_add_ns, yspec0)) < 0)
|
||||
goto done;
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if (clixon_xml2cbuf(cb, xtop, 0, 0, NULL, -1, 0) < 0)
|
||||
|
|
@ -537,7 +536,7 @@ cli_dbxml(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
cli_set(clicon_handle h,
|
||||
cli_set(clixon_handle h,
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
{
|
||||
|
|
@ -559,7 +558,7 @@ cli_set(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
cli_merge(clicon_handle h,
|
||||
cli_merge(clixon_handle h,
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
{
|
||||
|
|
@ -581,7 +580,7 @@ cli_merge(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
cli_create(clicon_handle h,
|
||||
cli_create(clixon_handle h,
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
{
|
||||
|
|
@ -604,7 +603,7 @@ cli_create(clicon_handle h,
|
|||
* @see cli_del
|
||||
*/
|
||||
int
|
||||
cli_remove(clicon_handle h,
|
||||
cli_remove(clixon_handle h,
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
{
|
||||
|
|
@ -626,7 +625,7 @@ cli_remove(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
cli_del(clicon_handle h,
|
||||
cli_del(clixon_handle h,
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
{
|
||||
|
|
@ -650,7 +649,7 @@ cli_del(clicon_handle h,
|
|||
* _or_ if a 'level' variable is present in cvv use that value instead.
|
||||
*/
|
||||
int
|
||||
cli_debug_cli(clicon_handle h,
|
||||
cli_debug_cli(clixon_handle h,
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
{
|
||||
|
|
@ -660,14 +659,14 @@ cli_debug_cli(clicon_handle h,
|
|||
|
||||
if ((cv = cvec_find_var(cvv, "level")) == NULL){
|
||||
if (cvec_len(argv) != 1){
|
||||
clicon_err(OE_PLUGIN, EINVAL, "Requires either label var or single arg: 0|1");
|
||||
clixon_err(OE_PLUGIN, EINVAL, "Requires either label var or single arg: 0|1");
|
||||
goto done;
|
||||
}
|
||||
cv = cvec_i(argv, 0);
|
||||
}
|
||||
level = cv_int32_get(cv);
|
||||
/* cli */
|
||||
clixon_debug_init(level, NULL); /* 0: dont debug, 1:debug */
|
||||
clixon_debug_init(h, level); /* 0: dont debug, 1:debug */
|
||||
retval = 0;
|
||||
done:
|
||||
return retval;
|
||||
|
|
@ -684,7 +683,7 @@ cli_debug_cli(clicon_handle h,
|
|||
* _or_ if a 'level' variable is present in cvv use that value instead.
|
||||
*/
|
||||
int
|
||||
cli_debug_backend(clicon_handle h,
|
||||
cli_debug_backend(clixon_handle h,
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
{
|
||||
|
|
@ -694,7 +693,7 @@ cli_debug_backend(clicon_handle h,
|
|||
|
||||
if ((cv = cvec_find_var(cvv, "level")) == NULL){
|
||||
if (cvec_len(argv) != 1){
|
||||
clicon_err(OE_PLUGIN, EINVAL, "Requires either label var or single arg: 0|1");
|
||||
clixon_err(OE_PLUGIN, EINVAL, "Requires either label var or single arg: 0|1");
|
||||
goto done;
|
||||
}
|
||||
cv = cvec_i(argv, 0);
|
||||
|
|
@ -721,7 +720,7 @@ cli_debug_backend(clicon_handle h,
|
|||
* 3 CLICON_BACKEND_RESTCONF_PROCESS is true (so that backend restarts restconf)
|
||||
*/
|
||||
int
|
||||
cli_debug_restconf(clicon_handle h,
|
||||
cli_debug_restconf(clixon_handle h,
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
{
|
||||
|
|
@ -731,7 +730,7 @@ cli_debug_restconf(clicon_handle h,
|
|||
|
||||
if ((cv = cvec_find_var(cvv, "level")) == NULL){
|
||||
if (cvec_len(argv) != 1){
|
||||
clicon_err(OE_PLUGIN, EINVAL, "Requires either label var or single arg: 0|1");
|
||||
clixon_err(OE_PLUGIN, EINVAL, "Requires either label var or single arg: 0|1");
|
||||
goto done;
|
||||
}
|
||||
cv = cvec_i(argv, 0);
|
||||
|
|
@ -753,7 +752,7 @@ cli_debug_restconf(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
cli_set_mode(clicon_handle h,
|
||||
cli_set_mode(clixon_handle h,
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
{
|
||||
|
|
@ -761,7 +760,7 @@ cli_set_mode(clicon_handle h,
|
|||
char *str = NULL;
|
||||
|
||||
if (cvec_len(argv) != 1){
|
||||
clicon_err(OE_PLUGIN, EINVAL, "Requires one element to be cli mode");
|
||||
clixon_err(OE_PLUGIN, EINVAL, "Requires one element to be cli mode");
|
||||
goto done;
|
||||
}
|
||||
str = cv_string_get(cvec_i(argv, 0));
|
||||
|
|
@ -781,7 +780,7 @@ cli_set_mode(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
cli_start_shell(clicon_handle h,
|
||||
cli_start_shell(clixon_handle h,
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
{
|
||||
|
|
@ -795,7 +794,7 @@ cli_start_shell(clicon_handle h,
|
|||
struct sigaction oldsigaction[32] = {{{0,},},};
|
||||
|
||||
if (cvec_len(argv) > 1){
|
||||
clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: [<shell>]",
|
||||
clixon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: [<shell>]",
|
||||
cvec_len(argv));
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -804,11 +803,11 @@ cli_start_shell(clicon_handle h,
|
|||
}
|
||||
cmd = (cvec_len(cvv)>1 ? cv_string_get(cv1) : NULL);
|
||||
if ((pw = getpwuid(getuid())) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "getpwuid");
|
||||
clixon_err(OE_UNIX, errno, "getpwuid");
|
||||
goto done;
|
||||
}
|
||||
if (chdir(pw->pw_dir) < 0){
|
||||
clicon_err(OE_UNIX, errno, "chdir");
|
||||
clixon_err(OE_UNIX, errno, "chdir");
|
||||
endpwent();
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -822,7 +821,7 @@ cli_start_shell(clicon_handle h,
|
|||
snprintf(bcmd, 128, "%s -c \"%s\"", shcmd, cmd);
|
||||
if (system(bcmd) < 0){
|
||||
cli_signal_block(h);
|
||||
clicon_err(OE_UNIX, errno, "system(bash -c)");
|
||||
clixon_err(OE_UNIX, errno, "system(bash -c)");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -830,14 +829,14 @@ cli_start_shell(clicon_handle h,
|
|||
snprintf(bcmd, 128, "%s ", shcmd); /* -l (login shell) but is applicable to bash only */
|
||||
if (system(bcmd) < 0){
|
||||
cli_signal_block(h);
|
||||
clicon_err(OE_UNIX, errno, "system(bash)");
|
||||
clixon_err(OE_UNIX, errno, "system(bash)");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
cli_signal_block(h);
|
||||
#if 0 /* Allow errcodes from bash */
|
||||
if (retval != 0){
|
||||
clicon_err(OE_UNIX, errno, "system(%s) %d", cmd, retval);
|
||||
clixon_err(OE_UNIX, errno, "system(%s) %d", cmd, retval);
|
||||
goto done;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -857,7 +856,7 @@ cli_start_shell(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
cli_quit(clicon_handle h,
|
||||
cli_quit(clixon_handle h,
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
{
|
||||
|
|
@ -874,7 +873,7 @@ cli_quit(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
cli_commit(clicon_handle h,
|
||||
cli_commit(clixon_handle h,
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
{
|
||||
|
|
@ -909,7 +908,7 @@ cli_commit(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
cli_validate(clicon_handle h,
|
||||
cli_validate(clixon_handle h,
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
{
|
||||
|
|
@ -932,7 +931,7 @@ cli_validate(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
compare_db_names(clicon_handle h,
|
||||
compare_db_names(clixon_handle h,
|
||||
enum format_enum format,
|
||||
char *db1,
|
||||
char *db2)
|
||||
|
|
@ -946,13 +945,23 @@ compare_db_names(clicon_handle h,
|
|||
if (clicon_rpc_get_config(h, NULL, db1, "/", NULL, NULL, &xc1) < 0)
|
||||
goto done;
|
||||
if ((xerr = xpath_first(xc1, NULL, "/rpc-error")) != NULL){
|
||||
#if 1
|
||||
if (clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Get configuration") < 0)
|
||||
goto done;
|
||||
#else
|
||||
clixon_netconf_error(h, xerr, "Get configuration", NULL);
|
||||
#endif
|
||||
goto done;
|
||||
}
|
||||
if (clicon_rpc_get_config(h, NULL, db2, "/", NULL, NULL, &xc2) < 0)
|
||||
goto done;
|
||||
if ((xerr = xpath_first(xc2, NULL, "/rpc-error")) != NULL){
|
||||
#if 1
|
||||
if (clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Get configuration") < 0)
|
||||
goto done;
|
||||
#else
|
||||
clixon_netconf_error(h, xerr, "Get configuration", NULL);
|
||||
#endif
|
||||
goto done;
|
||||
}
|
||||
/* Note that XML and TEXT uses a (new) structured in-mem algorithm while
|
||||
|
|
@ -961,7 +970,7 @@ compare_db_names(clicon_handle h,
|
|||
switch (format){
|
||||
case FORMAT_XML:
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if (clixon_xml_diff2cbuf(cb, xc1, xc2) < 0)
|
||||
|
|
@ -970,7 +979,7 @@ compare_db_names(clicon_handle h,
|
|||
break;
|
||||
case FORMAT_TEXT:
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if (clixon_text_diff2cbuf(cb, xc1, xc2) < 0)
|
||||
|
|
@ -1004,7 +1013,7 @@ compare_db_names(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
compare_dbs(clicon_handle h,
|
||||
compare_dbs(clixon_handle h,
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
{
|
||||
|
|
@ -1015,14 +1024,14 @@ compare_dbs(clicon_handle h,
|
|||
char *formatstr;
|
||||
|
||||
if (cvec_len(argv) != 3){
|
||||
clicon_err(OE_PLUGIN, EINVAL, "Expected arguments: <db1> <db2> <format>");
|
||||
clixon_err(OE_PLUGIN, EINVAL, "Expected arguments: <db1> <db2> <format>");
|
||||
goto done;
|
||||
}
|
||||
db1 = cv_string_get(cvec_i(argv, 0));
|
||||
db2 = cv_string_get(cvec_i(argv, 1));
|
||||
formatstr = cv_string_get(cvec_i(argv, 2));
|
||||
if ((format = format_str2int(formatstr)) < 0){
|
||||
clicon_err(OE_XML, 0, "format not found %s", formatstr);
|
||||
clixon_err(OE_XML, 0, "format not found %s", formatstr);
|
||||
goto done;
|
||||
}
|
||||
if (compare_db_names(h, format, db1, db2) < 0)
|
||||
|
|
@ -1054,7 +1063,7 @@ compare_dbs(clicon_handle h,
|
|||
* @see save_config_file
|
||||
*/
|
||||
int
|
||||
load_config_file(clicon_handle h,
|
||||
load_config_file(clixon_handle h,
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
{
|
||||
|
|
@ -1076,18 +1085,18 @@ load_config_file(clicon_handle h,
|
|||
char *lineptr = NULL;
|
||||
|
||||
if (cvec_len(argv) < 2 || cvec_len(argv) > 4){
|
||||
clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: <dbname>,<varname>[,<format>]",
|
||||
clixon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: <dbname>,<varname>[,<format>]",
|
||||
cvec_len(argv));
|
||||
goto done;
|
||||
}
|
||||
if ((yspec = clicon_dbspec_yang(h)) == NULL){
|
||||
clicon_err(OE_FATAL, 0, "No DB_SPEC");
|
||||
clixon_err(OE_FATAL, 0, "No DB_SPEC");
|
||||
goto done;
|
||||
}
|
||||
if (cvec_len(argv) > 2){
|
||||
formatstr = cv_string_get(cvec_i(argv, 2));
|
||||
if ((int)(format = format_str2int(formatstr)) < 0){
|
||||
clicon_err(OE_PLUGIN, 0, "Not valid format: %s", formatstr);
|
||||
clixon_err(OE_PLUGIN, 0, "Not valid format: %s", formatstr);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -1098,21 +1107,21 @@ load_config_file(clicon_handle h,
|
|||
else if (strcmp(opstr, "replace") == 0)
|
||||
replace = 1;
|
||||
else{
|
||||
clicon_err(OE_PLUGIN, 0, "No such op: %s, expected merge or replace", opstr);
|
||||
clixon_err(OE_PLUGIN, 0, "No such op: %s, expected merge or replace", opstr);
|
||||
goto done;
|
||||
}
|
||||
if ((cv = cvec_find(cvv, varstr)) == NULL){
|
||||
clicon_err(OE_PLUGIN, 0, "No such var name: %s", varstr);
|
||||
clixon_err(OE_PLUGIN, 0, "No such var name: %s", varstr);
|
||||
goto done;
|
||||
}
|
||||
filename = cv_string_get(cv);
|
||||
if (stat(filename, &st) < 0){
|
||||
clicon_err(OE_UNIX, errno, "load_config: stat(%s)", filename);
|
||||
clixon_err(OE_UNIX, errno, "load_config: stat(%s)", filename);
|
||||
goto done;
|
||||
}
|
||||
/* Open and parse local file into xml */
|
||||
if ((fp = fopen(filename, "r")) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "fopen(%s)", filename);
|
||||
clixon_err(OE_UNIX, errno, "fopen(%s)", filename);
|
||||
goto done;
|
||||
}
|
||||
switch (format){
|
||||
|
|
@ -1120,7 +1129,12 @@ load_config_file(clicon_handle h,
|
|||
if ((ret = clixon_xml_parse_file(fp, YB_NONE, yspec, &xt, &xerr)) < 0)
|
||||
goto done;
|
||||
if (ret == 0){
|
||||
#if 1
|
||||
if (clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Loading %s", filename) < 0)
|
||||
goto done;
|
||||
#else
|
||||
clixon_netconf_error(h, xerr, "Loading", filename);
|
||||
#endif
|
||||
goto done;
|
||||
}
|
||||
break;
|
||||
|
|
@ -1128,7 +1142,12 @@ load_config_file(clicon_handle h,
|
|||
if ((ret = clixon_json_parse_file(fp, 1, YB_NONE, yspec, &xt, &xerr)) < 0)
|
||||
goto done;
|
||||
if (ret == 0){
|
||||
#if 1
|
||||
if (clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Loading %s", filename) < 0)
|
||||
goto done;
|
||||
#else
|
||||
clixon_netconf_error(h, xerr, "Loading", filename);
|
||||
#endif
|
||||
goto done;
|
||||
}
|
||||
break;
|
||||
|
|
@ -1139,7 +1158,12 @@ load_config_file(clicon_handle h,
|
|||
if ((ret = clixon_text_syntax_parse_file(fp, YB_MODULE_NEXT, yspec, &xt, &xerr)) < 0)
|
||||
goto done;
|
||||
if (ret == 0){
|
||||
#if 1
|
||||
if (clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Loading %s", filename) < 0)
|
||||
goto done;
|
||||
#else
|
||||
clixon_netconf_error(h, xerr, "Loading", filename);
|
||||
#endif
|
||||
goto done;
|
||||
}
|
||||
break;
|
||||
|
|
@ -1154,7 +1178,7 @@ load_config_file(clicon_handle h,
|
|||
lineptr = NULL; n = 0;
|
||||
if (getline(&lineptr, &n, fp) < 0){
|
||||
if (errno){
|
||||
clicon_err(OE_UNIX, errno, "getline");
|
||||
clixon_err(OE_UNIX, errno, "getline");
|
||||
goto done;
|
||||
}
|
||||
goto ok; /* eof, skip backend rpc since this is done by cli code */
|
||||
|
|
@ -1173,16 +1197,18 @@ load_config_file(clicon_handle h,
|
|||
break;
|
||||
}
|
||||
default:
|
||||
clicon_err(OE_PLUGIN, 0, "format: %s not implemented", formatstr);
|
||||
clixon_err(OE_PLUGIN, 0, "format: %s not implemented", formatstr);
|
||||
goto done;
|
||||
break;
|
||||
}
|
||||
if (xt == NULL)
|
||||
goto done;
|
||||
if ((cbxml = cbuf_new()) == NULL)
|
||||
if ((cbxml = cbuf_new()) == NULL){
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
x = NULL;
|
||||
while ((x = xml_child_each(xt, x, -1)) != NULL) {
|
||||
while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL) {
|
||||
/* Read as datastore-top but transformed into an edit-config "config" */
|
||||
xml_name_set(x, NETCONF_INPUT_CONFIG);
|
||||
}
|
||||
|
|
@ -1228,7 +1254,7 @@ load_config_file(clicon_handle h,
|
|||
* @see load_config_file
|
||||
*/
|
||||
int
|
||||
save_config_file(clicon_handle h,
|
||||
save_config_file(clixon_handle h,
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
{
|
||||
|
|
@ -1246,14 +1272,14 @@ save_config_file(clicon_handle h,
|
|||
int pretty = 1; /* XXX hardcoded */
|
||||
|
||||
if (cvec_len(argv) < 2 || cvec_len(argv) > 4){
|
||||
clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: <dbname>,<varname>[,<format>]",
|
||||
clixon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: <dbname>,<varname>[,<format>]",
|
||||
cvec_len(argv));
|
||||
goto done;
|
||||
}
|
||||
if (cvec_len(argv) > 2){
|
||||
formatstr = cv_string_get(cvec_i(argv, 2));
|
||||
if ((int)(format = format_str2int(formatstr)) < 0){
|
||||
clicon_err(OE_PLUGIN, 0, "Not valid format: %s", formatstr);
|
||||
clixon_err(OE_PLUGIN, 0, "Not valid format: %s", formatstr);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -1261,23 +1287,28 @@ save_config_file(clicon_handle h,
|
|||
if (strcmp(dbstr, "running") != 0 &&
|
||||
strcmp(dbstr, "candidate") != 0 &&
|
||||
strcmp(dbstr, "startup") != 0) {
|
||||
clicon_err(OE_PLUGIN, 0, "No such db name: %s", dbstr);
|
||||
clixon_err(OE_PLUGIN, 0, "No such db name: %s", dbstr);
|
||||
goto done;
|
||||
}
|
||||
varstr = cv_string_get(cvec_i(argv, 1));
|
||||
if ((cv = cvec_find(cvv, varstr)) == NULL){
|
||||
clicon_err(OE_PLUGIN, 0, "No such var name: %s", varstr);
|
||||
clixon_err(OE_PLUGIN, 0, "No such var name: %s", varstr);
|
||||
goto done;
|
||||
}
|
||||
filename = cv_string_get(cv);
|
||||
if (clicon_rpc_get_config(h, NULL, dbstr,"/", NULL, NULL, &xt) < 0)
|
||||
goto done;
|
||||
if (xt == NULL){
|
||||
clicon_err(OE_CFG, 0, "get config: empty tree"); /* Shouldnt happen */
|
||||
clixon_err(OE_CFG, 0, "get config: empty tree"); /* Shouldnt happen */
|
||||
goto done;
|
||||
}
|
||||
if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){
|
||||
#if 1
|
||||
if (clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Get configuration") < 0)
|
||||
goto done;
|
||||
#else
|
||||
clixon_netconf_error(h, xerr, "Get configuration", NULL);
|
||||
#endif
|
||||
goto done;
|
||||
}
|
||||
/* get-config returns a <data> tree. Save as <config> tree so it can be used
|
||||
|
|
@ -1286,7 +1317,7 @@ save_config_file(clicon_handle h,
|
|||
if (xml_name_set(xt, DATASTORE_TOP_SYMBOL) < 0)
|
||||
goto done;
|
||||
if ((f = fopen(filename, "w")) == NULL){
|
||||
clicon_err(OE_CFG, errno, "Creating file %s", filename);
|
||||
clixon_err(OE_CFG, errno, "Creating file %s", filename);
|
||||
goto done;
|
||||
}
|
||||
switch (format){
|
||||
|
|
@ -1335,7 +1366,7 @@ save_config_file(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
delete_all(clicon_handle h,
|
||||
delete_all(clixon_handle h,
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
{
|
||||
|
|
@ -1343,14 +1374,14 @@ delete_all(clicon_handle h,
|
|||
int retval = -1;
|
||||
|
||||
if (cvec_len(argv) != 1){
|
||||
clicon_err(OE_PLUGIN, EINVAL, "Requires one element: dbname");
|
||||
clixon_err(OE_PLUGIN, EINVAL, "Requires one element: dbname");
|
||||
goto done;
|
||||
}
|
||||
dbstr = cv_string_get(cvec_i(argv, 0));
|
||||
if (strcmp(dbstr, "running") != 0 &&
|
||||
strcmp(dbstr, "candidate") != 0 &&
|
||||
strcmp(dbstr, "startup") != 0){
|
||||
clicon_err(OE_PLUGIN, 0, "No such db name: %s", dbstr);
|
||||
clixon_err(OE_PLUGIN, 0, "No such db name: %s", dbstr);
|
||||
goto done;
|
||||
}
|
||||
if (clicon_rpc_delete_config(h, dbstr) < 0)
|
||||
|
|
@ -1363,7 +1394,7 @@ delete_all(clicon_handle h,
|
|||
/*! Discard all changes in candidate and replace with running
|
||||
*/
|
||||
int
|
||||
discard_changes(clicon_handle h,
|
||||
discard_changes(clixon_handle h,
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
{
|
||||
|
|
@ -1377,7 +1408,7 @@ discard_changes(clicon_handle h,
|
|||
* @retval -1 Error and logged to syslog
|
||||
*/
|
||||
int
|
||||
db_copy(clicon_handle h,
|
||||
db_copy(clixon_handle h,
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
{
|
||||
|
|
@ -1411,7 +1442,7 @@ cli_notification_cb(int s,
|
|||
if (clicon_msg_rcv(s, NULL, 0, &reply, &eof) < 0)
|
||||
goto done;
|
||||
if (eof){
|
||||
clicon_err(OE_PROTO, ESHUTDOWN, "Socket unexpected close");
|
||||
clixon_err(OE_PROTO, ESHUTDOWN, "Socket unexpected close");
|
||||
close(s);
|
||||
errno = ESHUTDOWN;
|
||||
clixon_event_unreg_fd(s, cli_notification_cb);
|
||||
|
|
@ -1421,7 +1452,7 @@ cli_notification_cb(int s,
|
|||
if ((ret = clicon_msg_decode(reply, NULL, NULL, &xt, NULL)) < 0)
|
||||
goto done;
|
||||
if (ret == 0){ /* will not happen since no yspec ^*/
|
||||
clicon_err(OE_NETCONF, EFAULT, "Notification malformed");
|
||||
clixon_err(OE_NETCONF, EFAULT, "Notification malformed");
|
||||
goto done;
|
||||
}
|
||||
switch (format){
|
||||
|
|
@ -1464,7 +1495,7 @@ cli_notification_cb(int s,
|
|||
* XXX: format is a memory leak
|
||||
*/
|
||||
int
|
||||
cli_notify(clicon_handle h,
|
||||
cli_notify(clixon_handle h,
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
{
|
||||
|
|
@ -1475,7 +1506,7 @@ cli_notify(clicon_handle h,
|
|||
enum format_enum format = FORMAT_TEXT;
|
||||
|
||||
if (cvec_len(argv) != 2 && cvec_len(argv) != 3){
|
||||
clicon_err(OE_PLUGIN, EINVAL, "Requires arguments: <logstream> <status> [<format>]");
|
||||
clixon_err(OE_PLUGIN, EINVAL, "Requires arguments: <logstream> <status> [<format>]");
|
||||
goto done;
|
||||
}
|
||||
stream = cv_string_get(cvec_i(argv, 0));
|
||||
|
|
@ -1511,7 +1542,7 @@ cli_notify(clicon_handle h,
|
|||
* XXX: format is a memory leak
|
||||
*/
|
||||
int
|
||||
cli_lock(clicon_handle h,
|
||||
cli_lock(clixon_handle h,
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
{
|
||||
|
|
@ -1519,7 +1550,7 @@ cli_lock(clicon_handle h,
|
|||
char *db;
|
||||
|
||||
if (cvec_len(argv) != 1){
|
||||
clicon_err(OE_PLUGIN, EINVAL, "Requires arguments: <db>");
|
||||
clixon_err(OE_PLUGIN, EINVAL, "Requires arguments: <db>");
|
||||
goto done;
|
||||
}
|
||||
db = cv_string_get(cvec_i(argv, 0));
|
||||
|
|
@ -1543,7 +1574,7 @@ cli_lock(clicon_handle h,
|
|||
* XXX: format is a memory leak
|
||||
*/
|
||||
int
|
||||
cli_unlock(clicon_handle h,
|
||||
cli_unlock(clixon_handle h,
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
{
|
||||
|
|
@ -1551,7 +1582,7 @@ cli_unlock(clicon_handle h,
|
|||
char *db;
|
||||
|
||||
if (cvec_len(argv) != 1){
|
||||
clicon_err(OE_PLUGIN, EINVAL, "Requires arguments: <db>");
|
||||
clixon_err(OE_PLUGIN, EINVAL, "Requires arguments: <db>");
|
||||
goto done;
|
||||
}
|
||||
db = cv_string_get(cvec_i(argv, 0));
|
||||
|
|
@ -1589,7 +1620,7 @@ cli_unlock(clicon_handle h,
|
|||
* @endcode
|
||||
*/
|
||||
int
|
||||
cli_copy_config(clicon_handle h,
|
||||
cli_copy_config(clixon_handle h,
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
{
|
||||
|
|
@ -1615,7 +1646,7 @@ cli_copy_config(clicon_handle h,
|
|||
size_t len;
|
||||
|
||||
if (cvec_len(argv) != 6){
|
||||
clicon_err(OE_PLUGIN, EINVAL, "Requires 6 elements: <db> <xpath> <namespace> <keyname> <from> <to>");
|
||||
clixon_err(OE_PLUGIN, EINVAL, "Requires 6 elements: <db> <xpath> <namespace> <keyname> <from> <to>");
|
||||
goto done;
|
||||
}
|
||||
/* First argv argument: Database */
|
||||
|
|
@ -1633,14 +1664,14 @@ cli_copy_config(clicon_handle h,
|
|||
|
||||
/* Get from variable -> cv -> from name */
|
||||
if ((fromcv = cvec_find(cvv, fromvar)) == NULL){
|
||||
clicon_err(OE_PLUGIN, 0, "fromvar '%s' not found in cligen var list", fromvar);
|
||||
clixon_err(OE_PLUGIN, 0, "fromvar '%s' not found in cligen var list", fromvar);
|
||||
goto done;
|
||||
}
|
||||
/* Get from name from cv */
|
||||
fromname = cv_string_get(fromcv);
|
||||
/* Create xpath */
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_PLUGIN, errno, "cbuf_new");
|
||||
clixon_err(OE_PLUGIN, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
/* Sanity check that xpath contains exactly two %s, ie [%s='%s'] */
|
||||
|
|
@ -1651,7 +1682,7 @@ cli_copy_config(clicon_handle h,
|
|||
j++;
|
||||
}
|
||||
if (j != 2){
|
||||
clicon_err(OE_PLUGIN, 0, "xpath '%s' does not have two '%%'", xpath);
|
||||
clixon_err(OE_PLUGIN, 0, "xpath '%s' does not have two '%%'", xpath);
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, xpath, keyname, fromname);
|
||||
|
|
@ -1661,13 +1692,18 @@ cli_copy_config(clicon_handle h,
|
|||
if (clicon_rpc_get_config(h, NULL, db, cbuf_get(cb), nsc, NULL, &x1) < 0)
|
||||
goto done;
|
||||
if ((xerr = xpath_first(x1, NULL, "/rpc-error")) != NULL){
|
||||
#if 1
|
||||
if (clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Get configuration") < 0)
|
||||
goto done;
|
||||
#else
|
||||
clixon_netconf_error(h, xerr, "Get configuration", NULL);
|
||||
#endif
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Get to variable -> cv -> to name */
|
||||
if ((tocv = cvec_find(cvv, tovar)) == NULL){
|
||||
clicon_err(OE_PLUGIN, 0, "tovar '%s' not found in cligen var list", tovar);
|
||||
clixon_err(OE_PLUGIN, 0, "tovar '%s' not found in cligen var list", tovar);
|
||||
goto done;
|
||||
}
|
||||
toname = cv_string_get(tocv);
|
||||
|
|
@ -1679,7 +1715,7 @@ cli_copy_config(clicon_handle h,
|
|||
xml_name_set(x2, NETCONF_INPUT_CONFIG);
|
||||
cprintf(cb, "/%s", keyname);
|
||||
if ((x = xpath_first(x2, nsc, "%s", cbuf_get(cb))) == NULL){
|
||||
clicon_err(OE_PLUGIN, 0, "Field %s not found in copy tree", keyname);
|
||||
clixon_err(OE_PLUGIN, 0, "Field %s not found in copy tree", keyname);
|
||||
goto done;
|
||||
}
|
||||
x = xml_find(x, "body");
|
||||
|
|
@ -1713,7 +1749,7 @@ cli_copy_config(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
cli_help(clicon_handle h,
|
||||
cli_help(clixon_handle h,
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
{
|
||||
|
|
@ -1736,7 +1772,7 @@ cli_help(clicon_handle h,
|
|||
* @endcode
|
||||
*/
|
||||
int
|
||||
cli_restart_plugin(clicon_handle h,
|
||||
cli_restart_plugin(clixon_handle h,
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
{
|
||||
|
|
@ -1746,7 +1782,7 @@ cli_restart_plugin(clicon_handle h,
|
|||
|
||||
if ((cv = cvec_find_var(cvv, "plugin")) == NULL){
|
||||
if (cvec_len(argv) != 1){
|
||||
clicon_err(OE_PLUGIN, EINVAL, "Requires plugin variable");
|
||||
clixon_err(OE_PLUGIN, EINVAL, "Requires plugin variable");
|
||||
goto done;
|
||||
}
|
||||
cv = cvec_i(argv, 0);
|
||||
|
|
@ -1770,13 +1806,13 @@ cvec_append(cvec *cvv0,
|
|||
|
||||
if (cvv0 == NULL){
|
||||
if ((cvv2 = cvec_dup(cvv1)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cvec_dup");
|
||||
clixon_err(OE_UNIX, errno, "cvec_dup");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else{
|
||||
if ((cvv2 = cvec_dup(cvv0)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cvec_dup");
|
||||
clixon_err(OE_UNIX, errno, "cvec_dup");
|
||||
return NULL;
|
||||
}
|
||||
cv = NULL; /* Append cvv1 to cvv2 */
|
||||
|
|
@ -1804,7 +1840,7 @@ cvec_concat_cb(cvec *cvv,
|
|||
int i;
|
||||
|
||||
if (cb == NULL){
|
||||
clicon_err(OE_PLUGIN, EINVAL, "cb is NULL");
|
||||
clixon_err(OE_PLUGIN, EINVAL, "cb is NULL");
|
||||
goto done;
|
||||
}
|
||||
/* Iterate through all api_path_fmt:s, assume they start with / */
|
||||
|
|
@ -1838,7 +1874,7 @@ cvec_concat_cb(cvec *cvv,
|
|||
* @endcode
|
||||
*/
|
||||
int
|
||||
cli_process_control(clicon_handle h,
|
||||
cli_process_control(clixon_handle h,
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
{
|
||||
|
|
@ -1850,17 +1886,17 @@ cli_process_control(clicon_handle h,
|
|||
cxobj *xerr;
|
||||
|
||||
if (cvec_len(argv) != 2){
|
||||
clicon_err(OE_PLUGIN, EINVAL, "Requires two element: process name and operation");
|
||||
clixon_err(OE_PLUGIN, EINVAL, "Requires two element: process name and operation");
|
||||
goto done;
|
||||
}
|
||||
name = cv_string_get(cvec_i(argv, 0));
|
||||
opstr = cv_string_get(cvec_i(argv, 1));
|
||||
if (clixon_process_op_str2int(opstr) == -1){
|
||||
clicon_err(OE_UNIX, 0, "No such process op: %s", opstr);
|
||||
clixon_err(OE_UNIX, 0, "No such process op: %s", opstr);
|
||||
goto done;
|
||||
}
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "<rpc xmlns=\"%s\"", NETCONF_BASE_NAMESPACE);
|
||||
|
|
@ -1874,7 +1910,7 @@ cli_process_control(clicon_handle h,
|
|||
if (clicon_rpc_netconf(h, cbuf_get(cb), &xret, NULL) < 0)
|
||||
goto done;
|
||||
if ((xerr = xpath_first(xret, NULL, "//rpc-error")) != NULL){
|
||||
clixon_netconf_error(h, xerr, "Get configuration", NULL);
|
||||
clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Get configuration");
|
||||
goto done;
|
||||
}
|
||||
if (clixon_xml2file(stdout, xml_child_i(xret, 0), 0, 1, NULL, cligen_output, 0, 1) < 0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue