C-style update: Unified comment, retvals in order, remove trailing spaces

Changed function name for `clicon_debug` functions
This commit is contained in:
Olof hagsand 2023-10-22 18:04:47 +02:00
parent 6e314dd96f
commit 62348fc9c7
204 changed files with 6047 additions and 4904 deletions

View file

@ -86,7 +86,7 @@ co2apipath(cg_obj *co)
cg_callback *cb;
cvec *cvv;
cg_var *cv;
if (co == NULL)
return NULL;
if ((cb = co->co_callbacks) == NULL)
@ -121,7 +121,7 @@ cli_auto_edit(clicon_handle h,
char *api_path_fmt; /* xml key format */
char *api_path = NULL;
char *treename;
pt_head *ph;
pt_head *ph;
cg_obj *co;
cg_obj *coorig;
cvec *cvv2 = NULL; /* cvv2 = cvv0 + cvv1 */
@ -137,7 +137,7 @@ cli_auto_edit(clicon_handle h,
str = cv_string_get(cvec_i(argv, argc++));
if (str && strncmp(str, "mtpoint:", strlen("mtpoint:")) == 0){
mtpoint = str + strlen("mtpoint:");
clicon_debug(1, "%s mtpoint:%s", __FUNCTION__, mtpoint);
clixon_debug(CLIXON_DBG_DEFAULT, "%s mtpoint:%s", __FUNCTION__, mtpoint);
treename = cv_string_get(cvec_i(argv, argc++));
}
else
@ -181,7 +181,7 @@ cli_auto_edit(clicon_handle h,
char *mtpoint2;
if ((mtpoint2 = strdup(mtpoint)) == NULL){
clicon_err(OE_UNIX, errno, "strdup");
goto done;
goto done;
}
if (clicon_data_set(h, "cli-edit-mtpoint", mtpoint2) < 0)
goto done;
@ -205,9 +205,12 @@ cli_auto_edit(clicon_handle h,
}
/*! CLI callback: Working point tree up to parent
*
* @param[in] h CLICON handle
* @param[in] cvv Vector of variables from CLIgen command-line
* @param[in] argv Vector of user-supplied keywords
* @retval 0 OK
* @retval -1 Error
* Format of argv:
* <treename> Name of generated cligen parse-tree, eg "datamodel"
*/
@ -231,7 +234,7 @@ cli_auto_up(clicon_handle h,
int j;
size_t len;
cvec *cvv_filter = NULL;
if (cvec_len(argv) != 1){
clicon_err(OE_PLUGIN, EINVAL, "Usage: %s(<treename>)", __FUNCTION__);
goto done;
@ -283,7 +286,7 @@ cli_auto_up(clicon_handle h,
cvv1 = cvec_new(0);
for (i=0; i<cvec_len(cvv0)-j; i++){
cv = cvec_i(cvv0, i);
cvec_append_var(cvv1, cv);
cvec_append_var(cvv1, cv);
}
/* get api-path and xpath */
if (api_path_fmt2api_path(api_path_fmt1, cvv1, &api_path, NULL) < 0)
@ -300,9 +303,12 @@ cli_auto_up(clicon_handle h,
}
/*! CLI callback: Working point tree reset to top level
*
* @param[in] h CLICON handle
* @param[in] cvv Vector of variables from CLIgen command-line
* @param[in] argv Vector of user-supplied keywords
* @retval 0 OK
* @retval -1 Error
* Format of argv:
* <treename> Name of generated cligen parse-tree, eg "datamodel"
*/
@ -315,7 +321,7 @@ cli_auto_top(clicon_handle h,
cg_var *cv;
char *treename;
pt_head *ph;
cv = cvec_i(argv, 0);
treename = cv_string_get(cv);
if ((ph = cligen_ph_find(cli_cligen(h), treename)) == NULL){
@ -333,20 +339,23 @@ cli_auto_top(clicon_handle h,
}
/*! CLI callback: set auto db item
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] cvv Vector of cli string and instantiated variables
* @param[in] argv Vector. First element xml key format string, eg "/aaa/%s"
* @retval 0 OK
* @retval -1 Error
* Format of argv:
* <api-path-fmt> Generated
*/
int
int
cli_auto_set(clicon_handle h,
cvec *cvv,
cvec *argv)
{
int retval = -1;
cvec *cvv2 = NULL;
cvv2 = cvec_append(clicon_data_cvec_get(h, "cli-edit-cvv"), cvv);
if (cli_dbxml(h, cvv2, argv, OP_REPLACE, NULL) < 0)
goto done;
@ -358,18 +367,21 @@ cli_auto_set(clicon_handle h,
}
/*! Merge datastore xml entry
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] cvv Vector of cli string and instantiated variables
* @param[in] argv Vector. First element xml key format string, eg "/aaa/%s"
* @retval 0 OK
* @retval -1 Error
*/
int
int
cli_auto_merge(clicon_handle h,
cvec *cvv,
cvec *argv)
{
int retval = -1;
cvec *cvv2 = NULL;
cvv2 = cvec_append(clicon_data_cvec_get(h, "cli-edit-cvv"), cvv);
if (cli_dbxml(h, cvv2, argv, OP_MERGE, NULL) < 0)
goto done;
@ -381,18 +393,21 @@ cli_auto_merge(clicon_handle h,
}
/*! Create datastore xml entry
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] cvv Vector of cli string and instantiated variables
* @param[in] argv Vector. First element xml key format string, eg "/aaa/%s"
* @retval 0 OK
* @retval -1 Error
*/
int
int
cli_auto_create(clicon_handle h,
cvec *cvv,
cvec *argv)
{
int retval = -1;
int retval = -1;
cvec *cvv2 = NULL;
cvv2 = cvec_append(clicon_data_cvec_get(h, "cli-edit-cvv"), cvv);
if (cli_dbxml(h, cvv2, argv, OP_CREATE, NULL) < 0)
goto done;
@ -404,18 +419,21 @@ cli_auto_create(clicon_handle h,
}
/*! Delete datastore xml
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] cvv Vector of cli string and instantiated variables
* @param[in] argv Vector. First element xml key format string, eg "/aaa/%s"
* @retval 0 OK
* @retval -1 Error
*/
int
int
cli_auto_del(clicon_handle h,
cvec *cvv,
cvec *argv)
{
int retval = -1;
cvec *cvv2 = NULL;
cvv2 = cvec_append(clicon_data_cvec_get(h, "cli-edit-cvv"), cvv);
if (cli_dbxml(h, cvv2, argv, OP_REMOVE, NULL) < 0)
goto done;
@ -438,7 +456,6 @@ struct findpt_arg{
* @param[in] arg Argument, cast to application-specific info
* @retval 1 OK and return (abort iteration)
* @retval 0 OK and continue
* @retval -1 Error: break and return
*/
static int
cli_auto_findpt(cg_obj *co,
@ -456,9 +473,12 @@ cli_auto_findpt(cg_obj *co,
}
/*! Enter edit mode
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] cvv Vector of cli string and instantiated variables
* @param[in] argv Vector of args to function in command.
* @retval 0 OK
* @retval -1 Error
* Format of argv:
* <api_path_fmt> Generated API PATH FORMAT (print-like for variables)
* <vars>* List of static variables that can be used as values for api_path_fmt
@ -471,7 +491,7 @@ cli_auto_findpt(cg_obj *co,
* api_path: /a/b=42,99/c
* @see cli_auto_edit
*/
int
int
cli_auto_sub_enter(clicon_handle h,
cvec *cvv,
cvec *argv)
@ -486,7 +506,7 @@ cli_auto_sub_enter(clicon_handle h,
cg_var *cv = NULL;
pt_head *ph;
struct findpt_arg fa = {0,};
if (cvec_len(argv) < 2){
clicon_err(OE_PLUGIN, EINVAL, "Usage: %s(<tree> <api_path_fmt> (,vars)*)", __FUNCTION__);
goto done;
@ -506,7 +526,7 @@ cli_auto_sub_enter(clicon_handle h,
* argv, but this can be done differently
*/
/* Create a cvv with variables to add to api-path */
if ((cvv1 = cvec_new(0)) == NULL){
if ((cvv1 = cvec_new(0)) == NULL){
clicon_err(OE_UNIX, errno, "cvec_new");
goto done;
}

View file

@ -106,8 +106,8 @@ autocli_listkw_int2str(int listkw)
* @param[in] h Clixon handle
* @param[in] modname Name of YANG module, or NULL for ANY module (eg default)
* @param[out] enablep Include this module in autocli
* @retval -1 Error
* @retval 0 OK, and enablep set
* @retval -1 Error
*/
int
autocli_module(clicon_handle h,
@ -171,7 +171,7 @@ autocli_module(clicon_handle h,
}
ok:
*enablep = enable;
retval = 0;
retval = 0;
done:
return retval;
}
@ -190,7 +190,7 @@ autocli_compress_extension(yang_stmt *ys,
char *ns = NULL;
int exist = 0;
int ret;
if (nodeid_split(body, &prefix, &id) < 0)
goto done;
if (prefix != NULL){
@ -228,9 +228,8 @@ autocli_compress_extension(yang_stmt *ys,
*
* @param[in] h Clixon handle
* @param[out] compress
* @retval -1 Error
* @retval 0 OK, and compress set
* @retval -1 Error
* Canonical examples:
The config and state containers are "compressed" out of the schema.
+ op=COMPRESS
@ -261,7 +260,7 @@ autocli_compress(clicon_handle h,
char *keywstr;
int match = 0;
char *body;
if (compress == NULL){
clicon_err(OE_YANG, EINVAL, "Argument is NULL");
goto done;
@ -346,8 +345,8 @@ autocli_compress(clicon_handle h,
* Currently only returns list-keyword-default, could be extended to rules
* @param[in] h Clixon handle
* @param[out] completion Completion enabled
* @retval -1 Error
* @retval 0 OK
* @retval -1 Error
*/
int
autocli_completion(clicon_handle h,
@ -359,7 +358,7 @@ autocli_completion(clicon_handle h,
char *reason = NULL;
int ret;
cxobj *xautocli;
if (completion == NULL){
clicon_err(OE_YANG, EINVAL, "Argument is NULL");
goto done;
@ -377,7 +376,7 @@ autocli_completion(clicon_handle h,
goto done;
}
*completion = val;
retval = 0;
retval = 0;
done:
if (reason)
free(reason);
@ -389,8 +388,8 @@ autocli_completion(clicon_handle h,
* When false replaces uses with grouping, when true use tree reference
* @param[in] h Clixon handle
* @param[out] treeref grouping using treerefs enabled
* @retval -1 Error
* @retval 0 OK
* @retval -1 Error
*/
int
autocli_grouping_treeref(clicon_handle h,
@ -402,7 +401,7 @@ autocli_grouping_treeref(clicon_handle h,
char *reason = NULL;
int ret;
cxobj *xautocli;
if (treeref == NULL){
clicon_err(OE_YANG, EINVAL, "Argument is NULL");
goto done;
@ -420,7 +419,7 @@ autocli_grouping_treeref(clicon_handle h,
goto done;
}
*treeref = val;
retval = 0;
retval = 0;
done:
if (reason)
free(reason);
@ -432,8 +431,8 @@ autocli_grouping_treeref(clicon_handle h,
* Currently only returns list-keyword-default, could be extended to rules
* @param[in] h Clixon handle
* @param[out] listkw List keyword setting
* @retval -1 Error
* @retval 0 OK
* @retval -1 Error
*/
int
autocli_list_keyword(clicon_handle h,
@ -442,7 +441,7 @@ autocli_list_keyword(clicon_handle h,
int retval = -1;
char *str;
cxobj *xautocli = NULL;
if (listkw == NULL){
clicon_err(OE_YANG, EINVAL, "Argument is NULL");
goto done;
@ -456,7 +455,7 @@ autocli_list_keyword(clicon_handle h,
goto done;
}
*listkw = autocli_listkw_str2int(str);
retval = 0;
retval = 0;
done:
return retval;
}
@ -465,8 +464,8 @@ autocli_list_keyword(clicon_handle h,
*
* @param[in] h Clixon handle
* @param[out] treeref_state If true, generate CLI from state
* @retval -1 Error
* @retval 0 OK
* @retval -1 Error
*/
int
autocli_treeref_state(clicon_handle h,
@ -478,7 +477,7 @@ autocli_treeref_state(clicon_handle h,
char *reason = NULL;
int ret;
cxobj *xautocli;
if (treeref_state == NULL){
clicon_err(OE_YANG, EINVAL, "Argument is NULL");
goto done;
@ -496,7 +495,7 @@ autocli_treeref_state(clicon_handle h,
goto done;
}
*treeref_state = val;
retval = 0;
retval = 0;
done:
if (reason)
free(reason);
@ -508,8 +507,8 @@ autocli_treeref_state(clicon_handle h,
* @param[in] h Clixon handle
* @param[in] keyw YANG keyword
* @param[out] flag If 0 keyw is not a part of default edit-mode, if 1 it is.
* @retval -1 Error
* @retval 0 OK, see result in keyw
* @retval -1 Error
* @note keyw is a sub/superset of RFC 6020, see clixon-autocli.yang on which are defined
*/
int
@ -524,7 +523,7 @@ autocli_edit_mode(clicon_handle h,
int nvec;
char *v;
int i;
if (flag == NULL){
clicon_err(OE_YANG, EINVAL, "Argument is NULL");
goto done;
@ -547,7 +546,7 @@ autocli_edit_mode(clicon_handle h,
break;
}
}
retval = 0;
retval = 0;
done:
if (vec)
free(vec);

File diff suppressed because it is too large Load diff

View file

@ -122,8 +122,8 @@ 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,
yang_stmt *ys,
cli_expand_var_generate(clicon_handle h,
yang_stmt *ys,
const char *cvtypestr,
int options,
uint8_t fraction_digits,
@ -135,12 +135,12 @@ cli_expand_var_generate(clicon_handle h,
int extvalue = 0;
yang_stmt *yspec;
cg_var *cv = NULL;
if ((yspec = ys_spec(ys)) != NULL)
cv = yang_cv_get(yspec);
if (yang_extension_value(ys, "hide", CLIXON_AUTOCLI_NS, &extvalue, NULL) < 0)
goto done;
if (extvalue || yang_find(ys, Y_STATUS, "deprecated") != NULL)
if (extvalue || yang_find(ys, Y_STATUS, "deprecated") != NULL)
goto hide;
if (yang2api_path_fmt(ys, 1, &api_path_fmt) < 0)
goto done;
@ -167,15 +167,18 @@ cli_expand_var_generate(clicon_handle h,
}
/*! Create callback with api_path format string as argument
*
* @param[in] h Clixon handle
* @param[in] ys yang_stmt of the node at hand
* @param[out] cb The string where the result format string is inserted.
* @retval 0 OK
* @retval -1 Error
* @see cli_dbxml This is where the xmlkeyfmt string is used
* @see pt_callback_reference in CLIgen where the actual callback overwrites the template
*/
static int
cli_callback_generate(clicon_handle h,
yang_stmt *ys,
cli_callback_generate(clicon_handle h,
yang_stmt *ys,
cbuf *cb)
{
int retval = -1;
@ -200,6 +203,7 @@ cli_callback_generate(clicon_handle h,
}
/*! Print cligen help string as ("<helpstring>")
*
* @param[in] cb CLIgen buf holding generated CLIspec
* @param[in] helptext Help text
*/
@ -243,10 +247,13 @@ yang2cli_print_alias(cbuf *cb,
}
/*! Generate identityref statements for CLI variables
*
* @param[in] ys Yang statement
* @param[in] ytype Resolved yang type.
* @param[in] helptext CLI help text
* @param[out] cb Buffer where cligen code is written
* @retval 0 OK
* @retval -1 Error
* @see yang2cli_var_sub Its sub-function
*/
static int
@ -267,7 +274,7 @@ yang2cli_var_identityref(yang_stmt *ys,
yang_stmt *ymod;
yang_stmt *yprefix;
yang_stmt *yspec;
if ((ybaseref = yang_find(ytype, Y_BASE, NULL)) == NULL)
goto ok;
if ((ybaseid = yang_find_identity(ytype, yang_argument_get(ybaseref))) == NULL)
@ -316,10 +323,13 @@ yang2cli_var_identityref(yang_stmt *ys,
}
/*! Generate range check statements for CLI variables
*
* @param[in] ys Yang statement
* @param[in] options Flags field of optional values, eg YANG_OPTIONS_RANGE
* @param[in] cvv Cvec with array of range_min/range_max cv:s (if YANG_OPTIONS_RANGE is set in options)
* @param[out] cb Buffer where cligen code is written
* @retval 0 OK
* @retval -1 Error
* @see yang2cli_var_sub which is the main function
* In yang ranges are given as range 1 or range 1 .. 16, encoded in a cvv
* 0 : range_min = x
@ -349,7 +359,7 @@ yang2cli_var_range(yang_stmt *ys,
int i;
cg_var *cv1; /* lower limit */
cg_var *cv2; /* upper limit */
/* Loop through range_min and range_min..range_max */
i = 0;
while (i<cvec_len(cvv)){
@ -376,9 +386,12 @@ yang2cli_var_range(yang_stmt *ys,
}
/*! Generate CLI code for Yang variable pattern statement
*
* @param[in] h Clixon handle
* @param[in] patterns Cvec of regexp patterns
* @param[out] cb Buffer where cligen code is written
* @retval 0 OK
* @retval -1 Error
* @see cv_validate_pattern for netconf validate code
* @note for cligen, need to escape " -> \"
*/
@ -387,14 +400,14 @@ yang2cli_var_pattern(clicon_handle h,
cvec *patterns,
cbuf *cb)
{
int retval = -1;
int retval = -1;
enum regexp_mode mode;
cg_var *cvp;
char *pattern;
int invert;
char *posix = NULL;
int i;
cg_var *cvp;
char *pattern;
int invert;
char *posix = NULL;
int i;
mode = clicon_yang_regexp(h);
cvp = NULL; /* Loop over compiled regexps */
while ((cvp = cvec_each(patterns, cvp)) != NULL){
@ -439,6 +452,7 @@ static int yang2cli_var_union(clicon_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
*
* Check for completion (of already existent values), ranges (eg range[min:max]) and
* patterns, (eg regexp:"[0.9]*").
* @param[in] h Clixon handle
@ -451,11 +465,13 @@ static int yang2cli_var_union(clicon_handle h, yang_stmt *ys, char *origtype,
* @param[in] patterns Cvec of regexp patterns
* @param[in] fraction for decimal64, how many digits after period
* @param[out] cb Buffer where cligen code is written
* @retval 0 OK
* @retval -1 Error
* @see yang_type_resolve for options and other arguments
*/
static int
yang2cli_var_sub(clicon_handle h,
yang_stmt *ys,
yang_stmt *ys,
yang_stmt *ytype, /* resolved type */
char *helptext,
enum cv_type cvtype,
@ -481,7 +497,6 @@ yang2cli_var_sub(clicon_handle h,
}
type = ytype?yang_argument_get(ytype):NULL;
cvtypestr = cv_type2str(cvtype);
if (type && strcmp(type, "identityref") == 0)
cprintf(cb, "(");
cprintf(cb, "<%s:%s", yang_argument_get(ys), cvtypestr);
@ -533,17 +548,20 @@ yang2cli_var_sub(clicon_handle h,
}
/*! Resolve a single Yang union and generate code
*
* Part of generating CLI code for Yang leaf statement to CLIgen variable
* @param[in] h Clixon handle
* @param[in] ys Yang statement (caller of type)
* @param[in] origtype Name of original type in the call
* @param[in] ytsub Yang type invocation, a sub-type of a resolved union type
* @param[in] cb Buffer where cligen code is written
* @param[in] h Clixon handle
* @param[in] ys Yang statement (caller of type)
* @param[in] origtype Name of original type in the call
* @param[in] ytsub Yang type invocation, a sub-type of a resolved union type
* @param[in] cb Buffer where cligen code is written
* @param[in] helptext CLI help text
* @retval 0 OK
* @retval -1 Error
*/
static int
yang2cli_var_union_one(clicon_handle h,
yang_stmt *ys,
yang_stmt *ys,
char *origtype,
yang_stmt *ytsub,
char *helptext,
@ -581,7 +599,7 @@ yang2cli_var_union_one(clicon_handle h,
else {
if (clicon_type2cv(origtype, restype, ys, &cvtype) < 0)
goto done;
if ((retval = yang2cli_var_sub(h, ys, ytype, helptext, cvtype,
if ((retval = yang2cli_var_sub(h, ys, ytype, helptext, cvtype,
options, cvv, patterns, fraction_digits, cb)) < 0)
goto done;
}
@ -593,17 +611,20 @@ yang2cli_var_union_one(clicon_handle h,
}
/*! Loop over all sub-types of a Yang union
*
* Part of generating CLI code for Yang leaf statement to CLIgen variable
* @param[in] h Clixon handle
* @param[in] ys Yang statement (caller)
* @param[in] h Clixon handle
* @param[in] ys Yang statement (caller)
* @param[in] origtype Name of original type in the call
* @param[in] ytype Yang resolved type (a union in this case)
* @param[in] helptext CLI help text
* @param[out] cb Buffer where cligen code is written
* @param[in] ytype Yang resolved type (a union in this case)
* @param[in] helptext CLI help text
* @param[out] cb Buffer where cligen code is written
* @retval 0 OK
* @retval -1 Error
*/
static int
yang2cli_var_union(clicon_handle h,
yang_stmt *ys,
yang_stmt *ys,
char *origtype,
yang_stmt *ytype,
char *helptext,
@ -633,7 +654,7 @@ yang2cli_var_union(clicon_handle h,
static int
yang2cli_var_leafref(clicon_handle h,
yang_stmt *ys,
yang_stmt *ys,
yang_stmt *yrestype,
char *helptext,
enum cv_type cvtype,
@ -669,11 +690,11 @@ yang2cli_var_leafref(clicon_handle h,
if (completionp && regular_value)
cprintf(cb, "(");
if (regular_value)
if (yang2cli_var_sub(h, ys, yrestype, helptext, cvtype,
if (yang2cli_var_sub(h, ys, yrestype, helptext, cvtype,
options, cvv, patterns, fraction_digits, cb) < 0)
goto done;
if (completionp){
if ((ret = cli_expand_var_generate(h, ys, cvtypestr,
if ((ret = cli_expand_var_generate(h, ys, cvtypestr,
options, fraction_digits, regular_value,
cb)) < 0)
goto done;
@ -688,11 +709,14 @@ yang2cli_var_leafref(clicon_handle h,
}
/*! Generate CLI code for Yang leaf statement to CLIgen variable
*
* @param[in] h Clixon handle
* @param[in] ys Yang statement of original leaf
* @param[in] yreferred Yang statement of referred node for type (leafref)
* @param[in] helptext CLI help text
* @param[out] cb Buffer where cligen code is written
* @retval 0 OK
* @retval -1 Error
*
* Make a type lookup and complete a cligen variable expression such as <a:string>.
* One complication is yang union, that needs a recursion since it consists of
@ -707,7 +731,7 @@ yang2cli_var_leafref(clicon_handle h,
static int
yang2cli_var(clicon_handle h,
yang_stmt *ys,
yang_stmt *yreferred,
yang_stmt *yreferred,
char *helptext,
cbuf *cb)
{
@ -723,12 +747,12 @@ yang2cli_var(clicon_handle h,
int options = 0;
int completionp;
int ret;
if ((patterns = cvec_new(0)) == NULL){
clicon_err(OE_UNIX, errno, "cvec_new");
goto done;
}
if (yang_type_get(yreferred, &origtype, &yrestype,
if (yang_type_get(yreferred, &origtype, &yrestype,
&options, &cvv, patterns, NULL, &fraction_digits) < 0)
goto done;
restype = yang_argument_get(yrestype);
@ -739,7 +763,7 @@ yang2cli_var(clicon_handle h,
cvtypestr = cv_type2str(cvtype);
/* Note restype can be NULL here for example with unresolved hardcoded uuid */
if (strcmp(restype, "union") == 0){
if (strcmp(restype, "union") == 0){
/* Union: loop over resolved type's sub-types (can also be recursive unions) */
cprintf(cb, "(");
if (yang2cli_var_union(h, ys, origtype, yrestype, helptext, cb) < 0)
@ -747,7 +771,7 @@ yang2cli_var(clicon_handle h,
if (autocli_completion(h, &completionp) < 0)
goto done;
if (completionp){
if ((ret = cli_expand_var_generate(h, ys, cvtypestr,
if ((ret = cli_expand_var_generate(h, ys, cvtypestr,
options, fraction_digits, 1, cb)) < 0)
goto done;
if (ret == 1)
@ -770,15 +794,15 @@ yang2cli_var(clicon_handle h,
}
if (yang_path_arg(yreferred, path_arg, &yref) < 0)
goto done;
if (yref == NULL){
if (yref == NULL){
/* Give up: use yreferred
*/
if (yang2cli_var_leafref(h, ys, yrestype, helptext, cvtype, options,
if (yang2cli_var_leafref(h, ys, yrestype, helptext, cvtype, options,
cvv, patterns, fraction_digits, cb) < 0)
goto done;
}
else {
if (yreferred == yref){
if (yreferred == yref){
clicon_err(OE_YANG, 0, "Referred YANG node for leafref path %s points to self", path_arg);
goto done;
}
@ -803,26 +827,29 @@ yang2cli_var(clicon_handle h,
}
/*! Generate CLI code for Yang leaf statement
*
* @param[in] h Clixon handle
* @param[in] ys Yang statement
* @param[in] level Indentation level
* @param[in] callback If set, include a "; cli_set()" callback, otherwise not
* @param[in] callback If set, include a "; cli_set()" callback, otherwise not
* @param[in] key_leaf 0: ordinary leaf, 1:prekey, 2: lastkey
* @param[out] cb Buffer where cligen code is written
* @retval 0 OK
* @retval -1 Error
* Some complexity in callback, key_leaf and extralevel logic.
* If extralevel -> add extra { } level
* + if callbacks add: cb();{}
*/
static int
yang2cli_leaf(clicon_handle h,
yang_stmt *ys,
yang2cli_leaf(clicon_handle h,
yang_stmt *ys,
int level,
int callback,
int key_leaf,
cbuf *cb)
{
yang_stmt *yd; /* description */
int retval = -1;
yang_stmt *yd; /* description */
char *helptext = NULL;
char *s;
autocli_listkw_t listkw;
@ -841,7 +868,7 @@ yang2cli_leaf(clicon_handle h,
}
cprintf(cb, "%*s", level*3, "");
/* Called a second time in yang2cli_var, room for optimization */
if (yang_type_get(ys, NULL, &yrestype,
if (yang_type_get(ys, NULL, &yrestype,
NULL, NULL, NULL, NULL, NULL) < 0)
goto done;
if (key_leaf == 0 && strcmp(yang_argument_get(yrestype), "empty") != 0)
@ -905,27 +932,30 @@ yang2cli_leaf(clicon_handle h,
}
/*! Generate CLI code for Yang container statement
*
* @param[in] h Clixon handle
* @param[in] ys Yang statement
* @param[in] level Indentation level
* @param[out] cb Buffer where cligen code is written
* @param[out] cb Buffer where cligen code is written
* @retval 0 OK
* @retval -1 Error
*/
static int
yang2cli_container(clicon_handle h,
yang_stmt *ys,
yang2cli_container(clicon_handle h,
yang_stmt *ys,
int level,
cbuf *cb)
{
int retval = -1;
yang_stmt *yc;
yang_stmt *yd;
int retval = -1;
char *helptext = NULL;
char *s;
int compress = 0;
yang_stmt *ymod = NULL;
int extvalue = 0;
int ret;
if (ys_real_module(ys, &ymod) < 0)
goto done;
/* If non-presence container && HIDE mode && only child is
@ -964,7 +994,7 @@ yang2cli_container(clicon_handle h,
}
}
yc = NULL;
while ((yc = yn_each(ys, yc)) != NULL)
while ((yc = yn_each(ys, yc)) != NULL)
if (yang2cli_stmt(h, yc, level+1, cb) < 0)
goto done;
if (!compress)
@ -977,24 +1007,27 @@ yang2cli_container(clicon_handle h,
}
/*! Generate CLI code for Yang list statement
*
* @param[in] h Clixon handle
* @param[in] ys Yang statement
* @param[in] level Indentation level
* @param[out] cb Buffer where cligen code is written
* @retval 0 OK
* @retval -1 Error
*/
static int
yang2cli_list(clicon_handle h,
yang_stmt *ys,
yang_stmt *ys,
int level,
cbuf *cb)
{
int retval = -1;
yang_stmt *yc;
yang_stmt *yd;
yang_stmt *yleaf;
cg_var *cvi;
char *keyname;
cvec *cvk = NULL; /* vector of index keys */
int retval = -1;
char *helptext = NULL;
char *s;
int last_key = 0;
@ -1023,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\"",
clicon_err(OE_XML, 0, "List statement \"%s\" has no key leaf \"%s\"",
yang_argument_get(ys), keyname);
goto done;
}
@ -1066,7 +1099,7 @@ yang2cli_list(clicon_handle h,
}
cprintf(cb, "%*s}\n", level*3, "");
/* Close with } for each key */
while (keynr--)
while (keynr--)
cprintf(cb, "%*s}\n", level*3, "");
retval = 0;
done:
@ -1081,18 +1114,20 @@ yang2cli_list(clicon_handle h,
* @param[in] ys Yang statement
* @param[in] level Indentation level
* @param[out] cb Buffer where cligen code is written
@example
* @retval 0 OK
* @retval -1 Error
* @code
choice interface-type {
container ethernet { ... }
container fddi { ... }
}
@example.end
@Note Removes 'meta-syntax' from cli syntax. They are not shown when xml is
* @code.end
@note Removes 'meta-syntax' from cli syntax. They are not shown when xml is
translated to cli. and therefore input-syntax != output syntax. Which is bad
*/
static int
yang2cli_choice(clicon_handle h,
yang_stmt *ys,
yang2cli_choice(clicon_handle h,
yang_stmt *ys,
int level,
cbuf *cb)
{
@ -1206,6 +1241,7 @@ yang2cli_uses(clicon_handle h,
}
/*! Generate CLI code for Yang statement
*
* @param[in] h Clixon handle
* @param[in] ys Yang statement
* @param[in] level Indentation level
@ -1214,9 +1250,9 @@ yang2cli_uses(clicon_handle h,
* @retval -1 Error
*/
static int
yang2cli_stmt(clicon_handle h,
yang_stmt *ys,
int level,
yang2cli_stmt(clicon_handle h,
yang_stmt *ys,
int level,
cbuf *cb)
{
int retval = -1;
@ -1230,11 +1266,11 @@ yang2cli_stmt(clicon_handle h,
goto done;
}
if (yang_find(ys, Y_STATUS, "obsolete") != NULL){
clicon_debug(4, "%s obsolete: %s %s, skipped", __FUNCTION__, yang_argument_get(ys), yang_argument_get(ys_module(ys)));
clixon_debug(CLIXON_DBG_DETAIL, "%s obsolete: %s %s, skipped", __FUNCTION__, yang_argument_get(ys), yang_argument_get(ys_module(ys)));
goto ok;
}
if (yang_find(ys, Y_STATUS, "deprecated") != NULL){
clicon_debug(4, "%s deprecated: %s %s", __FUNCTION__, yang_argument_get(ys), yang_argument_get(ys_module(ys)));
clixon_debug(CLIXON_DBG_DETAIL, "%s deprecated: %s %s", __FUNCTION__, yang_argument_get(ys), yang_argument_get(ys_module(ys)));
}
/* Check if autocli skip */
if (yang_extension_value(ys, "skip", CLIXON_AUTOCLI_NS, &extvalue, NULL) < 0)
@ -1252,7 +1288,7 @@ yang2cli_stmt(clicon_handle h,
#ifdef AUTOCLI_GROUPING_TOPLEVEL_SKIP
cornercase = yang_keyword_get(yang_parent_get(ys)) == Y_MODULE || yang_keyword_get(yang_parent_get(ys)) == Y_SUBMODULE;
#endif
if (yang_keyword_get(ys) != Y_USES && yang_flag_get(ys, YANG_FLAG_GROUPING)
if (yang_keyword_get(ys) != Y_USES && yang_flag_get(ys, YANG_FLAG_GROUPING)
&& !cornercase
)
goto ok;
@ -1301,6 +1337,7 @@ yang2cli_stmt(clicon_handle h,
}
/*! Add cv with name to cvec
*
* @param[in] cvv Either existing or NULL
* @param[in] name Name of cv to add
* @retval cvv Either same as in cvv parameter or new
@ -1310,7 +1347,7 @@ cvec_add_name(cvec *cvv,
char *name)
{
cg_var *cv= NULL;
if (cvv == NULL &&
(cvv = cvec_new(0)) == NULL){
clicon_err(OE_UNIX, errno, "cvec_new");
@ -1382,7 +1419,7 @@ yang2cli_post(clicon_handle h,
char *name;
cg_var *cv = NULL;
int j=0;
cv = NULL;
while ((cv = cvec_each(cop->co_cvec, cv)) != NULL){
name = cv_name_get(cv);
@ -1480,7 +1517,7 @@ yang2cli_post(clicon_handle h,
* XXX merge with yang2cli_yspec
*/
static int
yang2cli_grouping(clicon_handle h,
yang2cli_grouping(clicon_handle h,
yang_stmt *ys,
char *treename)
{
@ -1495,7 +1532,7 @@ yang2cli_grouping(clicon_handle h,
cg_obj *co;
int config;
int i;
if ((pt0 = pt_new()) == NULL){
clicon_err(OE_UNIX, errno, "pt_new");
goto done;
@ -1506,11 +1543,11 @@ yang2cli_grouping(clicon_handle h,
}
/* Traverse YANG, loop through all modules and generate CLI, inline of yang2cli_stmt */
if (yang_find(ys, Y_STATUS, "obsolete") != NULL){
clicon_debug(4, "%s obsolete: %s %s, skipped", __FUNCTION__, yang_argument_get(ys), yang_argument_get(ys_module(ys)));
clixon_debug(CLIXON_DBG_DETAIL, "%s obsolete: %s %s, skipped", __FUNCTION__, yang_argument_get(ys), yang_argument_get(ys_module(ys)));
goto empty;
}
if (yang_find(ys, Y_STATUS, "deprecated") != NULL){
clicon_debug(4, "%s deprecated: %s %s", __FUNCTION__, yang_argument_get(ys), yang_argument_get(ys_module(ys)));
clixon_debug(CLIXON_DBG_DETAIL, "%s deprecated: %s %s", __FUNCTION__, yang_argument_get(ys), yang_argument_get(ys_module(ys)));
}
/* Only produce autocli for YANG non-config only if autocli-treeref-state is true */
if (autocli_treeref_state(h, &treeref_state) < 0)
@ -1539,12 +1576,12 @@ yang2cli_grouping(clicon_handle h,
fprintf(stderr, "%s\n", cbuf_get(cb));
goto done;
}
clicon_debug(CLIXON_DBG_DEFAULT, "%s Generated auto-cli for grouping:%s",
clixon_debug(CLIXON_DBG_DEFAULT, "%s Generated auto-cli for grouping:%s",
__FUNCTION__, yang_argument_get(ys));
/* Add prefix: assume new are appended */
for (i=0; i<pt_len_get(pt); i++){
if ((co = pt_vec_i_get(pt, i)) != NULL){
clicon_debug(CLIXON_DBG_DEFAULT, "%s command: %s",
clixon_debug(CLIXON_DBG_DEFAULT, "%s command: %s",
__FUNCTION__, co->co_command);
co_prefix_set(co, prefix);
}
@ -1562,7 +1599,7 @@ yang2cli_grouping(clicon_handle h,
clicon_log(LOG_NOTICE, "%s: Top-level cli-spec %s:\n%s",
__FUNCTION__, treename, cbuf_get(cb));
else
clicon_debug(CLIXON_DBG_DETAIL, "%s: Top-level cli-spec %s:\n%s",
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");
@ -1614,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(clicon_handle h,
yang_stmt *yspec,
char *treename)
{
@ -1629,7 +1666,7 @@ yang2cli_yspec(clicon_handle h,
cg_obj *co;
int i;
int config;
if ((pt0 = pt_new()) == NULL){
clicon_err(OE_UNIX, errno, "pt_new");
goto done;
@ -1669,12 +1706,12 @@ yang2cli_yspec(clicon_handle h,
fprintf(stderr, "%s\n", cbuf_get(cb));
goto done;
}
clicon_debug(CLIXON_DBG_DEFAULT, "%s Generated auto-cli for module:%s",
clixon_debug(CLIXON_DBG_DEFAULT, "%s Generated auto-cli for module:%s",
__FUNCTION__, yang_argument_get(ymod));
/* Add prefix: assume new are appended */
for (i=0; i<pt_len_get(pt); i++){
if ((co = pt_vec_i_get(pt, i)) != NULL){
clicon_debug(CLIXON_DBG_DEFAULT, "%s command: %s",
clixon_debug(CLIXON_DBG_DEFAULT, "%s command: %s",
__FUNCTION__, co->co_command);
co_prefix_set(co, prefix);
}
@ -1693,7 +1730,7 @@ yang2cli_yspec(clicon_handle h,
clicon_log(LOG_NOTICE, "%s: Top-level cli-spec %s:\n%s",
__FUNCTION__, treename, cbuf_get(cb));
else
clicon_debug(CLIXON_DBG_DETAIL, "%s: Top-level cli-spec %s:\n%s",
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");

View file

@ -72,7 +72,8 @@
#define handle(h) (assert(clicon_handle_check(h)==0),(struct cli_handle *)(h))
#define cligen(h) (handle(h)->cl_cligen)
/*! CLI specific handle added to header CLICON handle
/*! 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
@ -115,6 +116,8 @@ cli_handle_init(void)
}
/*! Free clicon handle
*
* @param[in] h Clixon handle
*/
int
cli_handle_exit(clicon_handle h)
@ -130,7 +133,10 @@ cli_handle_exit(clicon_handle h)
* cli-specific handle access functions
*----------------------------------------------------------*/
/*! Return clicon handle */
/*! Return clicon handle
*
* @param[in] h Clixon handle
*/
cligen_handle
cli_cligen(clicon_handle h)
{
@ -156,8 +162,9 @@ cli_susp_hook(clicon_handle h,
cligen_handle ch = cligen(h);
/* This assume first arg of fn can be treated as void* */
return cligen_susp_hook(ch, fn);
return cligen_susp_hook(ch, fn);
}
int
cli_interrupt_hook(clicon_handle h,
cligen_interrupt_cb_t *fn)
@ -165,7 +172,7 @@ cli_interrupt_hook(clicon_handle h,
cligen_handle ch = cligen(h);
/* This assume first arg of fn can be treated as void* */
return cligen_interrupt_hook(ch, fn);
return cligen_interrupt_hook(ch, fn);
}
int

View file

@ -76,8 +76,11 @@
#define CLI_OPTS "+hD:f:E:l:C:F:1a:u:d:m:qp:GLy:c:U:o:"
/*! Check if there is a CLI history file and if so dump the CLI histiry to it
*
* Just log if file does not exist or is not readable
* @param[in] h CLICON handle
* @param[in] h Clixon handle
* @retval 0 OK
* @retval -1 Error
*/
static int
cli_history_load(clicon_handle h)
@ -121,8 +124,11 @@ cli_history_load(clicon_handle h)
}
/*! Start CLI history and load from file
*
* Just log if file does not exist or is not readable
* @param[in] h CLICON handle
* @param[in] h Clixon handle
* @retval 0 OK
* @retval -1 Error
*/
static int
cli_history_save(clicon_handle h)
@ -157,6 +163,7 @@ cli_history_save(clicon_handle h)
}
/*! Clean and close all state of cli process (but dont exit).
*
* Cannot use h after this
* @param[in] h Clixon handle
*/
@ -170,7 +177,7 @@ cli_terminate(clicon_handle h)
if (clixon_exit_get() == 0)
clixon_exit_set(1);
if (clicon_data_get(h, "session-transport", NULL) == 0)
clicon_rpc_close_session(h);
clicon_rpc_close_session(h);
if ((yspec = clicon_dbspec_yang(h)) != NULL)
ys_free(yspec);
if ((yspec = clicon_config_yang(h)) != NULL)
@ -195,11 +202,11 @@ cli_terminate(clicon_handle h)
}
/*! Unlink pidfile and quit
*/
*/
static void
cli_sig_term(int arg)
{
clicon_log(LOG_NOTICE, "%s: %u Terminated (killed by sig %d)",
clicon_log(LOG_NOTICE, "%s: %u Terminated (killed by sig %d)",
__PROGRAM__, getpid(), arg);
exit(1);
}
@ -226,7 +233,8 @@ cli_signal_init (clicon_handle h)
}
/*! Interactive CLI command loop
* @param[in] h CLICON handle
*
* @param[in] h Clixon handle
* @retval 0
* @retval -1
* @see cligen_loop
@ -269,6 +277,7 @@ cli_interactive(clicon_handle h)
}
/*! Create pre-5.5 tree-refs for backward compatibility
*
* should probably be moved to clispec default
*/
static int
@ -382,8 +391,8 @@ autocli_start(clicon_handle h)
int retval = -1;
yang_stmt *yspec;
int enable = 0;
clicon_debug(1, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
/* There is no single "enable-autocli" flag,
* but set
* <module-default>false</module-default>
@ -394,7 +403,7 @@ autocli_start(clicon_handle h)
if (autocli_module(h, NULL, &enable) < 0)
goto done;
if (!enable){
clicon_debug(1, "%s Autocli not enabled (clixon-autocli)", __FUNCTION__);
clixon_debug(CLIXON_DBG_DEFAULT, "%s Autocli not enabled (clixon-autocli)", __FUNCTION__);
goto ok;
}
/* Init yang2cli */
@ -404,7 +413,7 @@ autocli_start(clicon_handle h)
/* The actual generating call from yang to clispec for the complete yang spec, @basemodel */
if (yang2cli_yspec(h, yspec, AUTOCLI_TREENAME) < 0)
goto done;
/* XXX Create pre-5.5 tree-refs for backward compatibility */
/* XXX Create pre-5.5 tree-refs for backward compatibility */
if (autocli_trees_default(h) < 0)
goto done;
ok:
@ -469,7 +478,7 @@ usage(clicon_handle h,
fprintf(stderr, "usage:%s [options] [commands] [-- extra-options]\n"
"where commands is a CLI command\n"
"and extra-options are app-dependent and passed to the plugin init function\n"
"and extra-options are app-dependent and passed to the plugin init function\n"
"where options are\n"
"\t-h \t\tHelp\n"
"\t-D <level> \tDebug level\n"
@ -525,7 +534,7 @@ main(int argc,
int nr;
int config_dump;
enum format_enum config_dump_format = FORMAT_XML;
/* Defaults */
once = 0;
config_dump = 0;
@ -533,7 +542,7 @@ main(int argc,
/* In the startup, logs to stderr & debug flag set later */
clicon_log_init(__PROGRAM__, LOG_INFO, logdst);
/* Initiate CLICON handle. CLIgen is also initialized */
/* Initiate Clixon handle. CLIgen is also initialized */
if ((h = cli_handle_init()) == NULL)
goto done;
@ -549,7 +558,7 @@ main(int argc,
cligen_comment_set(cli_cligen(h), '#'); /* Default to handle #! clicon_cli scripts */
cligen_lexicalorder_set(cli_cligen(h), 1);
/*
* First-step command-line options for help, debug, config-file and log,
*/
@ -588,11 +597,11 @@ main(int argc,
goto done;
break;
}
/*
/*
* Logs, error and debug to stderr or syslog, set debug level
*/
clicon_log_init(__PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst);
clicon_debug_init(dbg, NULL);
clixon_debug_init(dbg, NULL);
yang_init(h);
/* Find, read and parse configfile */
@ -601,7 +610,7 @@ main(int argc,
usage(h, argv[0]);
goto done;
}
/* Now rest of options */
/* Now rest of options */
opterr = 0;
optind = 1;
while ((c = getopt(argc, argv, CLI_OPTS)) != -1){
@ -698,7 +707,7 @@ main(int argc,
/* Defer: Wait to the last minute to print help message */
if (help)
usage(h, argv[0]);
/* Split remaining argv/argc into <cmd> and <extra-options> */
if (options_split(h, argv0, argc, argv, &restarg) < 0)
goto done;
@ -713,7 +722,7 @@ main(int argc,
nr = clicon_option_int(h, "CLICON_CLI_LINES_DEFAULT");
cligen_terminal_rows_set(cli_cligen(h), nr);
}
if (clicon_yang_regexp(h) == REGEXP_LIBXML2){
#ifdef HAVE_LIBXML2
/* Enable XSD libxml2 regex engine */
@ -732,7 +741,7 @@ main(int argc,
if ((nr = clicon_option_int(h, "CLICON_LOG_STRING_LIMIT")) != 0)
clicon_log_string_limit_set(nr);
/* Setup signal handlers */
if (cli_signal_init(h) < 0)
goto done;
@ -757,7 +766,7 @@ main(int argc,
goto done;
}
#endif
/* Add (hardcoded) netconf features in case ietf-netconf loaded here
* Otherwise it is loaded in netconf_module_load below
*/
@ -772,7 +781,7 @@ main(int argc,
if ((yspec = yspec_new()) == NULL)
goto done;
clicon_dbspec_yang_set(h, yspec);
/* Load Yang modules
* 1. Load a yang module as a specific absolute filename */
if ((str = clicon_yang_main_file(h)) != NULL){
@ -802,7 +811,6 @@ main(int argc,
/* Add netconf yang spec, used as internal protocol */
if (netconf_module_load(h) < 0)
goto done;
/* Here all modules are loaded
* Compute and set canonical namespace context
*/
@ -868,7 +876,7 @@ main(int argc,
clicon_option_dump(h, 1);
cligen_line_scrolling_set(cli_cligen(h), clicon_option_int(h,"CLICON_CLI_LINESCROLLING"));
/*! Start CLI history and load from file */
/* Start CLI history and load from file */
if (cli_history_load(h) < 0)
goto done;
/* Experimental utf8 mode */
@ -893,7 +901,7 @@ main(int argc,
if (evalresult < 0)
goto done;
}
/* Go into event-loop unless -1 command-line */
if (!once){
retval = cli_interactive(h);

View file

@ -92,7 +92,7 @@ pipe_arg_fn(clicon_handle h,
struct stat fstat;
char **argv = NULL;
int i;
if (cmd == NULL || strlen(cmd) == 0){
clicon_err(OE_PLUGIN, EINVAL, "cmd '%s' NULL or empty", cmd);
goto done;
@ -123,7 +123,7 @@ pipe_arg_fn(clicon_handle h,
/* Grep pipe output function
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] cvv Vector of cli string and instantiated variables
* @param[in] argv String vector of options. Format: <option> <value>
* @note Any vertical bar (|] in the patterns field is quoted for OR function
@ -182,9 +182,11 @@ pipe_grep_fn(clicon_handle h,
/*! wc pipe output function
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] cvv Vector of cli string and instantiated variables
* @param[in] argv String vector of options. Format: <option> <value>
* @retval 0 OK
* @retval -1 Error
*/
int
pipe_wc_fn(clicon_handle h,
@ -195,7 +197,7 @@ pipe_wc_fn(clicon_handle h,
cg_var *cv;
char *str;
char *option = NULL;
if (cvec_len(argv) != 1){
clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: <NUM>", cvec_len(argv));
goto done;
@ -211,9 +213,11 @@ pipe_wc_fn(clicon_handle h,
/*! wc pipe output function
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] cvv Vector of cli string and instantiated variables
* @param[in] argv String vector of options. Format: <option> <value>
* @retval 0 OK
* @retval -1 Error
*/
int
pipe_tail_fn(clicon_handle h,
@ -252,12 +256,14 @@ pipe_tail_fn(clicon_handle h,
/*! Output pipe translate from xml to other format: json,text,
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] cvv Vector of cli string and instantiated variables
* @param[in] argv String vector of show options, format:
* <format> "text"|"xml"|"json"|"cli"|"netconf" (see format_enum), default: xml
* <pretty> true|false: pretty-print or not
* <prepend> CLI prefix: prepend before cli syntax output
* @retval 0 OK
* @retval -1 Error
* @see cli_show_auto_devs
*/
int
@ -350,7 +356,7 @@ output_fn(cligen_handle handle,
cvec *argv)
{
cg_var *cv;
cv = NULL;
while ((cv = cvec_each(argv, cv)) != NULL){
cligen_output(stdout, "%s\n", cv_string_get(cv));

View file

@ -81,8 +81,10 @@
/*! Generate CLIgen parse tree for syntax mode
*
* @param[in] h Clicon handle
* @param[in] m Syntax mode struct
* @param[in] h Clixon handle
* @param[in] m Syntax mode struct
* @retval 0 OK
* @retval -1 Error
*/
static int
gen_parse_tree(clicon_handle h,
@ -92,7 +94,7 @@ gen_parse_tree(clicon_handle h,
{
int retval = -1;
pt_head *ph;
if ((ph = cligen_ph_add(cli_cligen(h), name)) == NULL)
goto done;
if (cligen_ph_parsetree_set(ph, pt) < 0)
@ -123,12 +125,12 @@ gen_parse_tree(clicon_handle h,
* @note the returned function is not type-checked which may result in segv at runtime
*/
void *
clixon_str2fn(char *name,
void *handle,
clixon_str2fn(char *name,
void *handle,
char **error)
{
void *fn = NULL;
/* Reset error */
*error = NULL;
/* Special check for auto-cli. If the virtual callback is used, it should be overwritten later
@ -160,16 +162,14 @@ clixon_str2fn(char *name,
* signal an error. However, just checking the function pointer for NULL
* should work in most cases, although it's not 100% correct.
*/
return NULL;
return NULL;
}
/*! Set output pipe flag in all callbacks
*
* @param[in] co CLIgen parse-tree object
* @param[in] arg Argument, cast to application-specific info
* @retval 1 OK and return (abort iteration)
* @retval 0 OK and continue
* @retval -1 Error: break and return
* @retval 0 OK
*/
static int
cli_mark_output_pipes(cg_obj *co,
@ -193,6 +193,8 @@ cli_mark_output_pipes(cg_obj *co,
* @param[in] dir Name of dir, or NULL
* @param[out] ptall Universal CLIgen parse tree: apply to all modes
* @param[out] modes Keep track of all modes
* @retval 0 OK
* @retval -1 Error
* @see clixon_plugins_load Where .so plugin code has been loaded prior to this
*/
static int
@ -202,10 +204,10 @@ clispec_load_file(clicon_handle h,
parse_tree *ptall,
cvec *modes)
{
int retval = -1;
void *handle = NULL; /* Handle to plugin .so module */
char *mode = NULL; /* Name of syntax mode to append new syntax */
parse_tree *pt = NULL;
int retval = -1;
FILE *f;
char filepath[MAXPATHLEN];
cvec *cvv = NULL;
@ -265,8 +267,8 @@ 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",
plgnam, filename, plgnam,
clicon_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;
}
@ -281,27 +283,27 @@ 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)",
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)",
filename, plgnam, plgnam);
goto done;
}
if (cligen_expandv_str2fn(pt, (expandv_str2fn_t*)clixon_str2fn, handle) < 0)
if (cligen_expandv_str2fn(pt, (expandv_str2fn_t*)clixon_str2fn, handle) < 0)
goto done;
/* Variable translation functions */
if (cligen_translate_str2fn(pt, (translate_str2fn_t*)clixon_str2fn, handle) < 0)
if (cligen_translate_str2fn(pt, (translate_str2fn_t*)clixon_str2fn, handle) < 0)
goto done;
/* Make sure we have a syntax mode specified */
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 */
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);
goto done;
}
}
/* Find all modes in CLICON_MODE string: where to append the pt syntax tree */
if ((vec = clicon_strsep(mode, ":", &nvec)) == NULL)
if ((vec = clicon_strsep(mode, ":", &nvec)) == NULL)
goto done;
if (nvec == 1 && strcmp(vec[0], "*") == 0){
@ -369,7 +371,9 @@ done:
*
* CLI .so plugins have been loaded: syntax table in place.
* Now load cligen syntax files and create cligen pt trees.
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @retval 0 OK
* @retval -1 Error
* XXX The parsetree loading needs a rewrite for multiple parse-trees
*/
int
@ -413,7 +417,7 @@ clispec_load(clicon_handle h)
goto done;
/* Load the syntax parse trees into cli_syntax stx structure */
for (i = 0; i < ndp; i++) {
clicon_debug(CLIXON_DBG_DEFAULT, "Loading clispec syntax: '%s/%s'",
clixon_debug(CLIXON_DBG_DEFAULT, "Loading clispec syntax: '%s/%s'",
clispec_dir, dp[i].d_name);
if (clispec_load_file(h, dp[i].d_name, clispec_dir, ptall, modes) < 0)
goto done;
@ -461,7 +465,8 @@ done:
}
/*! Free resources in plugin
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
*/
int
cli_plugin_finish(clicon_handle h)
@ -470,13 +475,14 @@ cli_plugin_finish(clicon_handle h)
}
/*! Help function to print a meaningful error string.
*
* 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
* See eg https://github.com/clicon/clixon/issues/325
* @param[in] f File handler to write error to.
*/
int
int
cli_handler_err(FILE *f)
{
if (clicon_errno){
@ -494,6 +500,7 @@ cli_handler_err(FILE *f)
}
/*! 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
@ -501,19 +508,19 @@ cli_handler_err(FILE *f)
* match is found in another mode, the mode variable is updated to point at
* the new mode string.
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] cmd Command string
* @param[in,out] modenamep Pointer to the mode string pointer
* @param[out] result CLIgen match result, < 0: errors, >=0 number of matches
* @param[out] evalres Evaluation result if result=1
* @retval 0 OK
* @retval -1 Error
* @retval 0 OK
* @retval -1 Error
*/
int
clicon_parse(clicon_handle h,
char *cmd,
char **modenamep,
cligen_result *result,
clicon_parse(clicon_handle h,
char *cmd,
char **modenamep,
cligen_result *result,
int *evalres)
{
int retval = -1;
@ -526,7 +533,7 @@ clicon_parse(clicon_handle h,
char *reason = NULL;
cligen_handle ch;
pt_head *ph;
ch = cli_cligen(h);
if (clicon_get_logflags()&CLICON_LOG_STDOUT)
f = stdout;
@ -546,10 +553,10 @@ clicon_parse(clicon_handle h,
if (cliread_parse(ch, cmd, pt, &match_obj, &cvv, result, &reason) < 0)
goto done;
/* Debug command and result code */
clicon_debug(1, "%s result:%d command: \"%s\"", __FUNCTION__, *result, cmd);
clixon_debug(CLIXON_DBG_DEFAULT, "%s result:%d command: \"%s\"", __FUNCTION__, *result, cmd);
switch (*result) {
case CG_EOF: /* eof */
case CG_ERROR:
case CG_ERROR:
fprintf(f, "CLI parse error: %s\n", cmd); // In practice never happens
break;
case CG_NOMATCH: /* no match */
@ -561,7 +568,7 @@ clicon_parse(clicon_handle h,
cli_set_syntax_mode(h, modename);
}
cli_output_reset();
if (!cligen_exiting(ch)) {
if (!cligen_exiting(ch)) {
clicon_err_reset();
if ((ret = cligen_eval(ch, match_obj, cvv)) < 0) {
cli_handler_err(stdout);
@ -596,6 +603,7 @@ done:
}
/*! Return a malloced expanded prompt string from printf-like format
*
* @param[in] h Clixon handle
* @param[in] fmt Format string, using %H, %
* @retval prompt Malloced string, free after use
@ -654,7 +662,7 @@ cli_prompt_get(clicon_handle h,
else
cprintf(cb, "/");
break;
case 'w': /* Full Working edit path */
case 'w': /* Full Working edit path */
if (clicon_data_get(h, "cli-edit-mode", &path) == 0 &&
strlen(path))
cprintf(cb, "%s", path);
@ -676,7 +684,7 @@ cli_prompt_get(clicon_handle h,
cprintf(cb, "%c", *s);
}
}
else
else
cprintf(cb, "%c", *s);
s++;
}
@ -693,7 +701,7 @@ cli_prompt_get(clicon_handle h,
/*! Read command from CLIgen's cliread() using current syntax mode.
*
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] ph Parse-tree head
* @param[out] stringp Pointer to command buffer or NULL on EOF
* @retval 1 OK
@ -756,7 +764,8 @@ clicon_cliread(clicon_handle h,
*/
/*! Set syntax mode mode for existing current plugin group.
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @retval 1 OK
* @retval 0 Not found / error
*/
@ -774,13 +783,14 @@ cli_set_syntax_mode(clicon_handle h,
}
/*! Get syntax mode name
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
*/
char *
cli_syntax_mode(clicon_handle h)
{
pt_head *ph;
if ((ph = cligen_pt_head_active_get(cli_cligen(h))) == NULL)
return NULL;
return cligen_ph_name_get(ph);

View file

@ -182,7 +182,7 @@ xpath_append(cbuf *cb0,
free(prefix);
if (id)
free(id);
free(vec);
free(vec);
return retval;
}
@ -201,13 +201,15 @@ xpath_append(cbuf *cb0,
* [<mt-point>] Optional YANG path-arg/xpath from mount-point
* @param[out] commands vector of function pointers to callback functions
* @param[out] helptxt vector of pointers to helptexts
* @retval 0 OK
* @retval -1 Error
* @see cli_expand_var_generate where api_path_fmt + mt-point are generated
*/
int
expand_dbvar(void *h,
char *name,
cvec *cvv,
cvec *argv,
expand_dbvar(void *h,
char *name,
cvec *cvv,
cvec *argv,
cvec *commands,
cvec *helptexts)
{
@ -246,7 +248,7 @@ expand_dbvar(void *h,
char *str;
int grouping_treeref;
cvec *callback_cvv;
if (argv == NULL || (cvec_len(argv) != 2 && cvec_len(argv) != 3)){
clicon_err(OE_PLUGIN, EINVAL, "requires arguments: <db> <apipathfmt> [<mountpt>]");
goto done;
@ -263,7 +265,7 @@ expand_dbvar(void *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);
clicon_err(OE_PLUGIN, 0, "No such db name: %s", dbstr);
goto done;
}
if ((cv = cvec_i(argv, 1)) == NULL){
@ -273,18 +275,18 @@ expand_dbvar(void *h,
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");
clicon_err(OE_PLUGIN, errno, "cbuf_new");
goto done;
}
if (grouping_treeref &&
(callback_cvv = cligen_callback_arguments_get(cli_cligen(h))) != NULL){
/* Concatenate callback arguments to a singel prepend string */
if (cvec_concat_cb(callback_cvv, api_path_fmt_cb) < 0)
goto done;
goto done;
}
cprintf(api_path_fmt_cb, "%s", cv_string_get(cv));
api_path_fmt = cbuf_get(api_path_fmt_cb);
if (cvec_len(argv) > 2){
if (cvec_len(argv) > 2){
cv = cvec_i(argv, 2);
str = cv_string_get(cv);
if (strncmp(str, "mtpoint:", strlen("mtpoint:")) != 0){
@ -379,13 +381,13 @@ expand_dbvar(void *h,
goto done;
}
/* Get configuration based on cbxpath */
if (clicon_rpc_get_config(h, NULL, dbstr, cbuf_get(cbxpath), nsc, NULL, &xt) < 0)
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(xe, "Get configuration", NULL);
goto ok;
goto ok;
}
if (xpath_vec(xt, nsc, "%s", &xvec, &xlen, cbuf_get(cbxpath)) < 0)
if (xpath_vec(xt, nsc, "%s", &xvec, &xlen, cbuf_get(cbxpath)) < 0)
goto done;
/* Loop for inserting into commands cvec.
* Detect duplicates: for ordered-by system assume list is ordered, so you need
@ -446,15 +448,22 @@ expand_dbvar(void *h,
xml_free(xtop);
if (xt)
xml_free(xt);
if (xpath)
if (xpath)
free(xpath);
return retval;
}
/*! CLI callback show yang spec. If arg given matches yang argument string */
/*! CLI callback show yang spec. If arg given matches yang argument string
*
* @param[in] h Clixon handle
* @param[in] cvv Vector of command variables
* @param[in] argv
* @retval 0 OK
* @retval -1 Error
*/
int
show_yang(clicon_handle h,
cvec *cvv,
show_yang(clicon_handle h,
cvec *cvv,
cvec *argv)
{
int retval = -1;
@ -462,7 +471,7 @@ show_yang(clicon_handle h,
char *str = NULL;
yang_stmt *yspec;
yspec = clicon_dbspec_yang(h);
yspec = clicon_dbspec_yang(h);
if (cvec_len(argv) > 0){
if ((str = cv_string_get(cvec_i(argv, 0))) != NULL &&
(yn = yang_find(yspec, 0, str)) != NULL)
@ -495,6 +504,8 @@ show_yang(clicon_handle h,
* @param[in] fromroot If 0, display config from node of XPATH, if 1 display from root
* @param[in] nsc Namespace mapping for xpath
* @param[in] skiptop If set, do not show object itself, only its children
* @retval 0 OK
* @retval -1 Error
*/
int
cli_show_common(clicon_handle h,
@ -511,7 +522,7 @@ cli_show_common(clicon_handle h,
int skiptop
)
{
int retval = -1;
int retval = -1;
cxobj *xt = NULL;
cxobj *xerr;
cxobj **vec = NULL;
@ -542,19 +553,19 @@ cli_show_common(clicon_handle h,
if (purge_tagged_nodes(xt, IETF_NETCONF_WITH_DEFAULTS_ATTR_NAMESPACE, "default", "true",
strcmp(extdefault, "report-all-tagged-strip")
) < 0)
goto done;
goto done;
/* Remove empty containers */
if (xml_defaults_nopresence(xt, 2) < 0)
goto done;
}
if (fromroot)
xpath="/";
if (xpath_vec(xt, nsc, "%s", &vec, &veclen, xpath) < 0)
if (xpath_vec(xt, nsc, "%s", &vec, &veclen, xpath) < 0)
goto done;
if (veclen){
/* Special case LIST */
if (format == FORMAT_JSON){
switch (format){
switch (format){
case FORMAT_JSON:
if (xml2json_vec(stdout, vec, veclen, pretty, cligen_output, skiptop) < 0)
goto done;
@ -619,7 +630,7 @@ done:
* @retval 0 OK
* @retval -1 Error
*/
int
int
cli_show_option_format(cvec *argv,
int argc,
enum format_enum *format)
@ -645,7 +656,7 @@ cli_show_option_format(cvec *argv,
* @retval 0 OK
* @retval -1 Error
*/
int
int
cli_show_option_bool(cvec *argv,
int argc,
int *result
@ -685,7 +696,7 @@ cli_show_option_bool(cvec *argv,
* @retval 0 OK
* @retval -1 Error
*/
int
int
cli_show_option_withdefault(cvec *argv,
int argc,
char **withdefault,
@ -722,7 +733,7 @@ cli_show_option_withdefault(cvec *argv,
/*! Generic show configuration callback
*
* Does not need to be used with the autocli as cli_show_auto does
* @param[in] h CLICON handle
* @param[in] h Clixon handle
* @param[in] cvv Vector of variables from CLIgen command-line
* @param[in] argv String vector of show options, format:
* <dbname> Name of datastore, such as "running"
@ -735,6 +746,8 @@ cli_show_option_withdefault(cvec *argv,
* <default> Retrieval mode: report-all, trim, explicit, report-all-tagged,
* NULL, report-all-tagged-default, report-all-tagged-strip (extended)
* <prepend> CLI prefix: prepend before cli syntax output
* @retval 0 OK
* @retval -1 Error
* @code
* clispec:
* show config, cli_show_config("running","xml");
@ -752,8 +765,8 @@ cli_show_option_withdefault(cvec *argv,
* @see cli_show_auto_mode autocli with edit menu support
*/
int
cli_show_config(clicon_handle h,
cvec *cvv,
cli_show_config(clicon_handle h,
cvec *cvv,
cvec *argv)
{
int retval = -1;
@ -769,7 +782,7 @@ cli_show_config(clicon_handle h,
char *xpath = "/";
char *namespace = NULL;
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));
goto done;
@ -815,29 +828,18 @@ cli_show_config(clicon_handle h,
return retval;
}
/*! Show configuration and state CLIGEN callback function
/*! Show configuration xpath
*
* @param[in] h CLICON handle
* @param[in] h Clixon handle
* @param[in] cvv Vector of variables from CLIgen command-line
* @param[in] argv String vector of show options, format:
* <dbname> "running"|"candidate"|"startup"
* @code
* show config id <n:string>, cli_show_config("running","xml","iface[name='foo']","urn:example:example");
* @endcode
* @see cli_show_config_state For config and state data (not only config)
*/
/*! Show configuration as text given an xpath using canonical namespace
*
* Utility function used by cligen spec file
* @param[in] h CLICON handle
* @param[in] cvv Vector of variables from CLIgen command-line must contain xpath and default namespace (if any)
* @param[in] argv A string: <dbname>
* @note Different from cli_show_conf: values taken cvv "xpath" and "ns" instead of argv
* @retval 0 OK
* @retval -1 Error
*/
int
show_conf_xpath(clicon_handle h,
cvec *cvv,
show_conf_xpath(clicon_handle h,
cvec *cvv,
cvec *argv)
{
int retval = -1;
@ -847,7 +849,7 @@ show_conf_xpath(clicon_handle h,
cvec *nsc = NULL;
yang_stmt *yspec;
int fromroot = 0;
if (cvec_len(argv) != 1){
clicon_err(OE_PLUGIN, EINVAL, "Requires one element to be <dbname>");
goto done;
@ -886,7 +888,7 @@ done:
*/
int
cli_show_version(clicon_handle h,
cvec *vars,
cvec *cvv,
cvec *argv)
{
cligen_output(stdout, "Clixon: %s\n", CLIXON_VERSION_STRING);
@ -914,6 +916,8 @@ cli_show_version(clicon_handle h,
* NULL, report-all-tagged-default, report-all-tagged-strip (extended)
* <prepend> CLI prefix: prepend before cli syntax output
* <fromroot> true|false: Show from root
* @retval 0 OK
* @retval -1 Error
* @code
* clispec:
* show config @datamodelshow, cli_show_auto("candidate", "xml");
@ -931,7 +935,7 @@ cli_show_version(clicon_handle h,
* XXX merge cli_show_auto and cli_show_auto_mode
* @see cli_callback_generate where api_path_fmt + mt-point are generated
*/
int
int
cli_show_auto(clicon_handle h,
cvec *cvv,
cvec *argv)
@ -955,7 +959,7 @@ cli_show_auto(clicon_handle h,
char *str;
char *mtpoint = NULL;
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));
goto done;
@ -996,7 +1000,7 @@ cli_show_auto(clicon_handle h,
clicon_err(OE_FATAL, 0, "No DB_SPEC");
goto done;
}
if (mtpoint){
if (mtpoint){
/* Get and combined api-path01 */
if (mtpoint_paths(yspec0, mtpoint, api_path_fmt, &api_path_fmt01) < 0)
goto done;
@ -1046,6 +1050,8 @@ cli_show_auto(clicon_handle h,
* <default> Retrieval mode: report-all, trim, explicit, report-all-tagged,
* NULL, report-all-tagged-default, report-all-tagged-strip (extended)
* <prepend> CLI prefix: prepend before cli syntax output
* @retval 0 OK
* @retval -1 Error
* @cli_show_auto_ctrl
code
* clispec:
@ -1088,7 +1094,7 @@ cli_show_auto_mode(clicon_handle h,
cvec *nsc0 = NULL;
cg_var *cv;
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));
goto done;
@ -1142,7 +1148,7 @@ cli_show_auto_mode(clicon_handle h,
goto done;
}
if (mtpoint){
cprintf(cbxpath, "%s", mtpoint);
cprintf(cbxpath, "%s", mtpoint);
if (xml_nsctx_yangspec(yspec0, &nsc0) < 0)
goto done;
cv = NULL; /* Append cvv1 to cvv2 */
@ -1170,9 +1176,14 @@ cli_show_auto_mode(clicon_handle h,
/*! Show clixon configuration options as loaded
*
* @param[in] h Clixon handle
* @param[in] cvv Vector of command variables
* @param[in] argv
* @retval 0 OK
* @retval -1 Error
'* @see clicon_option_dump clicon_option_dump1
*/
int
int
cli_show_options(clicon_handle h,
cvec *cvv,
cvec *argv)
@ -1185,7 +1196,7 @@ cli_show_options(clicon_handle h,
size_t klen;
size_t vlen;
cxobj *x = NULL;
if (clicon_hash_keys(hash, &keys, &klen) < 0)
goto done;
for(i = 0; i < klen; i++) {
@ -1228,9 +1239,12 @@ cli_show_options(clicon_handle h,
}
/*! Show pagination
* @param[in] h Clicon handle
*
* @param[in] h Clixon handle
* @param[in] cvv Vector of cli string and instantiated variables
* @param[in] argv Vector. Format: <xpath> <prefix> <namespace> <format> <limit>
* @retval 0 OK
* @retval -1 Error
* Also, if there is a cligen variable called "xpath" it will override argv xpath arg
*/
int
@ -1239,7 +1253,7 @@ cli_pagination(clicon_handle h,
cvec *argv)
{
int retval = -1;
cbuf *cb = NULL;
cbuf *cb = NULL;
char *xpath = NULL;
char *prefix = NULL;
char *namespace = NULL;
@ -1256,7 +1270,7 @@ cli_pagination(clicon_handle h,
cxobj **xvec = NULL;
size_t xlen;
int locked = 0;
if (cvec_len(argv) != 5){
clicon_err(OE_PLUGIN, 0, "Expected usage: <xpath> <prefix> <namespace> <format> <limit>");
goto done;
@ -1363,7 +1377,7 @@ cli_pagination(clicon_handle h,
*
* Howto: join strings and pass them down.
* Identify unique/index keywords for correct set syntax.
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in,out] cb Cligen buffer to write to
* @param[in] xn XML Parse-tree (to translate)
* @param[in] prepend Print this text in front of all commands.
@ -1421,7 +1435,7 @@ cli2cbuf(clicon_handle h,
}
/* Create prepend variable string */
if ((cbpre = cbuf_new()) == NULL){
clicon_err(OE_PLUGIN, errno, "cbuf_new");
clicon_err(OE_PLUGIN, errno, "cbuf_new");
goto done;
}
if (prepend)
@ -1466,7 +1480,7 @@ cli2cbuf(clicon_handle h,
/* For lists, print cbpre before its elements */
if (yang_keyword_get(ys) == Y_LIST)
cprintf(cb, "%s\n", cbuf_get(cbpre));
cprintf(cb, "%s\n", cbuf_get(cbpre));
/* Then loop through all other (non-keys) */
xe = NULL;
while ((xe = xml_child_each(xn, xe, -1)) != NULL){
@ -1491,15 +1505,17 @@ cli2cbuf(clicon_handle h,
*
* Howto: join strings and pass them down.
* Identify unique/index keywords for correct set syntax.
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] f Output FILE (eg stdout)
* @param[in] xn XML Parse-tree (to translate)
* @param[in] prepend Print this text in front of all commands.
* @param[in] fn Callback to make print function
* @retval 0 OK
* @retval -1 Error
*/
static int
cli2file(clicon_handle h,
FILE *f,
FILE *f,
cxobj *xn,
char *prepend,
clicon_output_cb *fn)
@ -1548,7 +1564,7 @@ cli2file(clicon_handle h,
}
/* Create prepend variable string */
if ((cbpre = cbuf_new()) == NULL){
clicon_err(OE_PLUGIN, errno, "cbuf_new");
clicon_err(OE_PLUGIN, errno, "cbuf_new");
goto done;
}
if (prepend)
@ -1593,7 +1609,7 @@ cli2file(clicon_handle h,
/* For lists, print cbpre before its elements */
if (yang_keyword_get(ys) == Y_LIST)
(*fn)(f, "%s\n", cbuf_get(cbpre));
(*fn)(f, "%s\n", cbuf_get(cbpre));
/* Then loop through all other (non-keys) */
xe = NULL;
while ((xe = xml_child_each(xn, xe, -1)) != NULL){
@ -1618,7 +1634,7 @@ cli2file(clicon_handle h,
*
* Howto: join strings and pass them down.
* Identify unique/index keywords for correct set syntax.
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] f Output FILE (eg stdout)
* @param[in] xn XML Parse-tree (to translate)
* @param[in] prepend Print this text in front of all commands.
@ -1630,7 +1646,7 @@ cli2file(clicon_handle h,
*/
int
clixon_cli2file(clicon_handle h,
FILE *f,
FILE *f,
cxobj *xn,
char *prepend,
clicon_output_cb *fn,
@ -1660,7 +1676,7 @@ clixon_cli2file(clicon_handle h,
*
* Howto: join strings and pass them down.
* Identify unique/index keywords for correct set syntax.
* @param[in] h Clicon handle
* @param[in] h Clixon handle
* @param[in] f Output FILE (eg stdout)
* @param[in] xn XML Parse-tree (to translate)
* @param[in] prepend Print this text in front of all commands.
@ -1698,8 +1714,8 @@ clixon_cli2cbuf(clicon_handle h,
/*! CLI callback show statistics
*/
int
cli_show_statistics(clicon_handle h,
cvec *cvv,
cli_show_statistics(clicon_handle h,
cvec *cvv,
cvec *argv)
{
int retval = -1;
@ -1712,7 +1728,7 @@ cli_show_statistics(clicon_handle h,
parse_tree *pt;
uint64_t nr = 0;
size_t sz = 0;
if (argv != NULL && cvec_len(argv) != 1){
clicon_err(OE_PLUGIN, EINVAL, "Expected arguments: [modules]");
goto done;
@ -1734,7 +1750,7 @@ cli_show_statistics(clicon_handle h,
nr = 0; sz = 0;
pt_stats(pt, &nr, &sz);
cligen_output(stdout, "%s: nr=%" PRIu64 " size:%zu\n",
cligen_ph_name_get(ph), nr, sz);
cligen_ph_name_get(ph), nr, sz);
}
/* Backend */
cprintf(cb, "<rpc xmlns=\"%s\"", NETCONF_BASE_NAMESPACE);

View file

@ -50,6 +50,7 @@ extern "C" {
*/
/*! Called when plugin loaded. Only mandadory callback. All others optional
*
* @see plginit_t
*/
int plugin_init(clicon_handle h);

View file

@ -43,10 +43,11 @@
* Types
*/
/*! Autocli list keyword type, see clixon-autocli.yang list-keyword-type
*
* Assume a YANG LIST:
* list a {
* key x;
* leaf x;
* list a {
* key x;
* leaf x;
* leaf y;
* }
* Maybe this type should be in cli_autocli.h
@ -77,7 +78,7 @@ cligen_handle cli_cligen(clicon_handle h);
/* cli_common.c */
int cli_notification_register(clicon_handle h, char *stream, enum format_enum format,
char *filter, int status,
char *filter, int status,
int (*fn)(int, void*), void *arg);
int mtpoint_paths(yang_stmt *yspec0, char *mtpoint, char *api_path_fmt1, char **api_path_fmt01);
@ -115,7 +116,7 @@ int cvec_concat_cb(cvec *cvv, cbuf *cb);
int cli_process_control(clicon_handle h, cvec *vars, cvec *argv);
/* In cli_show.c */
int expand_dbvar(void *h, char *name, cvec *cvv, cvec *argv,
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);