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:
Olof hagsand 2023-11-13 10:12:52 +01:00
parent 261469be16
commit 24a4991ec8
199 changed files with 4668 additions and 4158 deletions

View file

@ -70,7 +70,7 @@
/* cligen */
#include <cligen/cligen.h>
/* clicon */
/* clixon */
#include <clixon/clixon.h>
#include "clixon_cli_api.h"
@ -113,7 +113,7 @@ co2apipath(cg_obj *co)
* code
*/
int
cli_auto_edit(clicon_handle h,
cli_auto_edit(clixon_handle h,
cvec *cvv1,
cvec *argv)
{
@ -130,7 +130,7 @@ cli_auto_edit(clicon_handle h,
char *mtpoint = NULL;
if (cvec_len(argv) != 2 && cvec_len(argv) != 3){
clicon_err(OE_PLUGIN, EINVAL, "Usage: %s(api_path_fmt>*, <treename>)", __FUNCTION__);
clixon_err(OE_PLUGIN, EINVAL, "Usage: %s(api_path_fmt>*, <treename>)", __FUNCTION__);
goto done;
}
api_path_fmt = cv_string_get(cvec_i(argv, argc++));
@ -144,7 +144,7 @@ cli_auto_edit(clicon_handle h,
treename = str;
/* Find current cligen tree */
if ((ph = cligen_ph_find(cli_cligen(h), treename)) == NULL){
clicon_err(OE_PLUGIN, 0, "No such parsetree header: %s", treename);
clixon_err(OE_PLUGIN, 0, "No such parsetree header: %s", treename);
goto done;
}
/* Find the matching cligen object
@ -156,19 +156,19 @@ cli_auto_edit(clicon_handle h,
(coorig = co->co_ref) != NULL)
cligen_ph_workpoint_set(ph, coorig);
else {
clicon_err(OE_YANG, EINVAL, "No workpoint found");
clixon_err(OE_YANG, EINVAL, "No workpoint found");
goto done;
}
}
else{
clicon_err(OE_YANG, EINVAL, "No workpoint found");
clixon_err(OE_YANG, EINVAL, "No workpoint found");
goto done;
}
if ((cvv2 = cvec_append(clicon_data_cvec_get(h, "cli-edit-cvv"), cvv1)) == NULL)
goto done;
/* API_path format */
if ((api_path_fmt = co2apipath(coorig)) == NULL){
clicon_err(OE_YANG, EINVAL, "No apipath found");
clixon_err(OE_YANG, EINVAL, "No apipath found");
goto done;
}
/* get api-path and xpath */
@ -180,7 +180,7 @@ cli_auto_edit(clicon_handle h,
if (mtpoint){
char *mtpoint2;
if ((mtpoint2 = strdup(mtpoint)) == NULL){
clicon_err(OE_UNIX, errno, "strdup");
clixon_err(OE_UNIX, errno, "strdup");
goto done;
}
if (clicon_data_set(h, "cli-edit-mtpoint", mtpoint2) < 0)
@ -191,7 +191,7 @@ cli_auto_edit(clicon_handle h,
if (co->co_filter){
cvec *cvv3;
if ((cvv3 = cvec_dup(co->co_filter)) == NULL){
clicon_err(OE_YANG, errno, "cvec_dup");
clixon_err(OE_YANG, errno, "cvec_dup");
goto done;
}
if (clicon_data_cvec_set(h, "cli-edit-filter", cvv3) < 0)
@ -215,7 +215,7 @@ cli_auto_edit(clicon_handle h,
* <treename> Name of generated cligen parse-tree, eg "datamodel"
*/
int
cli_auto_up(clicon_handle h,
cli_auto_up(clixon_handle h,
cvec *cvv,
cvec *argv)
{
@ -236,13 +236,13 @@ cli_auto_up(clicon_handle h,
cvec *cvv_filter = NULL;
if (cvec_len(argv) != 1){
clicon_err(OE_PLUGIN, EINVAL, "Usage: %s(<treename>)", __FUNCTION__);
clixon_err(OE_PLUGIN, EINVAL, "Usage: %s(<treename>)", __FUNCTION__);
goto done;
}
cv = cvec_i(argv, 0);
treename = cv_string_get(cv);
if ((ph = cligen_ph_find(cli_cligen(h), treename)) == NULL){
clicon_err(OE_PLUGIN, 0, "No such parsetree header: %s", treename);
clixon_err(OE_PLUGIN, 0, "No such parsetree header: %s", treename);
goto done;
}
if ((co0 = cligen_ph_workpoint_get(ph)) == NULL)
@ -313,7 +313,7 @@ cli_auto_up(clicon_handle h,
* <treename> Name of generated cligen parse-tree, eg "datamodel"
*/
int
cli_auto_top(clicon_handle h,
cli_auto_top(clixon_handle h,
cvec *cvv,
cvec *argv)
{
@ -325,7 +325,7 @@ cli_auto_top(clicon_handle h,
cv = cvec_i(argv, 0);
treename = cv_string_get(cv);
if ((ph = cligen_ph_find(cli_cligen(h), treename)) == NULL){
clicon_err(OE_PLUGIN, 0, "No such parsetree header: %s", treename);
clixon_err(OE_PLUGIN, 0, "No such parsetree header: %s", treename);
goto done;
}
cligen_ph_workpoint_set(ph, NULL);
@ -349,7 +349,7 @@ cli_auto_top(clicon_handle h,
* <api-path-fmt> Generated
*/
int
cli_auto_set(clicon_handle h,
cli_auto_set(clixon_handle h,
cvec *cvv,
cvec *argv)
{
@ -375,7 +375,7 @@ cli_auto_set(clicon_handle h,
* @retval -1 Error
*/
int
cli_auto_merge(clicon_handle h,
cli_auto_merge(clixon_handle h,
cvec *cvv,
cvec *argv)
{
@ -401,7 +401,7 @@ cli_auto_merge(clicon_handle h,
* @retval -1 Error
*/
int
cli_auto_create(clicon_handle h,
cli_auto_create(clixon_handle h,
cvec *cvv,
cvec *argv)
{
@ -427,7 +427,7 @@ cli_auto_create(clicon_handle h,
* @retval -1 Error
*/
int
cli_auto_del(clicon_handle h,
cli_auto_del(clixon_handle h,
cvec *cvv,
cvec *argv)
{
@ -492,7 +492,7 @@ cli_auto_findpt(cg_obj *co,
* @see cli_auto_edit
*/
int
cli_auto_sub_enter(clicon_handle h,
cli_auto_sub_enter(clixon_handle h,
cvec *cvv,
cvec *argv)
{
@ -508,7 +508,7 @@ cli_auto_sub_enter(clicon_handle h,
struct findpt_arg fa = {0,};
if (cvec_len(argv) < 2){
clicon_err(OE_PLUGIN, EINVAL, "Usage: %s(<tree> <api_path_fmt> (,vars)*)", __FUNCTION__);
clixon_err(OE_PLUGIN, EINVAL, "Usage: %s(<tree> <api_path_fmt> (,vars)*)", __FUNCTION__);
goto done;
}
/* First argv argument: treename */
@ -527,7 +527,7 @@ cli_auto_sub_enter(clicon_handle h,
*/
/* Create a cvv with variables to add to api-path */
if ((cvv1 = cvec_new(0)) == NULL){
clicon_err(OE_UNIX, errno, "cvec_new");
clixon_err(OE_UNIX, errno, "cvec_new");
goto done;
}
/* Append static variables (skip first treename) */
@ -552,7 +552,7 @@ cli_auto_sub_enter(clicon_handle h,
goto done;
/* Find current cligen tree */
if ((ph = cligen_ph_find(cli_cligen(h), treename)) == NULL){
clicon_err(OE_PLUGIN, ENOENT, "No such parsetree header: %s", treename);
clixon_err(OE_PLUGIN, ENOENT, "No such parsetree header: %s", treename);
goto done;
}
/* Find the point in the generated clispec tree where workpoint should be set */
@ -560,7 +560,7 @@ cli_auto_sub_enter(clicon_handle h,
if (pt_apply(cligen_ph_parsetree_get(ph), cli_auto_findpt, INT32_MAX, &fa) < 0)
goto done;
if (fa.fa_co == NULL){
clicon_err(OE_PLUGIN, ENOENT, "No such cligen object found %s", api_path);
clixon_err(OE_PLUGIN, ENOENT, "No such cligen object found %s", api_path);
goto done;
}
cligen_ph_workpoint_set(ph, fa.fa_co);

View file

@ -110,7 +110,7 @@ autocli_listkw_int2str(int listkw)
* @retval -1 Error
*/
int
autocli_module(clicon_handle h,
autocli_module(clixon_handle h,
char *modname,
int *enablep)
{
@ -124,7 +124,7 @@ autocli_module(clicon_handle h,
char *body;
if (enablep == NULL){
clicon_err(OE_YANG, EINVAL, "Argument is NULL");
clixon_err(OE_YANG, EINVAL, "Argument is NULL");
goto done;
}
enable = 0;
@ -132,7 +132,7 @@ autocli_module(clicon_handle h,
goto ok;
/* Default rule */
if ((str = xml_find_body(xautocli, "module-default")) == NULL){
clicon_err(OE_XML, EINVAL, "No module-default rule");
clixon_err(OE_XML, EINVAL, "No module-default rule");
goto done;
}
enable = strcmp(str, "true") == 0;
@ -243,7 +243,7 @@ The surrounding container entities are removed from list nodes.
- Only one child + Child keyword is LIST
*/
int
autocli_compress(clicon_handle h,
autocli_compress(clixon_handle h,
yang_stmt *ys,
int *compress)
{
@ -262,11 +262,11 @@ autocli_compress(clicon_handle h,
char *body;
if (compress == NULL){
clicon_err(OE_YANG, EINVAL, "Argument is NULL");
clixon_err(OE_YANG, EINVAL, "Argument is NULL");
goto done;
}
if ((xautocli = clicon_conf_autocli(h)) == NULL){
clicon_err(OE_YANG, 0, "No clixon-autocli");
clixon_err(OE_YANG, 0, "No clixon-autocli");
goto done;
}
ymod = ys_module(ys);
@ -349,7 +349,7 @@ autocli_compress(clicon_handle h,
* @retval -1 Error
*/
int
autocli_completion(clicon_handle h,
autocli_completion(clixon_handle h,
int *completion)
{
int retval = -1;
@ -360,19 +360,19 @@ autocli_completion(clicon_handle h,
cxobj *xautocli;
if (completion == NULL){
clicon_err(OE_YANG, EINVAL, "Argument is NULL");
clixon_err(OE_YANG, EINVAL, "Argument is NULL");
goto done;
}
if ((xautocli = clicon_conf_autocli(h)) == NULL){
clicon_err(OE_YANG, 0, "No clixon-autocli");
clixon_err(OE_YANG, 0, "No clixon-autocli");
goto done;
}
if ((str = xml_find_body(xautocli, "completion-default")) == NULL){
clicon_err(OE_XML, EINVAL, "No completion-default rule");
clixon_err(OE_XML, EINVAL, "No completion-default rule");
goto done;
}
if ((ret = parse_bool(str, &val, &reason)) < 0){
clicon_err(OE_CFG, errno, "parse_bool");
clixon_err(OE_CFG, errno, "parse_bool");
goto done;
}
*completion = val;
@ -392,7 +392,7 @@ autocli_completion(clicon_handle h,
* @retval -1 Error
*/
int
autocli_grouping_treeref(clicon_handle h,
autocli_grouping_treeref(clixon_handle h,
int *treeref)
{
int retval = -1;
@ -403,19 +403,19 @@ autocli_grouping_treeref(clicon_handle h,
cxobj *xautocli;
if (treeref == NULL){
clicon_err(OE_YANG, EINVAL, "Argument is NULL");
clixon_err(OE_YANG, EINVAL, "Argument is NULL");
goto done;
}
if ((xautocli = clicon_conf_autocli(h)) == NULL){
clicon_err(OE_YANG, 0, "No clixon-autocli");
clixon_err(OE_YANG, 0, "No clixon-autocli");
goto done;
}
if ((str = xml_find_body(xautocli, "grouping-treeref")) == NULL){
clicon_err(OE_XML, EINVAL, "No grouping-treeref rule");
clixon_err(OE_XML, EINVAL, "No grouping-treeref rule");
goto done;
}
if ((ret = parse_bool(str, &val, &reason)) < 0){
clicon_err(OE_CFG, errno, "parse_bool");
clixon_err(OE_CFG, errno, "parse_bool");
goto done;
}
*treeref = val;
@ -435,7 +435,7 @@ autocli_grouping_treeref(clicon_handle h,
* @retval -1 Error
*/
int
autocli_list_keyword(clicon_handle h,
autocli_list_keyword(clixon_handle h,
autocli_listkw_t *listkw)
{
int retval = -1;
@ -443,15 +443,15 @@ autocli_list_keyword(clicon_handle h,
cxobj *xautocli = NULL;
if (listkw == NULL){
clicon_err(OE_YANG, EINVAL, "Argument is NULL");
clixon_err(OE_YANG, EINVAL, "Argument is NULL");
goto done;
}
if ((xautocli = clicon_conf_autocli(h)) == NULL){
clicon_err(OE_YANG, 0, "No clixon-autocli");
clixon_err(OE_YANG, 0, "No clixon-autocli");
goto done;
}
if ((str = xml_find_body(xautocli, "list-keyword-default")) == NULL){
clicon_err(OE_XML, EINVAL, "No list-keyword-default rule");
clixon_err(OE_XML, EINVAL, "No list-keyword-default rule");
goto done;
}
*listkw = autocli_listkw_str2int(str);
@ -468,7 +468,7 @@ autocli_list_keyword(clicon_handle h,
* @retval -1 Error
*/
int
autocli_treeref_state(clicon_handle h,
autocli_treeref_state(clixon_handle h,
int *treeref_state)
{
int retval = -1;
@ -479,19 +479,19 @@ autocli_treeref_state(clicon_handle h,
cxobj *xautocli;
if (treeref_state == NULL){
clicon_err(OE_YANG, EINVAL, "Argument is NULL");
clixon_err(OE_YANG, EINVAL, "Argument is NULL");
goto done;
}
if ((xautocli = clicon_conf_autocli(h)) == NULL){
clicon_err(OE_YANG, 0, "No clixon-autocli");
clixon_err(OE_YANG, 0, "No clixon-autocli");
goto done;
}
if ((str = xml_find_body(xautocli, "treeref-state-default")) == NULL){
clicon_err(OE_XML, EINVAL, "No treeref-state-default rule");
clixon_err(OE_XML, EINVAL, "No treeref-state-default rule");
goto done;
}
if ((ret = parse_bool(str, &val, &reason)) < 0){
clicon_err(OE_CFG, errno, "parse_bool");
clixon_err(OE_CFG, errno, "parse_bool");
goto done;
}
*treeref_state = val;
@ -512,7 +512,7 @@ autocli_treeref_state(clicon_handle h,
* @note keyw is a sub/superset of RFC 6020, see clixon-autocli.yang on which are defined
*/
int
autocli_edit_mode(clicon_handle h,
autocli_edit_mode(clixon_handle h,
char *keyw,
int *flag)
{
@ -525,16 +525,16 @@ autocli_edit_mode(clicon_handle h,
int i;
if (flag == NULL){
clicon_err(OE_YANG, EINVAL, "Argument is NULL");
clixon_err(OE_YANG, EINVAL, "Argument is NULL");
goto done;
}
*flag = 0;
if ((xautocli = clicon_conf_autocli(h)) == NULL){
clicon_err(OE_YANG, 0, "No clixon-autocli");
clixon_err(OE_YANG, 0, "No clixon-autocli");
goto done;
}
if ((str = xml_find_body(xautocli, "edit-mode-default")) == NULL){
clicon_err(OE_XML, EINVAL, "No edit-mode-default rule");
clixon_err(OE_XML, EINVAL, "No edit-mode-default rule");
goto done;
}
if ((vec = clicon_strsep(str, " ", &nvec)) == NULL)

View file

@ -50,12 +50,12 @@ enum autocli_op{
/*
* Prototypes
*/
int autocli_module(clicon_handle h, char *modname, int *enable);
int autocli_completion(clicon_handle h, int *completion);
int autocli_grouping_treeref(clicon_handle h, int *grouping_treeref);
int autocli_list_keyword(clicon_handle h, autocli_listkw_t *listkw);
int autocli_compress(clicon_handle h, yang_stmt *ys, int *compress);
int autocli_treeref_state(clicon_handle h, int *treeref_state);
int autocli_edit_mode(clicon_handle h, char *keyw, int *flag);
int autocli_module(clixon_handle h, char *modname, int *enable);
int autocli_completion(clixon_handle h, int *completion);
int autocli_grouping_treeref(clixon_handle h, int *grouping_treeref);
int autocli_list_keyword(clixon_handle h, autocli_listkw_t *listkw);
int autocli_compress(clixon_handle h, yang_stmt *ys, int *compress);
int autocli_treeref_state(clixon_handle h, int *treeref_state);
int autocli_edit_mode(clixon_handle h, char *keyw, int *flag);
#endif /* _CLI_AUTOCLI_H_ */

View file

@ -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)

View file

@ -39,8 +39,8 @@
#ifndef _CLI_COMMON_H_
#define _CLI_COMMON_H_
void cli_signal_block(clicon_handle h);
void cli_signal_unblock(clicon_handle h);
void cli_signal_block(clixon_handle h);
void cli_signal_unblock(clixon_handle h);
int mtpoint_paths(yang_stmt *yspec0, char *mtpoint, char *api_path_fmt1, char **api_path_fmt01);
cvec *cvec_append(cvec *cvv0, cvec *cvv1);

View file

@ -122,7 +122,7 @@ You can see which CLISPEC it generates via clixon_cli -D 2:
* @note XXX only fraction_digits handled,should also have mincv, maxcv, pattern
*/
static int
cli_expand_var_generate(clicon_handle h,
cli_expand_var_generate(clixon_handle h,
yang_stmt *ys,
const char *cvtypestr,
int options,
@ -177,7 +177,7 @@ cli_expand_var_generate(clicon_handle h,
* @see pt_callback_reference in CLIgen where the actual callback overwrites the template
*/
static int
cli_callback_generate(clicon_handle h,
cli_callback_generate(clixon_handle h,
yang_stmt *ys,
cbuf *cb)
{
@ -396,7 +396,7 @@ yang2cli_var_range(yang_stmt *ys,
* @note for cligen, need to escape " -> \"
*/
static int
yang2cli_var_pattern(clicon_handle h,
yang2cli_var_pattern(clixon_handle h,
cvec *patterns,
cbuf *cb)
{
@ -446,9 +446,9 @@ yang2cli_var_pattern(clicon_handle h,
}
/* Forward */
static int yang2cli_stmt(clicon_handle h, yang_stmt *ys, int level, cbuf *cb);
static int yang2cli_stmt(clixon_handle h, yang_stmt *ys, int level, cbuf *cb);
static int yang2cli_var_union(clicon_handle h, yang_stmt *ys, char *origtype,
static int yang2cli_var_union(clixon_handle h, yang_stmt *ys, char *origtype,
yang_stmt *ytype, char *helptext, cbuf *cb);
/*! Generate CLI code for Yang leaf state ment to CLIgen variable of specific type
@ -470,7 +470,7 @@ static int yang2cli_var_union(clicon_handle h, yang_stmt *ys, char *origtype,
* @see yang_type_resolve for options and other arguments
*/
static int
yang2cli_var_sub(clicon_handle h,
yang2cli_var_sub(clixon_handle h,
yang_stmt *ys,
yang_stmt *ytype, /* resolved type */
char *helptext,
@ -560,7 +560,7 @@ yang2cli_var_sub(clicon_handle h,
* @retval -1 Error
*/
static int
yang2cli_var_union_one(clicon_handle h,
yang2cli_var_union_one(clixon_handle h,
yang_stmt *ys,
char *origtype,
yang_stmt *ytsub,
@ -577,7 +577,7 @@ yang2cli_var_union_one(clicon_handle h,
char *restype;
if ((patterns = cvec_new(0)) == NULL){
clicon_err(OE_UNIX, errno, "cvec_new");
clixon_err(OE_UNIX, errno, "cvec_new");
goto done;
}
/* Resolve the sub-union type to a resolved type */
@ -586,7 +586,7 @@ yang2cli_var_union_one(clicon_handle h,
&cvv, patterns, NULL, &fraction_digits) < 0)
goto done;
if (ytype == NULL){
clicon_err(OE_YANG, 0, "result-type should not be NULL");
clixon_err(OE_YANG, 0, "result-type should not be NULL");
goto done;
}
restype = ytype?yang_argument_get(ytype):NULL;
@ -623,7 +623,7 @@ yang2cli_var_union_one(clicon_handle h,
* @retval -1 Error
*/
static int
yang2cli_var_union(clicon_handle h,
yang2cli_var_union(clixon_handle h,
yang_stmt *ys,
char *origtype,
yang_stmt *ytype,
@ -653,7 +653,7 @@ yang2cli_var_union(clicon_handle h,
}
static int
yang2cli_var_leafref(clicon_handle h,
yang2cli_var_leafref(clixon_handle h,
yang_stmt *ys,
yang_stmt *yrestype,
char *helptext,
@ -729,7 +729,7 @@ yang2cli_var_leafref(clicon_handle h,
* and thus its type.
*/
static int
yang2cli_var(clicon_handle h,
yang2cli_var(clixon_handle h,
yang_stmt *ys,
yang_stmt *yreferred,
char *helptext,
@ -749,7 +749,7 @@ yang2cli_var(clicon_handle h,
int ret;
if ((patterns = cvec_new(0)) == NULL){
clicon_err(OE_UNIX, errno, "cvec_new");
clixon_err(OE_UNIX, errno, "cvec_new");
goto done;
}
if (yang_type_get(yreferred, &origtype, &yrestype,
@ -785,11 +785,11 @@ yang2cli_var(clicon_handle h,
yang_stmt *yref = NULL;
if ((ypath = yang_find(yrestype, Y_PATH, NULL)) == NULL){
clicon_err(OE_YANG, 0, "No Y_PATH for leafref");
clixon_err(OE_YANG, 0, "No Y_PATH for leafref");
goto done;
}
if ((path_arg = yang_argument_get(ypath)) == NULL){
clicon_err(OE_YANG, 0, "No argument for Y_PATH");
clixon_err(OE_YANG, 0, "No argument for Y_PATH");
goto done;
}
if (yang_path_arg(yreferred, path_arg, &yref) < 0)
@ -803,7 +803,7 @@ yang2cli_var(clicon_handle h,
}
else {
if (yreferred == yref){
clicon_err(OE_YANG, 0, "Referred YANG node for leafref path %s points to self", path_arg);
clixon_err(OE_YANG, 0, "Referred YANG node for leafref path %s points to self", path_arg);
goto done;
}
/* recurse call with new referred node */
@ -841,7 +841,7 @@ yang2cli_var(clicon_handle h,
* + if callbacks add: cb();{}
*/
static int
yang2cli_leaf(clicon_handle h,
yang2cli_leaf(clixon_handle h,
yang_stmt *ys,
int level,
int callback,
@ -860,7 +860,7 @@ yang2cli_leaf(clicon_handle h,
/* description */
if ((yd = yang_find(ys, Y_DESCRIPTION, NULL)) != NULL){
if ((helptext = strdup(yang_argument_get(yd))) == NULL){
clicon_err(OE_UNIX, errno, "strdup");
clixon_err(OE_UNIX, errno, "strdup");
goto done;
}
if ((s = strstr(helptext, "\n\n")) != NULL)
@ -941,7 +941,7 @@ yang2cli_leaf(clicon_handle h,
* @retval -1 Error
*/
static int
yang2cli_container(clicon_handle h,
yang2cli_container(clixon_handle h,
yang_stmt *ys,
int level,
cbuf *cb)
@ -968,7 +968,7 @@ yang2cli_container(clicon_handle h,
cprintf(cb, "%*s%s", level*3, "", yang_argument_get(ys));
if ((yd = yang_find(ys, Y_DESCRIPTION, NULL)) != NULL){
if ((helptext = strdup(yang_argument_get(yd))) == NULL){
clicon_err(OE_UNIX, errno, "strdup");
clixon_err(OE_UNIX, errno, "strdup");
goto done;
}
if ((s = strstr(helptext, "\n\n")) != NULL)
@ -1016,7 +1016,7 @@ yang2cli_container(clicon_handle h,
* @retval -1 Error
*/
static int
yang2cli_list(clicon_handle h,
yang2cli_list(clixon_handle h,
yang_stmt *ys,
int level,
cbuf *cb)
@ -1037,7 +1037,7 @@ yang2cli_list(clicon_handle h,
cprintf(cb, "%*s%s", level*3, "", yang_argument_get(ys));
if ((yd = yang_find(ys, Y_DESCRIPTION, NULL)) != NULL){
if ((helptext = strdup(yang_argument_get(yd))) == NULL){
clicon_err(OE_UNIX, errno, "strdup");
clixon_err(OE_UNIX, errno, "strdup");
goto done;
}
if ((s = strstr(helptext, "\n\n")) != NULL)
@ -1056,7 +1056,7 @@ yang2cli_list(clicon_handle h,
while ((cvi = cvec_each(cvk, cvi)) != NULL) {
keyname = cv_string_get(cvi);
if ((yleaf = yang_find(ys, Y_LEAF, keyname)) == NULL){
clicon_err(OE_XML, 0, "List statement \"%s\" has no key leaf \"%s\"",
clixon_err(OE_XML, 0, "List statement \"%s\" has no key leaf \"%s\"",
yang_argument_get(ys), keyname);
goto done;
}
@ -1126,7 +1126,7 @@ yang2cli_list(clicon_handle h,
translated to cli. and therefore input-syntax != output syntax. Which is bad
*/
static int
yang2cli_choice(clicon_handle h,
yang2cli_choice(clixon_handle h,
yang_stmt *ys,
int level,
cbuf *cb)
@ -1168,7 +1168,7 @@ yang2cli_choice(clicon_handle h,
* @note Tie-break of same top-level symbol: prefix is NYI
* @see yang2cli_yspec for original
*/
static int yang2cli_grouping(clicon_handle h, yang_stmt *ys, char *treename);
static int yang2cli_grouping(clixon_handle h, yang_stmt *ys, char *treename);
/*! Generate CLI code for Yang uses statement
*
@ -1180,7 +1180,7 @@ static int yang2cli_grouping(clicon_handle h, yang_stmt *ys, char *treename);
* @retval -1 Error
*/
static int
yang2cli_uses(clicon_handle h,
yang2cli_uses(clixon_handle h,
yang_stmt *ys,
int level,
cbuf *cb)
@ -1200,11 +1200,11 @@ yang2cli_uses(clicon_handle h,
if (ys_grouping_resolve(ys, prefix, id, &ygrouping) < 0)
goto done;
if (ygrouping == NULL){
clicon_err(OE_YANG, 0, "grouping %s not found in \n", yang_argument_get(ys));
clixon_err(OE_YANG, 0, "grouping %s not found in \n", yang_argument_get(ys));
goto done;
}
if ((cbtree = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new");
clixon_err(OE_XML, errno, "cbuf_new");
goto done;
}
/* prefix is not globally unique, need namespace */
@ -1250,7 +1250,7 @@ yang2cli_uses(clicon_handle h,
* @retval -1 Error
*/
static int
yang2cli_stmt(clicon_handle h,
yang2cli_stmt(clixon_handle h,
yang_stmt *ys,
int level,
cbuf *cb)
@ -1262,7 +1262,7 @@ yang2cli_stmt(clicon_handle h,
int extvalue = 0;
if (ys == NULL){
clicon_err(OE_YANG, EINVAL, "No yang spec");
clixon_err(OE_YANG, EINVAL, "No yang spec");
goto done;
}
if (yang_find(ys, Y_STATUS, "obsolete") != NULL){
@ -1350,11 +1350,11 @@ cvec_add_name(cvec *cvv,
if (cvv == NULL &&
(cvv = cvec_new(0)) == NULL){
clicon_err(OE_UNIX, errno, "cvec_new");
clixon_err(OE_UNIX, errno, "cvec_new");
return NULL;
}
if ((cv = cvec_add(cvv, CGV_STRING)) == NULL){
clicon_err(OE_UNIX, errno, "cvec_add");
clixon_err(OE_UNIX, errno, "cvec_add");
return NULL;
}
/* Filter out state data, use "nonconfig" as defined in RFC8040 4.8.1
@ -1392,7 +1392,7 @@ cvec_add_name(cvec *cvv,
* (2) rewrite yang2cli code to create pt directly instead of via a cbuf.
*/
static int
yang2cli_post(clicon_handle h,
yang2cli_post(clixon_handle h,
cg_obj *cop,
parse_tree *pt,
int i0,
@ -1412,7 +1412,7 @@ yang2cli_post(clicon_handle h,
ypkeyword = yang_keyword_get(yp);
for (i = i0; i<pt_len_get(pt); i++){
if ((co = pt_vec_i_get(pt, i)) == NULL){
clicon_err(OE_YANG, 0, "Empty object in parsetreelist"); /* shouldnt happen */
clixon_err(OE_YANG, 0, "Empty object in parsetreelist"); /* shouldnt happen */
goto done;
}
if (co->co_type == CO_EMPTY){
@ -1517,7 +1517,7 @@ yang2cli_post(clicon_handle h,
* XXX merge with yang2cli_yspec
*/
static int
yang2cli_grouping(clicon_handle h,
yang2cli_grouping(clixon_handle h,
yang_stmt *ys,
char *treename)
{
@ -1534,11 +1534,11 @@ yang2cli_grouping(clicon_handle h,
int i;
if ((pt0 = pt_new()) == NULL){
clicon_err(OE_UNIX, errno, "pt_new");
clixon_err(OE_UNIX, errno, "pt_new");
goto done;
}
if ((cb = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new");
clixon_err(OE_XML, errno, "cbuf_new");
goto done;
}
/* Traverse YANG, loop through all modules and generate CLI, inline of yang2cli_stmt */
@ -1564,11 +1564,11 @@ yang2cli_grouping(clicon_handle h,
* Needs to move cligen_parse_str() call here instead of later
*/
if ((prefix = yang_find_myprefix(ys)) == NULL){
clicon_err(OE_YANG, 0, "Module %s lacks prefix", yang_argument_get(ys)); /* shouldnt happen */
clixon_err(OE_YANG, 0, "Module %s lacks prefix", yang_argument_get(ys)); /* shouldnt happen */
goto done;
}
if ((pt = pt_new()) == NULL){
clicon_err(OE_UNIX, errno, "pt_new");
clixon_err(OE_UNIX, errno, "pt_new");
goto done;
}
/* Parse the buffer using cligen parser. load cli syntax */
@ -1596,13 +1596,13 @@ yang2cli_grouping(clicon_handle h,
goto done;
}
if (clicon_data_int_get(h, "autocli-print-debug") == 1)
clicon_log(LOG_NOTICE, "%s: Top-level cli-spec %s:\n%s",
clixon_log(h, LOG_NOTICE, "%s: Top-level cli-spec %s:\n%s",
__FUNCTION__, treename, cbuf_get(cb));
else
clixon_debug(CLIXON_DBG_DETAIL, "%s: Top-level cli-spec %s:\n%s",
__FUNCTION__, treename, cbuf_get(cb));
if (cligen_parsetree_merge(pt0, NULL, pt) < 0){
clicon_err(OE_YANG, errno, "cligen_parsetree_merge");
clixon_err(OE_YANG, errno, "cligen_parsetree_merge");
goto done;
}
pt_free(pt, 1);
@ -1617,11 +1617,11 @@ yang2cli_grouping(clicon_handle h,
goto done;
/* Append cligen tree and name it */
if ((ph = cligen_ph_add(cli_cligen(h), treename)) == NULL){
clicon_err(OE_UNIX, 0, "cligen_ph_add");
clixon_err(OE_UNIX, 0, "cligen_ph_add");
goto done;
}
if (cligen_ph_parsetree_set(ph, pt0) < 0){
clicon_err(OE_UNIX, 0, "cligen_ph_parsetree_set");
clixon_err(OE_UNIX, 0, "cligen_ph_parsetree_set");
goto done;
}
pt0 = NULL;
@ -1651,7 +1651,7 @@ yang2cli_grouping(clicon_handle h,
* @note Tie-break of same top-level symbol: prefix is NYI
*/
int
yang2cli_yspec(clicon_handle h,
yang2cli_yspec(clixon_handle h,
yang_stmt *yspec,
char *treename)
{
@ -1668,11 +1668,11 @@ yang2cli_yspec(clicon_handle h,
int config;
if ((pt0 = pt_new()) == NULL){
clicon_err(OE_UNIX, errno, "pt_new");
clixon_err(OE_UNIX, errno, "pt_new");
goto done;
}
if ((cb = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new");
clixon_err(OE_XML, errno, "cbuf_new");
goto done;
}
/* Traverse YANG, loop through all modules and generate CLI */
@ -1694,11 +1694,11 @@ yang2cli_yspec(clicon_handle h,
* Needs to move cligen_parse_str() call here instead of later
*/
if ((prefix = yang_find_myprefix(ymod)) == NULL){
clicon_err(OE_YANG, 0, "Module %s lacks prefix", yang_argument_get(ymod)); /* shouldnt happen */
clixon_err(OE_YANG, 0, "Module %s lacks prefix", yang_argument_get(ymod)); /* shouldnt happen */
goto done;
}
if ((pt = pt_new()) == NULL){
clicon_err(OE_UNIX, errno, "pt_new");
clixon_err(OE_UNIX, errno, "pt_new");
goto done;
}
/* Parse the buffer using cligen parser. load cli syntax */
@ -1727,13 +1727,13 @@ yang2cli_yspec(clicon_handle h,
}
// pt_print(stderr,pt);
if (clicon_data_int_get(h, "autocli-print-debug") == 1)
clicon_log(LOG_NOTICE, "%s: Top-level cli-spec %s:\n%s",
clixon_log(h, LOG_NOTICE, "%s: Top-level cli-spec %s:\n%s",
__FUNCTION__, treename, cbuf_get(cb));
else
clixon_debug(CLIXON_DBG_DETAIL, "%s: Top-level cli-spec %s:\n%s",
__FUNCTION__, treename, cbuf_get(cb));
if (cligen_parsetree_merge(pt0, NULL, pt) < 0){
clicon_err(OE_YANG, errno, "cligen_parsetree_merge");
clixon_err(OE_YANG, errno, "cligen_parsetree_merge");
goto done;
}
pt_free(pt, 1);
@ -1748,17 +1748,17 @@ yang2cli_yspec(clicon_handle h,
goto done;
/* Append cligen tree and name it */
if ((ph = cligen_ph_add(cli_cligen(h), treename)) == NULL){
clicon_err(OE_UNIX, 0, "cligen_ph_add");
clixon_err(OE_UNIX, 0, "cligen_ph_add");
goto done;
}
if (cligen_ph_parsetree_set(ph, pt0) < 0){
clicon_err(OE_UNIX, 0, "cligen_ph_parsetree_set");
clixon_err(OE_UNIX, 0, "cligen_ph_parsetree_set");
goto done;
}
pt0 = NULL;
#if 0
if (clicon_data_int_get(h, "autocli-print-debug") == 1){
clicon_log(LOG_NOTICE, "%s: Top-level cli-spec %s", __FUNCTION__, treename);
clixon_log(h, LOG_NOTICE, "%s: Top-level cli-spec %s", __FUNCTION__, treename);
pt_print1(stderr, pt0, 0);
}
#endif
@ -1781,7 +1781,7 @@ yang2cli_yspec(clicon_handle h,
* @param[in] h Clixon handle
*/
int
yang2cli_init(clicon_handle h)
yang2cli_init(clixon_handle h)
{
return 0;
}

View file

@ -61,7 +61,7 @@
/*
* Prototypes
*/
int yang2cli_yspec(clicon_handle h, yang_stmt *yspec, char *treename);
int yang2cli_init(clicon_handle h);
int yang2cli_yspec(clixon_handle h, yang_stmt *yspec, char *treename);
int yang2cli_init(clixon_handle h);
#endif /* _CLI_GENERATE_H_ */

View file

@ -60,7 +60,7 @@
/* cligen */
#include <cligen/cligen.h>
/* clicon */
/* clixon */
#include <clixon/clixon.h>
#include "clixon_cli_api.h"
@ -69,15 +69,15 @@
#define CLICON_MAGIC 0x99aafabe
#define handle(h) (assert(clicon_handle_check(h)==0),(struct cli_handle *)(h))
#define handle(h) (assert(clixon_handle_check(h)==0),(struct cli_handle *)(h))
#define cligen(h) (handle(h)->cl_cligen)
/*! CLI specific handle added to header Clixon handle
*
* This file should only contain access functions for the _specific_
* entries in the struct below.
* @note The top part must be equivalent to struct clicon_handle in clixon_handle.c
* @see struct clicon_handle, struct backend_handle
* @note The top part must be equivalent to struct clixon_handle in clixon_handle.c
* @see struct clixon_handle, struct backend_handle
*/
struct cli_handle {
int cl_magic; /* magic (HDR)*/
@ -92,25 +92,25 @@ struct cli_handle {
/*! Return a clicon handle for other CLICON API calls
*/
clicon_handle
clixon_handle
cli_handle_init(void)
{
struct cli_handle *cl;
cligen_handle clih = NULL;
clicon_handle h = NULL;
clixon_handle h = NULL;
if ((cl = (struct cli_handle *)clicon_handle_init0(sizeof(struct cli_handle))) == NULL)
if ((cl = (struct cli_handle *)clixon_handle_init0(sizeof(struct cli_handle))) == NULL)
return NULL;
if ((clih = cligen_init()) == NULL){
clicon_handle_exit((clicon_handle)cl);
clixon_handle_exit((clixon_handle)cl);
goto done;
}
cligen_userhandle_set(clih, cl);
cligen_eval_wrap_fn_set(clih, plugin_context_check, cl);
cl->cl_cligen = clih;
h = (clicon_handle)cl;
h = (clixon_handle)cl;
done:
return h;
}
@ -120,11 +120,11 @@ cli_handle_init(void)
* @param[in] h Clixon handle
*/
int
cli_handle_exit(clicon_handle h)
cli_handle_exit(clixon_handle h)
{
cligen_handle ch = cligen(h);
clicon_handle_exit(h); /* frees h and options */
clixon_handle_exit(h); /* frees h and options */
cligen_exit(ch);
return 0;
}
@ -138,13 +138,13 @@ cli_handle_exit(clicon_handle h)
* @param[in] h Clixon handle
*/
cligen_handle
cli_cligen(clicon_handle h)
cli_cligen(clixon_handle h)
{
return cligen(h);
}
int
cli_parse_file(clicon_handle h,
cli_parse_file(clixon_handle h,
FILE *f,
char *name, /* just for errs */
parse_tree *pt,
@ -156,7 +156,7 @@ cli_parse_file(clicon_handle h,
}
int
cli_susp_hook(clicon_handle h,
cli_susp_hook(clixon_handle h,
cligen_susp_cb_t *fn)
{
cligen_handle ch = cligen(h);
@ -166,7 +166,7 @@ cli_susp_hook(clicon_handle h,
}
int
cli_interrupt_hook(clicon_handle h,
cli_interrupt_hook(clixon_handle h,
cligen_interrupt_cb_t *fn)
{
cligen_handle ch = cligen(h);
@ -176,7 +176,7 @@ cli_interrupt_hook(clicon_handle h,
}
int
cli_prompt_set(clicon_handle h,
cli_prompt_set(clixon_handle h,
char *prompt)
{
cligen_handle ch = cligen(h);
@ -184,7 +184,7 @@ cli_prompt_set(clicon_handle h,
}
int
cli_logsyntax_set(clicon_handle h,
cli_logsyntax_set(clixon_handle h,
int status)
{
cligen_handle ch = cligen(h);

View file

@ -43,18 +43,18 @@
* Prototypes
* Internal prototypes. For exported functions see clixon_cli_api.h
*/
int cli_parse_file(clicon_handle h,
int cli_parse_file(clixon_handle h,
FILE *f,
char *name, /* just for errs */
parse_tree *pt,
cvec *globals);
int cli_susp_hook(clicon_handle h, cligen_susp_cb_t *fn);
int cli_susp_hook(clixon_handle h, cligen_susp_cb_t *fn);
int cli_interrupt_hook(clicon_handle h, cligen_interrupt_cb_t *fn);
int cli_interrupt_hook(clixon_handle h, cligen_interrupt_cb_t *fn);
int cli_prompt_set(clicon_handle h, char *prompt);
int cli_prompt_set(clixon_handle h, char *prompt);
int cli_logsyntax_set(clicon_handle h, int status);
int cli_logsyntax_set(clixon_handle h, int status);
#endif /* _CLI_HANDLE_H_ */

View file

@ -61,7 +61,7 @@
/* cligen */
#include <cligen/cligen.h>
/* clicon */
/* clixon */
#include <clixon/clixon.h>
#include "clixon_cli_api.h"
@ -82,7 +82,7 @@
* @retval -1 Error
*/
static int
cli_history_load(clicon_handle h)
cli_history_load(clixon_handle h)
{
int retval = -1;
int lines;
@ -101,16 +101,16 @@ cli_history_load(clicon_handle h)
if ((filename = clicon_option_str(h,"CLICON_CLI_HIST_FILE")) == NULL)
goto ok; /* ignore */
if (wordexp(filename, &result, 0) < 0){
clicon_err(OE_UNIX, errno, "wordexp");
clixon_err(OE_UNIX, errno, "wordexp");
goto done;
}
if ((f = fopen(result.we_wordv[0], "r")) == NULL){
clicon_log(LOG_DEBUG, "Warning: Could not open CLI history file for reading: %s: %s",
clixon_log(h, LOG_DEBUG, "Warning: Could not open CLI history file for reading: %s: %s",
result.we_wordv[0], strerror(errno));
goto ok;
}
if (cligen_hist_file_load(cli_cligen(h), f) < 0){
clicon_err(OE_UNIX, errno, "cligen_hist_file_load");
clixon_err(OE_UNIX, errno, "cligen_hist_file_load");
goto done;
}
ok:
@ -130,7 +130,7 @@ cli_history_load(clicon_handle h)
* @retval -1 Error
*/
static int
cli_history_save(clicon_handle h)
cli_history_save(clixon_handle h)
{
int retval = -1;
char *filename;
@ -140,16 +140,16 @@ cli_history_save(clicon_handle h)
if ((filename = clicon_option_str(h, "CLICON_CLI_HIST_FILE")) == NULL)
goto ok; /* ignore */
if (wordexp(filename, &result, 0) < 0){
clicon_err(OE_UNIX, errno, "wordexp");
clixon_err(OE_UNIX, errno, "wordexp");
goto done;
}
if ((f = fopen(result.we_wordv[0], "w+")) == NULL){
clicon_log(LOG_DEBUG, "Warning: Could not open CLI history file for writing: %s: %s",
clixon_log(h, LOG_DEBUG, "Warning: Could not open CLI history file for writing: %s: %s",
result.we_wordv[0], strerror(errno));
goto ok;
}
if (cligen_hist_file_save(cli_cligen(h), f) < 0){
clicon_err(OE_UNIX, errno, "cligen_hist_file_save");
clixon_err(OE_UNIX, errno, "cligen_hist_file_save");
goto done;
}
ok:
@ -167,7 +167,7 @@ cli_history_save(clicon_handle h)
* @param[in] h Clixon handle
*/
static int
cli_terminate(clicon_handle h)
cli_terminate(clixon_handle h)
{
yang_stmt *yspec;
cvec *nsctx;
@ -196,7 +196,7 @@ cli_terminate(clicon_handle h)
cli_history_save(h);
cli_handle_exit(h);
clixon_err_exit();
clicon_log_exit();
clixon_log_exit();
return 0;
}
@ -205,7 +205,7 @@ cli_terminate(clicon_handle h)
static void
cli_sig_term(int arg)
{
clicon_log(LOG_NOTICE, "%s: %u Terminated (killed by sig %d)",
clixon_log(NULL, LOG_NOTICE, "%s: %u Terminated (killed by sig %d)",
__PROGRAM__, getpid(), arg);
exit(1);
}
@ -213,17 +213,17 @@ cli_sig_term(int arg)
/*! Setup signal handlers
*/
static int
cli_signal_init (clicon_handle h)
cli_signal_init (clixon_handle h)
{
int retval = -1;
cli_signal_block(h);
if (set_signal(SIGTERM, cli_sig_term, NULL) < 0){
clicon_err(OE_UNIX, errno, "Setting SIGTERM signal");
clixon_err(OE_UNIX, errno, "Setting SIGTERM signal");
goto done;
}
if (set_signal(SIGPIPE, SIG_IGN, NULL) < 0){
clicon_err(OE_UNIX, errno, "Setting DIGPIPE signal");
clixon_err(OE_UNIX, errno, "Setting DIGPIPE signal");
goto done;
}
retval = 0;
@ -239,7 +239,7 @@ cli_signal_init (clicon_handle h)
* @see cligen_loop
*/
static int
cli_interactive(clicon_handle h)
cli_interactive(clixon_handle h)
{
int retval = -1;
char *cmd;
@ -251,7 +251,7 @@ cli_interactive(clicon_handle h)
/* Loop through all commands */
while(!cligen_exiting(cli_cligen(h))) {
if ((ph = cligen_pt_head_active_get(cli_cligen(h))) == NULL){
clicon_err(OE_UNIX, 0, "active tree not found");
clixon_err(OE_UNIX, 0, "active tree not found");
goto done;
}
new_mode = cligen_ph_name_get(ph);
@ -280,7 +280,7 @@ cli_interactive(clicon_handle h)
* should probably be moved to clispec default
*/
static int
autocli_trees_default(clicon_handle h)
autocli_trees_default(clixon_handle h)
{
int retval = -1;
cbuf *cb = NULL;
@ -292,7 +292,7 @@ autocli_trees_default(clicon_handle h)
if ((ph = cligen_ph_add(cli_cligen(h), "datamodel")) == NULL)
goto done;
if ((pt = pt_new()) == NULL){
clicon_err(OE_UNIX, errno, "pt_new");
clixon_err(OE_UNIX, errno, "pt_new");
goto done;
}
if (clispec_parse_str(cli_cligen(h),
@ -306,7 +306,7 @@ autocli_trees_default(clicon_handle h)
if ((ph = cligen_ph_add(cli_cligen(h), "datamodelshow")) == NULL)
goto done;
if ((pt = pt_new()) == NULL){
clicon_err(OE_UNIX, errno, "pt_new");
clixon_err(OE_UNIX, errno, "pt_new");
goto done;
}
if (clispec_parse_str(cli_cligen(h),
@ -319,7 +319,7 @@ autocli_trees_default(clicon_handle h)
if ((ph = cligen_ph_add(cli_cligen(h), "datamodelstate")) == NULL)
goto done;
if ((pt = pt_new()) == NULL){
clicon_err(OE_UNIX, errno, "pt_new");
clixon_err(OE_UNIX, errno, "pt_new");
goto done;
}
if (clispec_parse_str(cli_cligen(h),
@ -333,11 +333,11 @@ autocli_trees_default(clicon_handle h)
if ((ph = cligen_ph_add(cli_cligen(h), "datamodelmode")) == NULL)
goto done;
if ((pt = pt_new()) == NULL){
clicon_err(OE_UNIX, errno, "pt_new");
clixon_err(OE_UNIX, errno, "pt_new");
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, "@basemodel, @remove:act-prekey, @remove:act-leafconst, @remove:ac-state");
@ -385,7 +385,7 @@ autocli_trees_default(clicon_handle h)
* @retval -1 Error
*/
static int
autocli_start(clicon_handle h)
autocli_start(clixon_handle h)
{
int retval = -1;
yang_stmt *yspec;
@ -435,7 +435,7 @@ autocli_start(clicon_handle h)
* @retval -1 Error
*/
static int
options_split(clicon_handle h,
options_split(clixon_handle h,
char *argv0,
int argc,
char **argv,
@ -470,7 +470,7 @@ options_split(clicon_handle h,
}
static void
usage(clicon_handle h,
usage(clixon_handle h,
char *argv0)
{
char *plgdir = clicon_cli_dir(h);
@ -518,10 +518,10 @@ main(int argc,
int once;
char *tmp;
char *argv0 = argv[0];
clicon_handle h;
clixon_handle h;
int logclisyntax = 0;
int help = 0;
int logdst = CLICON_LOG_STDERR;
int logdst = CLIXON_LOG_STDERR;
char *restarg = NULL; /* what remains after options */
yang_stmt *yspec;
struct passwd *pw;
@ -540,18 +540,20 @@ main(int argc,
once = 0;
config_dump = 0;
/* In the startup, logs to stderr & debug flag set later */
clicon_log_init(__PROGRAM__, LOG_INFO, logdst);
/* Initiate Clixon handle. CLIgen is also initialized */
if ((h = cli_handle_init()) == NULL)
goto done;
/* In the startup, logs to stderr & debug flag set later */
if (clixon_log_init(h, __PROGRAM__, LOG_INFO, logdst) < 0)
goto done;
if (clixon_err_init(h) < 0)
goto done;
/* Set username to clicon handle. Use in all communication to backend
* Note, can be overridden by -U
*/
if ((pw = getpwuid(getuid())) == NULL){
clicon_err(OE_UNIX, errno, "getpwuid");
clixon_err(OE_UNIX, errno, "getpwuid");
goto done;
}
if (clicon_username_set(h, pw->pw_name) < 0)
@ -594,19 +596,19 @@ main(int argc,
clicon_option_str_set(h, "CLICON_CONFIGDIR", optarg);
break;
case 'l': /* Log destination: s|e|o|f */
if ((logdst = clicon_log_opt(optarg[0])) < 0)
if ((logdst = clixon_log_opt(optarg[0])) < 0)
usage(h, argv[0]);
if (logdst == CLICON_LOG_FILE &&
if (logdst == CLIXON_LOG_FILE &&
strlen(optarg)>1 &&
clicon_log_file(optarg+1) < 0)
clixon_log_file(optarg+1) < 0)
goto done;
break;
}
/*
* Logs, error and debug to stderr or syslog, set debug level
*/
clicon_log_init(__PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst);
clixon_debug_init(dbg, NULL);
clixon_log_init(h, __PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst);
clixon_debug_init(h, dbg);
yang_init(h);
/* Find, read and parse configfile */
@ -734,7 +736,7 @@ main(int argc,
/* Enable XSD libxml2 regex engine */
cligen_regex_xsd_set(cli_cligen(h), 1);
#else
clicon_err(OE_FATAL, 0, "CLICON_YANG_REGEXP set to libxml2, but HAVE_LIBXML2 not set (Either change CLICON_YANG_REGEXP to posix, or run: configure --with-libxml2))");
clixon_err(OE_FATAL, 0, "CLICON_YANG_REGEXP set to libxml2, but HAVE_LIBXML2 not set (Either change CLICON_YANG_REGEXP to posix, or run: configure --with-libxml2))");
goto done;
#endif
}
@ -746,7 +748,7 @@ main(int argc,
cligen_helpstring_lines_set(cli_cligen(h), nr);
if ((nr = clicon_option_int(h, "CLICON_LOG_STRING_LIMIT")) != 0)
clicon_log_string_limit_set(nr);
clixon_log_string_limit_set(nr);
/* Setup signal handlers */
if (cli_signal_init(h) < 0)
@ -852,7 +854,7 @@ main(int argc,
goto done;
}
if (cligen_ph_find(cli_cligen(h), cli_syntax_mode(h)) == NULL)
clicon_log(LOG_WARNING, "No such cli mode: %s (Specify cli mode with CLICON_CLI_MODE in config file or -m <mode> on command line", cli_syntax_mode(h));
clixon_log(h, LOG_WARNING, "No such cli mode: %s (Specify cli mode with CLICON_CLI_MODE in config file or -m <mode> on command line", cli_syntax_mode(h));
/* CLIgen tab mode, ie how <tab>s behave */
if ((tabmode = clicon_cli_tab_mode(h)) < 0){
fprintf(stderr, "FATAL: CLICON_CLI_TAB_MODE not set\n");
@ -922,9 +924,9 @@ main(int argc,
done:
if (restarg)
free(restarg);
// Gets in your face if we log on stderr
clicon_log_init(__PROGRAM__, LOG_INFO, 0); /* Log on syslog no stderr */
clicon_log(LOG_NOTICE, "%s: %u Terminated", __PROGRAM__, getpid());
// Gets in your face if we log on stderr
clixon_log_init(h, __PROGRAM__, LOG_INFO, 0); /* Log on syslog no stderr */
clixon_log(h, LOG_NOTICE, "%s: %u Terminated", __PROGRAM__, getpid());
if (h)
cli_terminate(h);
return retval;

View file

@ -67,7 +67,7 @@
/* cligen */
#include <cligen/cligen.h>
/* clicon */
/* clixon */
#include <clixon/clixon.h>
#include "clixon_cli_api.h"
@ -83,7 +83,7 @@
* @endcode
*/
int
pipe_arg_fn(clicon_handle h,
pipe_arg_fn(clixon_handle h,
char *cmd,
char *option,
char *value)
@ -94,19 +94,19 @@ pipe_arg_fn(clicon_handle h,
int i;
if (cmd == NULL || strlen(cmd) == 0){
clicon_err(OE_PLUGIN, EINVAL, "cmd '%s' NULL or empty", cmd);
clixon_err(OE_PLUGIN, EINVAL, "cmd '%s' NULL or empty", cmd);
goto done;
}
if (stat(cmd, &fstat) < 0) {
clicon_err(OE_UNIX, errno, "stat(%s)", cmd);
clixon_err(OE_UNIX, errno, "stat(%s)", cmd);
goto done;
}
if (!S_ISREG(fstat.st_mode)){
clicon_err(OE_UNIX, errno, "%s is not a regular file", cmd);
clixon_err(OE_UNIX, errno, "%s is not a regular file", cmd);
goto done;
}
if ((argv = calloc(4, sizeof(char *))) == NULL){
clicon_err(OE_UNIX, errno, "calloc");
clixon_err(OE_UNIX, errno, "calloc");
goto done;
}
i = 0;
@ -129,7 +129,7 @@ pipe_arg_fn(clicon_handle h,
* @note Any vertical bar (|] in the patterns field is quoted for OR function
*/
int
pipe_grep_fn(clicon_handle h,
pipe_grep_fn(clixon_handle h,
cvec *cvv,
cvec *argv)
{
@ -144,7 +144,7 @@ pipe_grep_fn(clicon_handle h,
char c;
if (cvec_len(argv) != 2){
clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: <option> <argname>", cvec_len(argv));
clixon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: <option> <argname>", cvec_len(argv));
goto done;
}
if ((cv = cvec_i(argv, 0)) != NULL &&
@ -156,7 +156,7 @@ pipe_grep_fn(clicon_handle h,
strlen(str))
argname = str;
if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new");
clixon_err(OE_UNIX, errno, "cbuf_new");
goto done;
}
if (argname && strlen(argname)){
@ -189,7 +189,7 @@ pipe_grep_fn(clicon_handle h,
* @retval -1 Error
*/
int
pipe_wc_fn(clicon_handle h,
pipe_wc_fn(clixon_handle h,
cvec *cvv,
cvec *argv)
{
@ -199,7 +199,7 @@ pipe_wc_fn(clicon_handle h,
char *option = NULL;
if (cvec_len(argv) != 1){
clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: <NUM>", cvec_len(argv));
clixon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: <NUM>", cvec_len(argv));
goto done;
}
if ((cv = cvec_i(argv, 0)) != NULL &&
@ -220,7 +220,7 @@ pipe_wc_fn(clicon_handle h,
* @retval -1 Error
*/
int
pipe_tail_fn(clicon_handle h,
pipe_tail_fn(clixon_handle h,
cvec *cvv,
cvec *argv)
{
@ -232,7 +232,7 @@ pipe_tail_fn(clicon_handle h,
char *argname = NULL;
if (cvec_len(argv) != 2){
clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: <option> <argname>", cvec_len(argv));
clixon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: <option> <argname>", cvec_len(argv));
goto done;
}
if ((cv = cvec_i(argv, 0)) != NULL &&
@ -267,7 +267,7 @@ pipe_tail_fn(clicon_handle h,
* @see cli_show_auto_devs
*/
int
pipe_showas_fn(clicon_handle h,
pipe_showas_fn(clixon_handle h,
cvec *cvv,
cvec *argv)
{
@ -282,7 +282,7 @@ pipe_showas_fn(clicon_handle h,
cxobj *xerr = NULL;
if (cvec_len(argv) < 1 || cvec_len(argv) > 3){
clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected:: <format> [<pretty> [<prepend>]]", cvec_len(argv));
clixon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected:: <format> [<pretty> [<prepend>]]", cvec_len(argv));
goto done;
}
if (cvec_len(argv) > argc){
@ -308,7 +308,7 @@ pipe_showas_fn(clicon_handle h,
if ((ret = xml_bind_yang(h, xt, YB_MODULE, yspec, &xerr)) < 0)
goto done;
if (ret == 0){
clixon_netconf_error(h, xerr, "Parse top file", NULL);
clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Parse top file");
goto done;
}
break;

View file

@ -59,7 +59,7 @@
/* cligen */
#include <cligen/cligen.h>
/* clicon */
/* clixon */
#include <clixon/clixon.h>
/* clicon_cli */
@ -87,7 +87,7 @@
* @retval -1 Error
*/
static int
gen_parse_tree(clicon_handle h,
gen_parse_tree(clixon_handle h,
char *name,
parse_tree *pt,
pt_head **php)
@ -100,7 +100,7 @@ gen_parse_tree(clicon_handle h,
if (cligen_ph_parsetree_set(ph, pt) < 0)
goto done;
if (cligen_ph_prompt_set(ph, CLI_DEFAULT_PROMPT) < 0){
clicon_err(OE_UNIX, errno, "cligen_ph_prompt_set");
clixon_err(OE_UNIX, errno, "cligen_ph_prompt_set");
goto done;
}
*php = ph;
@ -198,7 +198,7 @@ cli_mark_output_pipes(cg_obj *co,
* @see clixon_plugins_load Where .so plugin code has been loaded prior to this
*/
static int
clispec_load_file(clicon_handle h,
clispec_load_file(clixon_handle h,
const char *filename,
const char *dir,
parse_tree *ptall,
@ -223,7 +223,7 @@ clispec_load_file(clicon_handle h,
#endif
if ((pt = pt_new()) == NULL){
clicon_err(OE_UNIX, errno, "pt_new");
clixon_err(OE_UNIX, errno, "pt_new");
goto done;
}
if (dir)
@ -231,18 +231,18 @@ clispec_load_file(clicon_handle h,
else
snprintf(filepath, MAXPATHLEN-1, "%s", filename);
if ((cvv = cvec_new(0)) == NULL){
clicon_err(OE_PLUGIN, errno, "cvec_new");
clixon_err(OE_PLUGIN, errno, "cvec_new");
goto done;
}
/* Build parse tree from syntax spec. */
if ((f = fopen(filepath, "r")) == NULL){
clicon_err(OE_PLUGIN, errno, "fopen %s", filepath);
clixon_err(OE_PLUGIN, errno, "fopen %s", filepath);
goto done;
}
/* Assuming this plugin is first in queue */
if (clispec_parse_file(h, f, filepath, NULL, pt, cvv) < 0){
clicon_err(OE_PLUGIN, 0, "failed to parse cli file %s", filepath);
clixon_err(OE_PLUGIN, 0, "failed to parse cli file %s", filepath);
fclose(f);
goto done;
}
@ -267,7 +267,7 @@ clispec_load_file(clicon_handle h,
if ((cp = clixon_plugin_find(h, plgnam)) != NULL)
handle = clixon_plugin_handle_get(cp);
if (handle == NULL){
clicon_err(OE_PLUGIN, 0, "CLICON_PLUGIN set to '%s' in %s but plugin %s.so not found in %s",
clixon_err(OE_PLUGIN, 0, "CLICON_PLUGIN set to '%s' in %s but plugin %s.so not found in %s",
plgnam, filename, plgnam,
clicon_cli_dir(h));
goto done;
@ -284,7 +284,7 @@ clispec_load_file(clicon_handle h,
/* Resolve callback names to function pointers. */
if (cligen_callbackv_str2fn(pt, (cgv_str2fn_t*)clixon_str2fn, handle) < 0){
clicon_err(OE_PLUGIN, 0, "Mismatch between CLIgen file '%s' and CLI plugin file '%s'. Some possible errors:\n\t1. A function given in the CLIgen file does not exist in the plugin (ie link error)\n\t2. The CLIgen spec does not point to the correct plugin .so file (CLICON_PLUGIN=\"%s\" is wrong)",
clixon_err(OE_PLUGIN, 0, "Mismatch between CLIgen file '%s' and CLI plugin file '%s'. Some possible errors:\n\t1. A function given in the CLIgen file does not exist in the plugin (ie link error)\n\t2. The CLIgen spec does not point to the correct plugin .so file (CLICON_PLUGIN=\"%s\" is wrong)",
filename, plgnam, plgnam);
goto done;
}
@ -298,7 +298,7 @@ clispec_load_file(clicon_handle h,
if (mode == NULL || strlen(mode) < 1) { /* may be null if not given in file */
mode = clicon_cli_mode(h);
if (mode == NULL || strlen(mode) < 1) { /* may be null if not given in file */
clicon_err(OE_PLUGIN, 0, "No syntax mode specified in %s", filepath);
clixon_err(OE_PLUGIN, 0, "No syntax mode specified in %s", filepath);
goto done;
}
}
@ -312,7 +312,7 @@ clispec_load_file(clicon_handle h,
* all modes may not be known (not yet loaded)
*/
if (cligen_parsetree_merge(ptall, NULL, pt) < 0){
clicon_err(OE_PLUGIN, errno, "cligen_parsetree_merge");
clixon_err(OE_PLUGIN, errno, "cligen_parsetree_merge");
goto done;
}
}
@ -323,7 +323,7 @@ clispec_load_file(clicon_handle h,
cg_var *cv;
if ((ph = cligen_ph_find(cli_cligen(h), name)) == NULL){
if ((ptnew = pt_new()) == NULL){
clicon_err(OE_UNIX, errno, "pt_new");
clixon_err(OE_UNIX, errno, "pt_new");
goto done;
}
if (gen_parse_tree(h, name, ptnew, &ph) < 0)
@ -331,12 +331,12 @@ clispec_load_file(clicon_handle h,
if (ph == NULL)
goto done;
if ((cv = cv_new(CGV_STRING)) == NULL){
clicon_err(OE_UNIX, errno, "cv_new");
clixon_err(OE_UNIX, errno, "cv_new");
goto done;
}
cv_string_set(cv, name);
if (cvec_append_var(modes, cv) < 0){
clicon_err(OE_UNIX, errno, "cvec_append_var");
clixon_err(OE_UNIX, errno, "cvec_append_var");
goto done;
}
if (cv)
@ -346,12 +346,12 @@ clispec_load_file(clicon_handle h,
if (cligen_ph_pipe_set(ph, pipetree) < 0)
goto done;
if (cligen_parsetree_merge(cligen_ph_parsetree_get(ph), NULL, pt) < 0){
clicon_err(OE_PLUGIN, errno, "cligen_parsetree_merge");
clixon_err(OE_PLUGIN, errno, "cligen_parsetree_merge");
goto done;
}
if (prompt){
if (cligen_ph_prompt_set(ph, prompt) < 0){
clicon_err(OE_UNIX, errno, "cligen_ph_prompt_set");
clixon_err(OE_UNIX, errno, "cligen_ph_prompt_set");
return -1;
}
}
@ -377,7 +377,7 @@ done:
* XXX The parsetree loading needs a rewrite for multiple parse-trees
*/
int
clispec_load(clicon_handle h)
clispec_load(clixon_handle h)
{
int retval = -1;
char *clispec_dir = NULL;
@ -394,11 +394,11 @@ clispec_load(clicon_handle h)
cg_var *cv = NULL;
if ((ptall = pt_new()) == NULL){
clicon_err(OE_UNIX, errno, "pt_new");
clixon_err(OE_UNIX, errno, "pt_new");
goto done;
}
if ((modes = cvec_new(0)) == NULL){
clicon_err(OE_UNIX, errno, "cvec_new");
clixon_err(OE_UNIX, errno, "cvec_new");
goto done;
}
/* Format plugin directory path */
@ -438,7 +438,7 @@ clispec_load(clicon_handle h)
if (cligen_parsetree_merge(cligen_ph_parsetree_get(ph),
NULL,
ptall) < 0){
clicon_err(OE_PLUGIN, errno, "cligen_parsetree_merge");
clixon_err(OE_PLUGIN, errno, "cligen_parsetree_merge");
goto done;
}
}
@ -469,7 +469,7 @@ done:
* @param[in] h Clixon handle
*/
int
cli_plugin_finish(clicon_handle h)
cli_plugin_finish(clixon_handle h)
{
return 0;
}
@ -478,19 +478,19 @@ cli_plugin_finish(clicon_handle h)
*
* Sometimes the libraries specify an error string, if so print that.
* Otherwise just print 'command error'.
* But do not print it if error is already logged in eg clicon_err() using STDERR logging
* But do not print it if error is already logged in eg clixon_err() using STDERR logging
* See eg https://github.com/clicon/clixon/issues/325
* @param[in] f File handler to write error to.
*/
int
cli_handler_err(FILE *f)
{
if (clicon_errno){
if (clixon_err_category()){
/* Check if error is already logged on stderr */
if ((clicon_get_logflags() & CLICON_LOG_STDERR) == 0){
fprintf(f, "%s: %s", clicon_strerror(clicon_errno), clicon_err_reason);
if (clicon_suberrno)
fprintf(f, ": %s", strerror(clicon_suberrno));
if ((clixon_get_logflags() & CLIXON_LOG_STDERR) == 0){
fprintf(f, "%s: %s", clixon_err_str(), clixon_err_reason());
if (clixon_err_subnr())
fprintf(f, ": %s", strerror(clixon_err_subnr()));
fprintf(f, "\n");
}
else
@ -517,7 +517,7 @@ cli_handler_err(FILE *f)
* @retval -1 Error
*/
int
clicon_parse(clicon_handle h,
clicon_parse(clixon_handle h,
char *cmd,
char **modenamep,
cligen_result *result,
@ -535,7 +535,7 @@ clicon_parse(clicon_handle h,
pt_head *ph;
ch = cli_cligen(h);
if (clicon_get_logflags()&CLICON_LOG_STDOUT)
if (clixon_get_logflags()&CLIXON_LOG_STDOUT)
f = stdout;
else
f = stderr;
@ -569,10 +569,10 @@ clicon_parse(clicon_handle h,
}
cli_output_reset();
if (!cligen_exiting(ch)) {
clicon_err_reset();
clixon_err_reset();
if ((ret = cligen_eval(ch, match_obj, cvv)) < 0) {
cli_handler_err(stdout);
if (clicon_suberrno == ESHUTDOWN)
if (clixon_err_subnr() == ESHUTDOWN)
goto done;
}
}
@ -610,7 +610,7 @@ done:
* @retval NULL Error
*/
static char *
cli_prompt_get(clicon_handle h,
cli_prompt_get(clixon_handle h,
char *fmt)
{
char *s = fmt;
@ -623,7 +623,7 @@ cli_prompt_get(clicon_handle h,
char *str0;
if ((cb = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new");
clixon_err(OE_XML, errno, "cbuf_new");
goto done;
}
/* Start with empty string */
@ -690,7 +690,7 @@ cli_prompt_get(clicon_handle h,
}
str0 = cbuf_len(cb) ? cbuf_get(cb) : CLI_DEFAULT_PROMPT;
if ((promptstr = strdup(str0)) == NULL){
clicon_err(OE_UNIX, errno, "strdup");
clixon_err(OE_UNIX, errno, "strdup");
goto done;
}
done:
@ -709,7 +709,7 @@ cli_prompt_get(clicon_handle h,
* @retval -1 Error
*/
int
clicon_cliread(clicon_handle h,
clicon_cliread(clixon_handle h,
pt_head *ph,
char **stringp)
{
@ -739,10 +739,10 @@ clicon_cliread(clicon_handle h,
cli_prompt_set(h, promptstr);
free(promptstr);
}
clicon_err_reset();
clixon_err_reset();
if (cliread(cli_cligen(h), stringp) < 0){
cli_handler_err(stdout);
if (clicon_suberrno == ESHUTDOWN)
if (clixon_err_subnr() == ESHUTDOWN)
goto done;
goto fail;
}
@ -770,7 +770,7 @@ clicon_cliread(clicon_handle h,
* @retval 0 Not found / error
*/
int
cli_set_syntax_mode(clicon_handle h,
cli_set_syntax_mode(clixon_handle h,
char *name)
{
@ -787,7 +787,7 @@ cli_set_syntax_mode(clicon_handle h,
* @param[in] h Clixon handle
*/
char *
cli_syntax_mode(clicon_handle h)
cli_syntax_mode(clixon_handle h)
{
pt_head *ph;

View file

@ -43,15 +43,15 @@
#include <netinet/in.h>
/* clicon generic callback pointer */
typedef void (clicon_callback_t)(clicon_handle h);
typedef void (clicon_callback_t)(clixon_handle h);
void *clixon_str2fn(char *name, void *handle, char **error);
int clicon_parse(clicon_handle h, char *cmd, char **mode, cligen_result *result, int *evalres);
int clicon_parse(clixon_handle h, char *cmd, char **mode, cligen_result *result, int *evalres);
int clicon_cliread(clicon_handle h, pt_head *ph, char **stringp);
int clicon_cliread(clixon_handle h, pt_head *ph, char **stringp);
int cli_plugin_finish(clicon_handle h);
int cli_plugin_finish(clixon_handle h);
#endif /* _CLI_PLUGIN_H_ */

View file

@ -66,7 +66,7 @@
/* cligen */
#include <cligen/cligen.h>
/* clicon */
/* clixon */
#include <clixon/clixon.h>
/* Exported functions in this file are in clixon_cli_api.h */
@ -115,7 +115,7 @@ xpath_append(cbuf *cb0,
int j;
if (cb0 == NULL){
clicon_err(OE_XML, EINVAL, "cb0 is NULL");
clixon_err(OE_XML, EINVAL, "cb0 is NULL");
goto done;
}
if (xpath1 == NULL || strlen(xpath1)==0)
@ -158,7 +158,7 @@ xpath_append(cbuf *cb0,
if ((ret = yang_find_namespace_by_prefix(y, prefix, &ns)) < 0)
goto done;
if (ret == 0){
clicon_err(OE_DB, 0, "Prefix %s does not have an associated namespace", prefix);
clixon_err(OE_DB, 0, "Prefix %s does not have an associated namespace", prefix);
goto done;
}
if (xml_nsctx_add(nsc, prefix, ns) < 0)
@ -250,32 +250,32 @@ expand_dbvar(void *h,
cvec *callback_cvv;
if (argv == NULL || (cvec_len(argv) != 2 && cvec_len(argv) != 3)){
clicon_err(OE_PLUGIN, EINVAL, "requires arguments: <db> <apipathfmt> [<mountpt>]");
clixon_err(OE_PLUGIN, EINVAL, "requires arguments: <db> <apipathfmt> [<mountpt>]");
goto done;
}
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 ((cv = cvec_i(argv, 0)) == NULL){
clicon_err(OE_PLUGIN, 0, "Error when accessing argument <db>");
clixon_err(OE_PLUGIN, 0, "Error when accessing argument <db>");
goto done;
}
dbstr = cv_string_get(cv);
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 ((cv = cvec_i(argv, 1)) == NULL){
clicon_err(OE_PLUGIN, 0, "Error when accessing argument <api_path>");
clixon_err(OE_PLUGIN, 0, "Error when accessing argument <api_path>");
goto done;
}
if (autocli_grouping_treeref(h, &grouping_treeref) < 0)
goto done;
if ((api_path_fmt_cb = cbuf_new()) == NULL){
clicon_err(OE_PLUGIN, errno, "cbuf_new");
clixon_err(OE_PLUGIN, errno, "cbuf_new");
goto done;
}
if (grouping_treeref &&
@ -290,7 +290,7 @@ expand_dbvar(void *h,
cv = cvec_i(argv, 2);
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:");
@ -320,8 +320,7 @@ expand_dbvar(void *h,
if ((ret = api_path2xml(api_path, yspec, xtop, YC_DATANODE, 0, &xbot, &y, &xerr)) < 0)
goto done;
if (ret == 0){
// XXX cf cli_dbxml
clixon_netconf_error(h, xerr, "Expand datastore symbol", NULL);
clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Expand datastore symbol");
goto done;
}
}
@ -331,7 +330,7 @@ expand_dbvar(void *h,
if (api_path2xpath(api_path, yspec, &xpath, &nsc, NULL) < 0)
goto done;
if ((cbxpath = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new");
clixon_err(OE_UNIX, errno, "cbuf_new");
goto done;
}
if (mtpoint){
@ -372,7 +371,7 @@ expand_dbvar(void *h,
* the "path" statement is defined.
*/
if ((ypath = yang_find(ytype, Y_PATH, NULL)) == NULL){
clicon_err(OE_DB, 0, "Leafref %s requires path statement", yang_argument_get(ytype));
clixon_err(OE_DB, 0, "Leafref %s requires path statement", yang_argument_get(ytype));
goto done;
}
/* Extend xpath with leafref path: Append yang_argument_get(ypath) to xpath
@ -384,7 +383,7 @@ expand_dbvar(void *h,
if (clicon_rpc_get_config(h, NULL, dbstr, cbuf_get(cbxpath), nsc, NULL, &xt) < 0)
goto done;
if ((xe = xpath_first(xt, NULL, "/rpc-error")) != NULL){
clixon_netconf_error(h, xe, "Get configuration", NULL);
clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Get configuration");
goto ok;
}
if (xpath_vec(xt, nsc, "%s", &xvec, &xlen, cbuf_get(cbxpath)) < 0)
@ -462,7 +461,7 @@ expand_dbvar(void *h,
* @retval -1 Error
*/
int
show_yang(clicon_handle h,
show_yang(clixon_handle h,
cvec *cvv,
cvec *argv)
{
@ -508,7 +507,7 @@ show_yang(clicon_handle h,
* @retval -1 Error
*/
int
cli_show_common(clicon_handle h,
cli_show_common(clixon_handle h,
char *db,
enum format_enum format,
int pretty,
@ -531,7 +530,7 @@ cli_show_common(clicon_handle h,
int i;
if (state && strcmp(db, "running") != 0){
clicon_err(OE_FATAL, 0, "Show state only for running database, not %s", db);
clixon_err(OE_FATAL, 0, "Show state only for running database, not %s", db);
goto done;
}
if (state == 0){ /* Get configuration-only from a database */
@ -543,7 +542,7 @@ cli_show_common(clicon_handle h,
goto done;
}
if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){
clixon_netconf_error(h, xerr, "Get configuration", NULL);
clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Get configuration");
goto done;
}
/* Special tagged modes: strip wd:default=true attribute and (optionally) nodes associated with it */
@ -640,7 +639,7 @@ cli_show_option_format(cvec *argv,
formatstr = cv_string_get(cvec_i(argv, argc));
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;
}
retval = 0;
@ -668,11 +667,11 @@ cli_show_option_bool(cvec *argv,
boolstr = cv_string_get(cvec_i(argv, argc));
if ((boolcv = cv_new(CGV_BOOL)) == NULL){
clicon_err(OE_UNIX, errno, "cv_new");
clixon_err(OE_UNIX, errno, "cv_new");
goto done;
}
if (cv_parse(boolstr, boolcv) < 0){
clicon_err(OE_UNIX, errno, "Parse boolean %s", boolstr);
clixon_err(OE_UNIX, errno, "Parse boolean %s", boolstr);
goto done;
}
*result = cv_bool_get(boolcv);
@ -719,7 +718,7 @@ cli_show_option_withdefault(cvec *argv,
strcmp(e, "trim") != 0 &&
strcmp(e, "explicit") != 0 &&
strcmp(e, "report-all-tagged") != 0){
clicon_err(OE_YANG, EINVAL, "Unexpected with-default option: %s", e);
clixon_err(OE_YANG, EINVAL, "Unexpected with-default option: %s", e);
goto done;
}
else
@ -765,7 +764,7 @@ cli_show_option_withdefault(cvec *argv,
* @see cli_show_auto_mode autocli with edit menu support
*/
int
cli_show_config(clicon_handle h,
cli_show_config(clixon_handle h,
cvec *cvv,
cvec *argv)
{
@ -784,7 +783,7 @@ cli_show_config(clicon_handle h,
int fromroot = 0;
if (cvec_len(argv) < 2 || cvec_len(argv) > 8){
clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: <dbname> [<format><xpath> <namespace> <pretty> <state> <default> <prepend>]", cvec_len(argv));
clixon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: <dbname> [<format><xpath> <namespace> <pretty> <state> <default> <prepend>]", cvec_len(argv));
goto done;
}
dbname = cv_string_get(cvec_i(argv, argc++));
@ -838,7 +837,7 @@ cli_show_config(clicon_handle h,
* @retval -1 Error
*/
int
show_conf_xpath(clicon_handle h,
show_conf_xpath(clixon_handle h,
cvec *cvv,
cvec *argv)
{
@ -851,17 +850,17 @@ show_conf_xpath(clicon_handle h,
int fromroot = 0;
if (cvec_len(argv) != 1){
clicon_err(OE_PLUGIN, EINVAL, "Requires one element to be <dbname>");
clixon_err(OE_PLUGIN, EINVAL, "Requires one element to be <dbname>");
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;
}
dbname = cv_string_get(cvec_i(argv, 0));
/* Look for xpath in command (kludge: cv must be called "xpath") */
if ((cv = cvec_find(cvv, "xpath")) == NULL){
clicon_err(OE_PLUGIN, EINVAL, "Requires one variable to be <xpath>");
clixon_err(OE_PLUGIN, EINVAL, "Requires one variable to be <xpath>");
goto done;
}
xpath = cv_string_get(cv);
@ -887,7 +886,7 @@ done:
/*! Show clixon and CLIgen versions
*/
int
cli_show_version(clicon_handle h,
cli_show_version(clixon_handle h,
cvec *cvv,
cvec *argv)
{
@ -936,7 +935,7 @@ cli_show_version(clicon_handle h,
* @see cli_callback_generate where api_path_fmt + mt-point are generated
*/
int
cli_show_auto(clicon_handle h,
cli_show_auto(clixon_handle h,
cvec *cvv,
cvec *argv)
{
@ -961,7 +960,7 @@ cli_show_auto(clicon_handle h,
int fromroot = 0;
if (cvec_len(argv) < 2 || cvec_len(argv) > 9){
clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected:: <api-path-fmt>* <database> [<format> <pretty> <state> <default> <prepend> <fromroot>]", cvec_len(argv));
clixon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected:: <api-path-fmt>* <database> [<format> <pretty> <state> <default> <prepend> <fromroot>]", cvec_len(argv));
goto done;
}
api_path_fmt = cv_string_get(cvec_i(argv, argc++));
@ -997,7 +996,7 @@ cli_show_auto(clicon_handle h,
goto done;
}
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 (mtpoint){
@ -1014,7 +1013,7 @@ cli_show_auto(clicon_handle h,
if (api_path2xpath(api_path, yspec0, &xpath, &nsc, NULL) < 0)
goto done;
if (xpath == NULL){
clicon_err(OE_FATAL, 0, "Invalid api-path: %s", api_path);
clixon_err(OE_FATAL, 0, "Invalid api-path: %s", api_path);
goto done;
}
if (cli_show_common(h, dbname, format, pretty, state,
@ -1069,7 +1068,7 @@ code
* @see cli_show_config with no autocli coupling
*/
int
cli_show_auto_mode(clicon_handle h,
cli_show_auto_mode(clixon_handle h,
cvec *cvv,
cvec *argv)
{
@ -1096,11 +1095,11 @@ cli_show_auto_mode(clicon_handle h,
int fromroot = 0;
if (cvec_len(argv) < 2 || cvec_len(argv) > 7){
clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: <database> [ <format> <pretty> <state> <default> <cli-prefix>]", cvec_len(argv));
clixon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: <database> [ <format> <pretty> <state> <default> <cli-prefix>]", cvec_len(argv));
goto done;
}
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;
}
dbname = cv_string_get(cvec_i(argv, argc++));
@ -1140,11 +1139,11 @@ cli_show_auto_mode(clicon_handle h,
if (api_path2xpath(api_path, yspec, &xpath, &nsc, NULL) < 0)
goto done;
if (xpath == NULL){
clicon_err(OE_FATAL, 0, "Invalid api-path: %s", api_path);
clixon_err(OE_FATAL, 0, "Invalid api-path: %s", api_path);
goto done;
}
if ((cbxpath = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new");
clixon_err(OE_UNIX, errno, "cbuf_new");
goto done;
}
if (mtpoint){
@ -1184,7 +1183,7 @@ cli_show_auto_mode(clicon_handle h,
'* @see clicon_option_dump clicon_option_dump1
*/
int
cli_show_options(clicon_handle h,
cli_show_options(clixon_handle h,
cvec *cvv,
cvec *argv)
{
@ -1248,7 +1247,7 @@ cli_show_options(clicon_handle h,
* Also, if there is a cligen variable called "xpath" it will override argv xpath arg
*/
int
cli_pagination(clicon_handle h,
cli_pagination(clixon_handle h,
cvec *cvv,
cvec *argv)
{
@ -1272,7 +1271,7 @@ cli_pagination(clicon_handle h,
int locked = 0;
if (cvec_len(argv) != 5){
clicon_err(OE_PLUGIN, 0, "Expected usage: <xpath> <prefix> <namespace> <format> <limit>");
clixon_err(OE_PLUGIN, 0, "Expected usage: <xpath> <prefix> <namespace> <format> <limit>");
goto done;
}
/* prefix:variable overrides argv */
@ -1284,17 +1283,17 @@ cli_pagination(clicon_handle h,
namespace = cvec_i_str(argv, 2);
str = cv_string_get(cvec_i(argv, 3)); /* Fourthformat: output format */
if ((int)(format = format_str2int(str)) < 0){
clicon_err(OE_PLUGIN, 0, "Not valid format: %s", str);
clixon_err(OE_PLUGIN, 0, "Not valid format: %s", str);
goto done;
}
if ((str = cv_string_get(cvec_i(argv, 4))) != NULL){
if (parse_uint32(str, &limit, NULL) < 1){
clicon_err(OE_UNIX, errno, "error parsing limit:%s", str);
clixon_err(OE_UNIX, errno, "error parsing limit:%s", str);
goto done;
}
}
if (limit == 0){
clicon_err(OE_UNIX, EINVAL, "limit is 0");
clixon_err(OE_UNIX, EINVAL, "limit is 0");
goto done;
}
if ((nsc = xml_nsctx_init(prefix, namespace)) == NULL)
@ -1314,7 +1313,7 @@ cli_pagination(clicon_handle h,
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 (xpath_vec(xret, nsc, "%s", &xvec, &xlen, xpath) < 0)
@ -1386,7 +1385,7 @@ cli_pagination(clicon_handle h,
* @see clixon_cli2file
*/
static int
cli2cbuf(clicon_handle h,
cli2cbuf(clixon_handle h,
cbuf *cb,
cxobj *xn,
char *prepend)
@ -1435,7 +1434,7 @@ cli2cbuf(clicon_handle h,
}
/* Create prepend variable string */
if ((cbpre = cbuf_new()) == NULL){
clicon_err(OE_PLUGIN, errno, "cbuf_new");
clixon_err(OE_PLUGIN, errno, "cbuf_new");
goto done;
}
if (prepend)
@ -1514,7 +1513,7 @@ cli2cbuf(clicon_handle h,
* @retval -1 Error
*/
static int
cli2file(clicon_handle h,
cli2file(clixon_handle h,
FILE *f,
cxobj *xn,
char *prepend,
@ -1564,7 +1563,7 @@ cli2file(clicon_handle h,
}
/* Create prepend variable string */
if ((cbpre = cbuf_new()) == NULL){
clicon_err(OE_PLUGIN, errno, "cbuf_new");
clixon_err(OE_PLUGIN, errno, "cbuf_new");
goto done;
}
if (prepend)
@ -1645,7 +1644,7 @@ cli2file(clicon_handle h,
* @see clixon_cli2cbuf
*/
int
clixon_cli2file(clicon_handle h,
clixon_cli2file(clixon_handle h,
FILE *f,
cxobj *xn,
char *prepend,
@ -1687,7 +1686,7 @@ clixon_cli2file(clicon_handle h,
* @see clixon_cli2file
*/
int
clixon_cli2cbuf(clicon_handle h,
clixon_cli2cbuf(clixon_handle h,
cbuf *cb,
cxobj *xn,
char *prepend,
@ -1714,7 +1713,7 @@ clixon_cli2cbuf(clicon_handle h,
/*! CLI callback show statistics
*/
int
cli_show_statistics(clicon_handle h,
cli_show_statistics(clixon_handle h,
cvec *cvv,
cvec *argv)
{
@ -1730,7 +1729,7 @@ cli_show_statistics(clicon_handle h,
size_t sz = 0;
if (argv != NULL && cvec_len(argv) != 1){
clicon_err(OE_PLUGIN, EINVAL, "Expected arguments: [modules]");
clixon_err(OE_PLUGIN, EINVAL, "Expected arguments: [modules]");
goto done;
}
if (argv){
@ -1738,7 +1737,7 @@ cli_show_statistics(clicon_handle h,
modules = (strcmp(cv_string_get(cv), "modules") == 0);
}
if ((cb = cbuf_new()) == NULL){
clicon_err(OE_PLUGIN, errno, "cbuf_new");
clixon_err(OE_PLUGIN, errno, "cbuf_new");
goto done;
}
/* CLI */
@ -1764,7 +1763,7 @@ cli_show_statistics(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;
}
fprintf(stdout, "Backend:\n");

View file

@ -53,17 +53,17 @@ extern "C" {
*
* @see plginit_t
*/
int plugin_init(clicon_handle h);
int plugin_init(clixon_handle h);
/* Called when backend started with cmd-line arguments from daemon call.
* @see plgstart_t
*/
int plugin_start(clicon_handle h, int argc, char **argv);
int plugin_start(clixon_handle h, int argc, char **argv);
/* Called just before plugin unloaded.
* @see plgexit_t
*/
int plugin_exit(clicon_handle h);
int plugin_exit(clixon_handle h);
#endif /* _CLIXON_CLI_H_ */

View file

@ -63,21 +63,21 @@ typedef enum autocli_listkw autocli_listkw_t;
* Function Declarations
*/
/* cli_plugin.c */
int cli_set_syntax_mode(clicon_handle h, char *mode);
char *cli_syntax_mode(clicon_handle h);
int clispec_load(clicon_handle h);
int cli_set_syntax_mode(clixon_handle h, char *mode);
char *cli_syntax_mode(clixon_handle h);
int clispec_load(clixon_handle h);
int cli_handler_err(FILE *fd);
int cli_set_prompt(clicon_handle h, char *mode, char *prompt);
int cli_ptpush(clicon_handle h, char *mode, char *string, char *op);
int cli_ptpop(clicon_handle h, char *mode, char *op);
int cli_set_prompt(clixon_handle h, char *mode, char *prompt);
int cli_ptpush(clixon_handle h, char *mode, char *string, char *op);
int cli_ptpop(clixon_handle h, char *mode, char *op);
/* cli_handle.c */
clicon_handle cli_handle_init(void);
int cli_handle_exit(clicon_handle h);
cligen_handle cli_cligen(clicon_handle h);
clixon_handle cli_handle_init(void);
int cli_handle_exit(clixon_handle h);
cligen_handle cli_cligen(clixon_handle h);
/* cli_common.c */
int cli_notification_register(clicon_handle h, char *stream, enum format_enum format,
int cli_notification_register(clixon_handle h, char *stream, enum format_enum format,
char *filter, int status,
int (*fn)(int, void*), void *arg);
@ -85,70 +85,70 @@ int mtpoint_paths(yang_stmt *yspec0, char *mtpoint, char *api_path_fmt1, char **
int dbxml_body(cxobj *xbot, cvec *cvv);
int identityref_add_ns(cxobj *x, void *arg);
int cli_dbxml(clicon_handle h, cvec *vars, cvec *argv, enum operation_type op, cvec *nsctx);
int cli_set(clicon_handle h, cvec *vars, cvec *argv);
int cli_merge(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_debug_cli(clicon_handle h, cvec *vars, cvec *argv);
int cli_debug_backend(clicon_handle h, cvec *vars, cvec *argv);
int cli_debug_restconf(clicon_handle h, cvec *vars, cvec *argv);
int cli_set_mode(clicon_handle h, cvec *vars, cvec *argv);
int cli_start_shell(clicon_handle h, cvec *vars, cvec *argv);
int cli_quit(clicon_handle h, cvec *vars, cvec *argv);
int cli_commit(clicon_handle h, cvec *vars, cvec *argv);
int cli_validate(clicon_handle h, cvec *vars, cvec *argv);
int compare_db_names(clicon_handle h, enum format_enum format, char *db1, char *db2);
int compare_dbs(clicon_handle h, cvec *vars, cvec *argv);
int load_config_file(clicon_handle h, cvec *vars, cvec *argv);
int save_config_file(clicon_handle h, cvec *vars, cvec *argv);
int delete_all(clicon_handle h, cvec *vars, cvec *argv);
int discard_changes(clicon_handle h, cvec *vars, cvec *argv);
int cli_notify(clicon_handle h, cvec *cvv, cvec *argv);
int db_copy(clicon_handle h, cvec *cvv, cvec *argv);
int cli_lock(clicon_handle h, cvec *cvv, cvec *argv);
int cli_unlock(clicon_handle h, cvec *cvv, cvec *argv);
int cli_copy_config(clicon_handle h, cvec *cvv, cvec *argv);
int cli_help(clicon_handle h, cvec *vars, cvec *argv);
int cli_dbxml(clixon_handle h, cvec *vars, cvec *argv, enum operation_type op, cvec *nsctx);
int cli_set(clixon_handle h, cvec *vars, cvec *argv);
int cli_merge(clixon_handle h, cvec *vars, cvec *argv);
int cli_create(clixon_handle h, cvec *vars, cvec *argv);
int cli_remove(clixon_handle h, cvec *vars, cvec *argv);
int cli_del(clixon_handle h, cvec *vars, cvec *argv);
int cli_debug_cli(clixon_handle h, cvec *vars, cvec *argv);
int cli_debug_backend(clixon_handle h, cvec *vars, cvec *argv);
int cli_debug_restconf(clixon_handle h, cvec *vars, cvec *argv);
int cli_set_mode(clixon_handle h, cvec *vars, cvec *argv);
int cli_start_shell(clixon_handle h, cvec *vars, cvec *argv);
int cli_quit(clixon_handle h, cvec *vars, cvec *argv);
int cli_commit(clixon_handle h, cvec *vars, cvec *argv);
int cli_validate(clixon_handle h, cvec *vars, cvec *argv);
int compare_db_names(clixon_handle h, enum format_enum format, char *db1, char *db2);
int compare_dbs(clixon_handle h, cvec *vars, cvec *argv);
int load_config_file(clixon_handle h, cvec *vars, cvec *argv);
int save_config_file(clixon_handle h, cvec *vars, cvec *argv);
int delete_all(clixon_handle h, cvec *vars, cvec *argv);
int discard_changes(clixon_handle h, cvec *vars, cvec *argv);
int cli_notify(clixon_handle h, cvec *cvv, cvec *argv);
int db_copy(clixon_handle h, cvec *cvv, cvec *argv);
int cli_lock(clixon_handle h, cvec *cvv, cvec *argv);
int cli_unlock(clixon_handle h, cvec *cvv, cvec *argv);
int cli_copy_config(clixon_handle h, cvec *cvv, cvec *argv);
int cli_help(clixon_handle h, cvec *vars, cvec *argv);
cvec *cvec_append(cvec *cvv0, cvec *cvv1);
int cvec_concat_cb(cvec *cvv, cbuf *cb);
int cli_process_control(clicon_handle h, cvec *vars, cvec *argv);
int cli_process_control(clixon_handle h, cvec *vars, cvec *argv);
/* In cli_show.c */
int expand_dbvar(void *h, char *name, cvec *cvv, cvec *argv,
cvec *commands, cvec *helptexts);
int clixon_cli2file(clicon_handle h, FILE *f, cxobj *xn, char *prepend, clicon_output_cb *fn, int skiptop);
int clixon_cli2cbuf(clicon_handle h, cbuf *cb, cxobj *xn, char *prepend, int skiptop);
int clixon_cli2file(clixon_handle h, FILE *f, cxobj *xn, char *prepend, clicon_output_cb *fn, int skiptop);
int clixon_cli2cbuf(clixon_handle h, cbuf *cb, cxobj *xn, char *prepend, int skiptop);
/* cli_show.c: CLIgen new vector arg callbacks */
int cli_show_common(clicon_handle h, char *db, enum format_enum format, int pretty, int state, char *withdefault, char *extdefault, char *prepend, char *xpath, int fromroot, cvec *nsc, int skiptop);
int cli_show_common(clixon_handle h, char *db, enum format_enum format, int pretty, int state, char *withdefault, char *extdefault, char *prepend, char *xpath, int fromroot, cvec *nsc, int skiptop);
int show_yang(clicon_handle h, cvec *vars, cvec *argv);
int show_conf_xpath(clicon_handle h, cvec *cvv, cvec *argv);
int show_yang(clixon_handle h, cvec *vars, cvec *argv);
int show_conf_xpath(clixon_handle h, cvec *cvv, cvec *argv);
int cli_show_option_format(cvec *argv, int argc, enum format_enum *format);
int cli_show_option_bool(cvec *argv, int argc, int *result);
int cli_show_option_withdefault(cvec *argv, int argc, char **withdefault, char **extdefault);
int cli_show_config(clicon_handle h, cvec *cvv, cvec *argv);
int cli_show_config(clixon_handle h, cvec *cvv, cvec *argv);
int cli_show_config_state(clicon_handle h, cvec *cvv, cvec *argv);
int cli_show_config_state(clixon_handle h, cvec *cvv, cvec *argv);
int cli_show_auto(clicon_handle h, cvec *cvv, cvec *argv);
int cli_show_auto(clixon_handle h, cvec *cvv, cvec *argv);
int cli_show_options(clicon_handle h, cvec *cvv, cvec *argv);
int cli_show_version(clicon_handle h, cvec *vars, cvec *argv);
int cli_show_options(clixon_handle h, cvec *cvv, cvec *argv);
int cli_show_version(clixon_handle h, cvec *vars, cvec *argv);
/* cli_auto.c: Autocli mode support */
int cli_auto_edit(clicon_handle h, cvec *cvv1, cvec *argv);
int cli_auto_up(clicon_handle h, cvec *cvv, cvec *argv);
int cli_auto_top(clicon_handle h, cvec *cvv, cvec *argv);
int cli_show_auto_mode(clicon_handle h, cvec *cvv, cvec *argv);
int cli_auto_set(clicon_handle h, cvec *cvv, cvec *argv);
int cli_auto_merge(clicon_handle h, cvec *cvv, cvec *argv);
int cli_auto_create(clicon_handle h, cvec *cvv, cvec *argv);
int cli_auto_del(clicon_handle h, cvec *cvv, cvec *argv);
int cli_auto_sub_enter(clicon_handle h, cvec *cvv, cvec *argv);
int cli_auto_edit(clixon_handle h, cvec *cvv1, cvec *argv);
int cli_auto_up(clixon_handle h, cvec *cvv, cvec *argv);
int cli_auto_top(clixon_handle h, cvec *cvv, cvec *argv);
int cli_show_auto_mode(clixon_handle h, cvec *cvv, cvec *argv);
int cli_auto_set(clixon_handle h, cvec *cvv, cvec *argv);
int cli_auto_merge(clixon_handle h, cvec *cvv, cvec *argv);
int cli_auto_create(clixon_handle h, cvec *cvv, cvec *argv);
int cli_auto_del(clixon_handle h, cvec *cvv, cvec *argv);
int cli_auto_sub_enter(clixon_handle h, cvec *cvv, cvec *argv);
int cli_pagination(clicon_handle h, cvec *cvv, cvec *argv);
int cli_pagination(clixon_handle h, cvec *cvv, cvec *argv);
#endif /* _CLIXON_CLI_API_H_ */