Merge branch 'master' into develop

This commit is contained in:
Olof hagsand 2017-09-27 18:22:11 +02:00
commit c74cdda1e8
6 changed files with 31 additions and 30 deletions

View file

@ -538,10 +538,8 @@ cli_commit(clicon_handle h,
{
int retval = -1;
if ((retval = clicon_rpc_commit(h)) < 0){ /* startup */
cli_output(stderr, "Commit failed. Edit and try again or discard changes");
if ((retval = clicon_rpc_commit(h)) < 0)
goto done;
}
retval = 0;
done:
return retval;
@ -659,13 +657,13 @@ compare_dbs(clicon_handle h,
if (clicon_rpc_get_config(h, "running", "/", &xc1) < 0)
goto done;
if ((xerr = xpath_first(xc1, "/rpc-error")) != NULL){
clicon_rpc_generate_error(xerr);
clicon_rpc_generate_error("Get configuration", xerr);
goto done;
}
if (clicon_rpc_get_config(h, "candidate", "/", &xc2) < 0)
goto done;
if ((xerr = xpath_first(xc2, "/rpc-error")) != NULL){
clicon_rpc_generate_error(xerr);
clicon_rpc_generate_error("Get configuration", xerr);
goto done;
}
if (compare_xmls(xc1, xc2, astext) < 0) /* astext? */
@ -836,7 +834,7 @@ save_config_file(clicon_handle h,
if (clicon_rpc_get_config(h, dbstr,"/", &xt) < 0)
goto done;
if ((xerr = xpath_first(xt, "/rpc-error")) != NULL){
clicon_rpc_generate_error(xerr);
clicon_rpc_generate_error("Get configuration", xerr);
goto done;
}
if ((f = fopen(filename, "wb")) == NULL){
@ -1180,7 +1178,7 @@ cli_copy_config(clicon_handle h,
if (clicon_rpc_get_config(h, db, cbuf_get(cb), &x1) < 0)
goto done;
if ((xerr = xpath_first(x1, "/rpc-error")) != NULL){
clicon_rpc_generate_error(xerr);
clicon_rpc_generate_error("Get configuration", xerr);
goto done;
}

View file

@ -568,7 +568,6 @@ cli_handler_err(FILE *f)
if (clicon_suberrno)
cli_output(f, ": %s", strerror(clicon_suberrno));
cli_output(f, "\n");
}
else
cli_output(f, "CLI command error\n");

View file

@ -156,7 +156,7 @@ expand_dbvar(void *h,
if (clicon_rpc_get_config(h, dbstr, "/", &xt) < 0)
goto done;
if ((xerr = xpath_first(xt, "/rpc-error")) != NULL){
clicon_rpc_generate_error(xerr);
clicon_rpc_generate_error("Get configuration", xerr);
goto done;
}
xcur = xt; /* default top-of-tree */
@ -481,7 +481,7 @@ cli_show_config(clicon_handle h,
if (clicon_rpc_get_config(h, db, cbuf_get(cbxpath), &xt) < 0)
goto done;
if ((xerr = xpath_first(xt, "/rpc-error")) != NULL){
clicon_rpc_generate_error(xerr);
clicon_rpc_generate_error("Get configuration", xerr);
goto done;
}
/* Print configuration according to format */
@ -565,7 +565,7 @@ show_conf_xpath(clicon_handle h,
if (clicon_rpc_get_config(h, str, xpath, &xt) < 0)
goto done;
if ((xerr = xpath_first(xt, "/rpc-error")) != NULL){
clicon_rpc_generate_error(xerr);
clicon_rpc_generate_error("Get configuration", xerr);
goto done;
}
if (xpath_vec(xt, xpath, &xv, &xlen) < 0)

View file

@ -44,7 +44,7 @@ int clicon_rpc_msg(clicon_handle h, struct clicon_msg *msg, cxobj **xret0,
int *sock0);
int clicon_rpc_netconf(clicon_handle h, char *xmlst, cxobj **xret, int *sp);
int clicon_rpc_netconf_xml(clicon_handle h, cxobj *xml, cxobj **xret, int *sp);
int clicon_rpc_generate_error(cxobj *xerr);
int clicon_rpc_generate_error(char *format, cxobj *xerr);
int clicon_rpc_get_config(clicon_handle h, char *db, char *xpath, cxobj **xret);
int clicon_rpc_edit_config(clicon_handle h, char *db, enum operation_type op,
char *xml);

View file

@ -280,6 +280,11 @@ clicon_option_default(clicon_hash_t *copt)
if (hash_add(copt, "CLICON_CLI_LINESCROLLING", "1", strlen("1")+1) < 0)
goto done;
}
/* Default is to use line-scrolling */
if (!hash_lookup(copt, "CLICON_CLI_LINESCROLLING")){
if (hash_add(copt, "CLICON_CLI_LINESCROLLING", "1", strlen("1")+1) < 0)
goto catch;
}
retval = 0;
done:
return retval;

View file

@ -199,7 +199,8 @@ clicon_rpc_netconf_xml(clicon_handle h,
* @param[in] xerr Netconf error message on the level: <rpc-reply><rpc-error>
*/
int
clicon_rpc_generate_error(cxobj *xerr)
clicon_rpc_generate_error(char *format,
cxobj *xerr)
{
int retval = -1;
cbuf *cb = NULL;
@ -217,7 +218,7 @@ clicon_rpc_generate_error(cxobj *xerr)
cprintf(cb, "%s ", xml_body(x));
if ((x=xpath_first(xerr, "error-info"))!=NULL)
clicon_xml2cbuf(cb, xml_child_i(x,0), 0, 0);
clicon_err_fn("Clixon", 0, OE_XML, 0, "%s", cbuf_get(cb));
clicon_log(LOG_ERR, "%s: %s", format, cbuf_get(cb));
retval = 0;
done:
if (cb)
@ -239,7 +240,7 @@ clicon_rpc_generate_error(cxobj *xerr)
* if (clicon_rpc_get_config(h, "running", "/", &xt) < 0)
* err;
* if ((xerr = xpath_first(xt, "/rpc-error")) != NULL){
* clicon_rpc_generate_error(xerr);
* clicon_rpc_generate_error("", xerr);
* err;
* }
* if (xt)
@ -330,7 +331,7 @@ clicon_rpc_edit_config(clicon_handle h,
if (clicon_rpc_msg(h, msg, &xret, NULL) < 0)
goto done;
if ((xerr = xpath_first(xret, "//rpc-error")) != NULL){
clicon_rpc_generate_error(xerr);
clicon_rpc_generate_error("Editing configuration", xerr);
goto done;
}
retval = 0;
@ -370,7 +371,7 @@ clicon_rpc_copy_config(clicon_handle h,
if (clicon_rpc_msg(h, msg, &xret, NULL) < 0)
goto done;
if ((xerr = xpath_first(xret, "//rpc-error")) != NULL){
clicon_rpc_generate_error(xerr);
clicon_rpc_generate_error("Copying configuration", xerr);
goto done;
}
retval = 0;
@ -404,7 +405,7 @@ clicon_rpc_delete_config(clicon_handle h,
if (clicon_rpc_msg(h, msg, &xret, NULL) < 0)
goto done;
if ((xerr = xpath_first(xret, "//rpc-error")) != NULL){
clicon_rpc_generate_error(xerr);
clicon_rpc_generate_error("Deleting configuration", xerr);
goto done;
}
retval = 0;
@ -434,7 +435,7 @@ clicon_rpc_lock(clicon_handle h,
if (clicon_rpc_msg(h, msg, &xret, NULL) < 0)
goto done;
if ((xerr = xpath_first(xret, "//rpc-error")) != NULL){
clicon_rpc_generate_error(xerr);
clicon_rpc_generate_error("Locking configuration", xerr);
goto done;
}
retval = 0;
@ -464,7 +465,7 @@ clicon_rpc_unlock(clicon_handle h,
if (clicon_rpc_msg(h, msg, &xret, NULL) < 0)
goto done;
if ((xerr = xpath_first(xret, "//rpc-error")) != NULL){
clicon_rpc_generate_error(xerr);
clicon_rpc_generate_error("Configuration unlock", xerr);
goto done;
}
retval = 0;
@ -556,7 +557,7 @@ clicon_rpc_close_session(clicon_handle h)
if (clicon_rpc_msg(h, msg, &xret, NULL) < 0)
goto done;
if ((xerr = xpath_first(xret, "//rpc-error")) != NULL){
clicon_rpc_generate_error(xerr);
clicon_rpc_generate_error("Close session", xerr);
goto done;
}
retval = 0;
@ -586,7 +587,7 @@ clicon_rpc_kill_session(clicon_handle h,
if (clicon_rpc_msg(h, msg, &xret, NULL) < 0)
goto done;
if ((xerr = xpath_first(xret, "//rpc-error")) != NULL){
clicon_rpc_generate_error(xerr);
clicon_rpc_generate_error("Kill session", xerr);
goto done;
}
retval = 0;
@ -611,16 +612,14 @@ clicon_rpc_validate(clicon_handle h,
struct clicon_msg *msg = NULL;
cxobj *xret = NULL;
cxobj *xerr;
cxobj *x;
if ((msg = clicon_msg_encode("<rpc><validate><source><%s/></source></validate></rpc>", db)) == NULL)
goto done;
if (clicon_rpc_msg(h, msg, &xret, NULL) < 0)
goto done;
if ((xerr = xpath_first(xret, "//rpc-error")) != NULL){
x=xpath_first(xerr, "error-message");
clicon_log(LOG_ERR, "Validate failed: \"%s\". Edit and try again or discard changes", x?xml_body(x):"");
goto done;
clicon_rpc_generate_error("Validate failed. Edit and try again or discard changes", xerr);
goto done;
}
retval = 0;
done:
@ -648,7 +647,7 @@ clicon_rpc_commit(clicon_handle h)
if (clicon_rpc_msg(h, msg, &xret, NULL) < 0)
goto done;
if ((xerr = xpath_first(xret, "//rpc-error")) != NULL){
clicon_rpc_generate_error(xerr);
clicon_rpc_generate_error("Commit failed. Edit and try again or discard changes", xerr);
goto done;
}
retval = 0;
@ -677,7 +676,7 @@ clicon_rpc_discard_changes(clicon_handle h)
if (clicon_rpc_msg(h, msg, &xret, NULL) < 0)
goto done;
if ((xerr = xpath_first(xret, "//rpc-error")) != NULL){
clicon_rpc_generate_error(xerr);
clicon_rpc_generate_error("Discard changes", xerr);
goto done;
}
retval = 0;
@ -716,7 +715,7 @@ clicon_rpc_create_subscription(clicon_handle h,
if (clicon_rpc_msg(h, msg, &xret, s0) < 0)
goto done;
if ((xerr = xpath_first(xret, "//rpc-error")) != NULL){
clicon_rpc_generate_error(xerr);
clicon_rpc_generate_error("Create subscription", xerr);
goto done;
}
retval = 0;
@ -746,7 +745,7 @@ clicon_rpc_debug(clicon_handle h,
if (clicon_rpc_msg(h, msg, &xret, NULL) < 0)
goto done;
if ((xerr = xpath_first(xret, "//rpc-error")) != NULL){
clicon_rpc_generate_error(xerr);
clicon_rpc_generate_error("Debug",xerr);
goto done;
}
if (xpath_first(xret, "//rpc-reply/ok") == NULL){