diff --git a/CHANGELOG.md b/CHANGELOG.md index 46c0ee11..9faaded1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ * Previous support did no validation of values. * Validation of types and CLI expansion * Example extended with inclusion of iana-if-type RFC 7224 interface identities - + * Applications which have not strictly enforced the identities may now have problems with validation and may need to be modified. ### Minor changes: * Added yang identityref runtime validation * Removed cli callback vector functions. Set COMPAT_COMPAT_CLIV if you need to keep these functions in clixon_custom.h. diff --git a/apps/cli/cli_main.c b/apps/cli/cli_main.c index 2e269016..4e5b2048 100644 --- a/apps/cli/cli_main.c +++ b/apps/cli/cli_main.c @@ -119,7 +119,7 @@ cli_interactive(clicon_handle h) int res; char *cmd; char *new_mode; - int result; + int eval; /* Loop through all commands */ while(!cligen_exiting(cli_cligen(h))) { @@ -128,7 +128,7 @@ cli_interactive(clicon_handle h) cligen_exiting_set(cli_cligen(h), 1); /* EOF */ goto done; } - if ((res = clicon_parse(h, cmd, &new_mode, &result)) < 0) + if ((res = clicon_parse(h, cmd, &new_mode, &eval)) < 0) goto done; } retval = 0; diff --git a/apps/cli/cli_plugin.c b/apps/cli/cli_plugin.c index 193e6df3..92caf7fd 100644 --- a/apps/cli/cli_plugin.c +++ b/apps/cli/cli_plugin.c @@ -444,6 +444,8 @@ cli_handler_err(FILE *f) /*! Evaluate a matched command * @param[in] h Clicon handle * @param[in] cmd The command string + * @retval int If there is a callback, the return value of the callback is returned, + * @retval 0 otherwise */ int clicon_eval(clicon_handle h, @@ -451,10 +453,12 @@ clicon_eval(clicon_handle h, cg_obj *match_obj, cvec *cvv) { + int retval = 0; + cli_output_reset(); if (!cligen_exiting(cli_cligen(h))) { clicon_err_reset(); - if (cligen_eval(cli_cligen(h), match_obj, cvv) < 0) { + if ((retval = cligen_eval(cli_cligen(h), match_obj, cvv)) < 0) { #if 0 /* This is removed since we get two error messages on failure. But maybe only sometime? Both a real log when clicon_err is called, and the here again. @@ -463,11 +467,10 @@ clicon_eval(clicon_handle h, #endif } } - return 0; + return retval; } - -/*! Given a command string, parse and evaluate. +/*! Given a command string, parse and if match single command, eval it. * Parse and evaluate the string according to * the syntax parse tree of the syntax mode specified by *mode. * If there is no match in the tree for the command, the parse hook @@ -478,20 +481,25 @@ clicon_eval(clicon_handle h, * @param[in] h Clicon handle * @param[in] cmd Command string * @param[in,out] modenamep Pointer to the mode string pointer - * @param[out] result -2 On eof (shouldnt happen) + * @param[out] evalres Evaluation result if retval=1 + * -2 On eof (shouldnt happen) * -1 On parse error * >=0 Number of matches - * @retval 0 XXX How does this relate to result??? + * @retval -2 Eof CG_EOF + * @retval -1 Error CG_ERROR + * @retval 0 No match CG_NOMATCH + * @retval 1 Exactly one match CG_MATCH + * @retval 2+ Multiple matches */ int clicon_parse(clicon_handle h, char *cmd, char **modenamep, - int *result) + int *evalres) { + int retval = -1; char *modename; char *modename0; - int retval = -1; int r; cli_syntax_t *stx = NULL; cli_syntaxmode_t *smode; @@ -515,8 +523,7 @@ clicon_parse(clicon_handle h, goto done; } } - if (smode) - while(1) { + if (smode){ modename0 = NULL; if ((pt = cligen_tree_active_get(cli_cligen(h))) != NULL) modename0 = pt->pt_name; @@ -543,13 +550,12 @@ clicon_parse(clicon_handle h, case CG_EOF: /* eof */ case CG_ERROR: cli_output(f, "CLI parse error: %s\n", cmd); - goto done; + break; case CG_NOMATCH: /* no match */ /* clicon_err(OE_CFG, 0, "CLI syntax error: \"%s\": %s", cmd, cli_nomatch(h));*/ cli_output(f, "CLI syntax error: \"%s\": %s\n", cmd, cli_nomatch(h)); - goto done; break; case CG_MATCH: if (strcmp(modename, *modenamep)){ /* Command in different mode */ @@ -559,16 +565,14 @@ clicon_parse(clicon_handle h, if ((r = clicon_eval(h, cmd, match_obj, cvv)) < 0) cli_handler_err(stdout); pt_expand_cleanup_1(pt); /* XXX change to pt_expand_treeref_cleanup */ - if (result) - *result = r; - goto done; + if (evalres) + *evalres = r; break; default: cli_output(f, "CLI syntax error: \"%s\" is ambiguous\n", cmd); - goto done; break; } /* switch retval */ - } /* while smode */ + } done: if (cvv) cvec_free(cvv); diff --git a/apps/cli/cli_show.c b/apps/cli/cli_show.c index ed92d5de..94a4c7c4 100644 --- a/apps/cli/cli_show.c +++ b/apps/cli/cli_show.c @@ -161,7 +161,7 @@ expand_dbvar(void *h, goto done; if ((xerr = xpath_first(xt, "/rpc-error")) != NULL){ clicon_rpc_generate_error("Get configuration", xerr); - goto done; + goto ok; } xcur = xt; /* default top-of-tree */ xpathcur = xpath;