yumapro  20.10-10
YumaPro SDK

Bootstrap CLI based on name/value pairs Used to setup the basics as soon as possible. More...

Collaboration diagram for CLI Parser:

Data Structures

struct  cli_rawparm_t
 used for bootstrap CLI parms only, no validation More...
 

Typedefs

typedef val_value_t *(* cli_xml_buffer_fn_t) (const xmlChar *xmlbuff, obj_template_t *targetobj, status_t *res)
 Read an XML buffer and convert it into a real data structure. More...
 
typedef status_t(* cli_var_replace_fn_t) (runstack_context_t *rcxt, val_value_t *val)
 Check a val_value_t for variable usage to be replaced by the variable value. More...
 

Enumerations

Functions

cli_rawparm_tcli_new_rawparm (const xmlChar *name, boolean xsdlist)
 bootstrap CLI support Malloc and init a raw parm entry More...
 
cli_rawparm_tcli_new_empty_rawparm (const xmlChar *name)
 Malloc and init a raw parm entry that has no value (NCX_BT_EMPTY) More...
 
void cli_free_rawparm (cli_rawparm_t *parm)
 Clean and free a raw parm entry. More...
 
void cli_clean_rawparmQ (dlq_hdr_t *parmQ)
 Clean and free a Q of raw parm entries. More...
 
cli_rawparm_tcli_find_rawparm (const xmlChar *name, dlq_hdr_t *parmQ)
 Find the specified raw parm entry. More...
 
status_t cli_parse_raw (int argc, char *argv[], dlq_hdr_t *rawparmQ)
 Generate N sets of variable/value pairs for the specified boot-strap CLI parameters. More...
 
val_value_tcli_parse (runstack_context_t *rcxt, int argc, char *argv[], obj_template_t *obj, boolean valonly, boolean script, boolean autocomp, cli_mode_t mode, status_t *status)
 schema based CLI support More...
 
val_value_tcli_parse_inline (runstack_context_t *rcxt, int argc, char *argv[], obj_template_t *obj, boolean valonly, boolean script, boolean autocomp, cli_mode_t mode, status_t *status, cli_xml_buffer_fn_t cbfn, cli_var_replace_fn_t cbfn2)
 schema based CLI support More...
 
status_t cli_parse_parm (runstack_context_t *rcxt, val_value_t *val, obj_template_t *obj, const xmlChar *strval, boolean script)
 Create a val_value_t struct for the specified parm value, and insert it into the parent container value. More...
 
status_t cli_parse_parm_ret (runstack_context_t *rcxt, val_value_t *val, obj_template_t *obj, const xmlChar *strval, boolean script, val_value_t **retval)
 Create a val_value_t struct for the specified parm value, and insert it into the parent container value. More...
 
status_t cli_parse_parm_binary (runstack_context_t *rcxt, val_value_t *val, obj_template_t *obj, const xmlChar *strval, boolean script, val_value_t **retval)
 Create a val_value_t struct for the specified parm value, and insert it into the value set Extended. More...
 
status_t cli_parse_parm_ex (runstack_context_t *rcxt, val_value_t *val, obj_template_t *obj, const xmlChar *strval, boolean script, ncx_bad_data_t bad_data)
 Create a val_value_t struct for the specified parm value, and insert it into the parent container value Allow different bad data error handling vioa parameter. More...
 
status_t conf_parse_val_from_filespec (const xmlChar *filespec, val_value_t *val, boolean keepvals, boolean fileerr)
 Parse a file as an NCX text config file against a specific parmset definition. More...
 
status_t conf_parse_val_from_filespec_ex (const xmlChar *filespec, const xmlChar *banner_object, val_value_t *val, boolean keepvals, boolean fileerr, boolean *fileopened)
 Parse a file as an NCX text config file against a specific parmset definition. More...
 

Detailed Description

Bootstrap CLI based on name/value pairs Used to setup the basics as soon as possible.

Configuration File using YANG container object for the schema.

YANG CLI available after all YANG modules loaded Uses an obj_template_t to specify the schema for the value set

Typedef Documentation

typedef status_t(* cli_var_replace_fn_t) (runstack_context_t *rcxt, val_value_t *val)

Check a val_value_t for variable usage to be replaced by the variable value.

All descendant nodes of 'val' are checked

Parameters
rcxtruntime context to find variables
valvalue node to check for variable replacements Expected to be complex type (container or list)
Return values
valdescendants may have values replaced
Returns
status
typedef val_value_t*(* cli_xml_buffer_fn_t) (const xmlChar *xmlbuff, obj_template_t *targetobj, status_t *res)

Read an XML buffer and convert it into a real data structure.

Parameters
xmlbuffXML buffer to load
targetobjtemplate to use to validate XML and encode as this object !! must not be ncx:root!!
== NULL to use OBJ_TYP_ANYXML as the target object template
resaddress of return status
Return values
*resreturn status
Returns
malloced val_value_t struct filled in with the contents

Enumeration Type Documentation

enum cli_mode_t

CLI parsing modes.

Enumerator
CLI_MODE_NONE 

mode not set

CLI_MODE_PROGRAM 

real argc, argv

CLI_MODE_COMMAND 

called from yangcli command parser

Function Documentation

void cli_clean_rawparmQ ( dlq_hdr_t *  parmQ)

Clean and free a Q of raw parm entries.

Parameters
parmQQ of raw parm entry to free

Here is the call graph for this function:

cli_rawparm_t* cli_find_rawparm ( const xmlChar *  name,
dlq_hdr_t *  parmQ 
)

Find the specified raw parm entry.

Parameters
nameobject name to really use
parmQQ of cli_rawparm_t
Returns
raw parm entry if found, NULL if not
void cli_free_rawparm ( cli_rawparm_t parm)

Clean and free a raw parm entry.

Parameters
parmraw parm entry to free

Here is the call graph for this function:

Here is the caller graph for this function:

cli_rawparm_t* cli_new_empty_rawparm ( const xmlChar *  name)

Malloc and init a raw parm entry that has no value (NCX_BT_EMPTY)

Parameters
namename of parm (static const string)
Returns
new parm entry, NULL if malloc failed
cli_rawparm_t* cli_new_rawparm ( const xmlChar *  name,
boolean  xsdlist 
)

bootstrap CLI support Malloc and init a raw parm entry

Parameters
namename of parm (static const string)
xsdlistwhether parm list is structured as XSDLIST
Returns
new parm entry, NULL if malloc failed
val_value_t* cli_parse ( runstack_context_t rcxt,
int  argc,
char *  argv[],
obj_template_t obj,
boolean  valonly,
boolean  script,
boolean  autocomp,
cli_mode_t  mode,
status_t status 
)

schema based CLI support

Generate 1 val_value_t struct from a Unix Command Line, which should conform to the specified obj_template_t definition.

For CLI interfaces, only one container object can be specified at this time.

  CLI Syntax Supported
  [prefix] parmname [separator] [value]
     prefix ==  0 to 2 dashes    foo  -foo --foo
     parmname == any valid NCX identifier string
     separator ==  - equals char (=)
  • whitespace (sp, ht) value == any NCX number or NCX string == 'enum' data type == not present (only for 'flag' data type) == extended This value: string will converted to appropriate simple type in val_value_t format.
  The format "--foo=bar" must be processed within one argv segment.
  If the separator is a whitespace char, then the next string
  in the argv array must contain the expected value.
  Whitespace can be preserved using single or double quotes
  DESIGN NOTES:
    1) parse the (argc, argv) input against the specified object
    2) add any missing mandatory and condition-met parameters
       to the container.
    3) Add defaults if valonly is false
    4) Validate any 'choice' constructs within the parmset
    5) Validate the proper number of instances (missing or extra)
       (unless valonly is TRUE)
  The 'value' string cannot be split across multiple argv segments.
  Use quotation chars within the CLI shell to pass a string
  containing whitespace to the CLI parser:
    --foo="quoted string if whitespace needed"
    --foo="quoted string if setting a variable \
          as a top-level assignment"
    --foo=unquoted-string-without-whitespace
  The input is parsed against the specified obj_template_t struct.
  A val_value_t tree is built as the input is read.
  Each parameter is syntax checked as is is parsed.
  If possible, the parser will skip to next parmameter in the parmset,
  in order to support 'continue-on-error' type of operations.
  Any agent callback functions that might be registered for
  the specified container (or its sub-nodes) are not called
  by this function.  This must be done after this function
  has been called, and returns NO_ERR.
 
@param rcxt runstack context to use
@param argc number of strings passed in 'argv'
@param argv array of command line argument strings
@param obj obj_template_t of the container
       that should be used to validate the input
       against the child nodes of this container
@param valonly TRUE if only the values presented should
          be checked, no defaults, missing parms (Step 1 & 2 only)\n
        FALSE if all the tests and procedures should be done
@param autocomp TRUE if parameter auto-completion should be
            tried if any specified parameters are not matches
            for the specified parmset\n
         FALSE if exact match only is desired
@param mode CLI_MODE_PROGRAM if calling with real (argc, argv)
        parameters; these may need some prep work\n
     CLI_MODE_COMMAND if calling from yangcli or
        some other internal command parser.
        These strings will not be preped at all
@param status pointer to status_t to get the return value
@retval *status the final function return status

Just as the NETCONF parser does, the CLI parser will not add a parameter to the val_value_t if any errors occur related to the initial parsing.

Returns
pointer to the malloced and filled in val_value_t

Here is the call graph for this function:

Here is the caller graph for this function:

val_value_t* cli_parse_inline ( runstack_context_t rcxt,
int  argc,
char *  argv[],
obj_template_t obj,
boolean  valonly,
boolean  script,
boolean  autocomp,
cli_mode_t  mode,
status_t status,
cli_xml_buffer_fn_t  cbfn,
cli_var_replace_fn_t  cbfn2 
)

schema based CLI support

Generate 1 val_value_t struct from a Unix Command Line, which should conform to the specified obj_template_t definition.

For CLI interfaces, only one container object can be specified at this time.

Parameters
rcxtrunstack context to use
argcnumber of strings passed in 'argv'
argvarray of command line argument strings
objobj_template_t of the container that should be used to validate the input against the child nodes of this container
valonlyTRUE if only the values presented should be checked, no defaults, missing parms (Step 1 & 2 only)
FALSE if all the tests and procedures should be done
scriptTRUE if calling from a script; FALSE if interactive
autocompTRUE if parameter auto-completion should be tried if any specified parameters are not matches for the specified parmset
FALSE if exact match only is desired
modeCLI_MODE_PROGRAM if calling with real (argc, argv) parameters; these may need some prep work
CLI_MODE_COMMAND if calling from yangcli or some other internal command parser. These strings will not be preped at all
statuspointer to status_t to get the return value
cbfninline XML data only: callback for XML buffer parsing
cbfn2inline data variable replacement callback function
Return values
*statusthe final function return status Just as the NETCONF parser does, the CLI parser will not add a parameter to the val_value_t if any errors occur related to the initial parsing.
Returns
pointer to the malloced and filled in val_value_t

Here is the call graph for this function:

Here is the caller graph for this function:

status_t cli_parse_parm ( runstack_context_t rcxt,
val_value_t val,
obj_template_t obj,
const xmlChar *  strval,
boolean  script 
)

Create a val_value_t struct for the specified parm value, and insert it into the parent container value.

ONLY CALLED FROM CLI PARSING FUNCTIONS IN ncxcli.c ALLOWS SCRIPT EXTENSIONS TO BE PRESENT

A new val_value_t will be inserted in the val->v.childQ as required to fill in the parm.

Parameters
rcxtrunstack context to use
valparent value struct to adjust
objobj_template_t descriptor for the missing parm
strvalstring representation of the parm value (may be NULL if parm btype is NCX_BT_EMPTY
scriptTRUE if CLI script mode
FALSE if CLI plain mode
Returns
status
status_t cli_parse_parm_binary ( runstack_context_t rcxt,
val_value_t val,
obj_template_t obj,
const xmlChar *  strval,
boolean  script,
val_value_t **  retval 
)

Create a val_value_t struct for the specified parm value, and insert it into the value set Extended.

This function is specially called for the binary leaf/ leaf-list with default value.

If the specified parm is mandatory w/defval defined, then a new val_value_t will be inserted in the val->v.childQ as required to fill in the value set.

Parameters
rcxtrunstack context to use
valcomplex val_value_t to add the parsed parm into
objobj_template_t descriptor for the missing parm
strvalstring representation of the object value (may be NULL if obj btype is NCX_BT_EMPTY
scriptTRUE if parsing a script (in the manager)
FALSE if parsing XML or CLI
retvaladdress of return parm
Return values
*retvalcreated parm
Returns
status

Here is the call graph for this function:

status_t cli_parse_parm_ex ( runstack_context_t rcxt,
val_value_t val,
obj_template_t obj,
const xmlChar *  strval,
boolean  script,
ncx_bad_data_t  bad_data 
)

Create a val_value_t struct for the specified parm value, and insert it into the parent container value Allow different bad data error handling vioa parameter.

ONLY CALLED FROM CLI PARSING FUNCTIONS IN ncxcli.c ALLOWS SCRIPT EXTENSIONS TO BE PRESENT

A new val_value_t will be inserted in the val->v.childQ as required to fill in the parm.

Parameters
rcxtrunstack context to use
valparent value struct to adjust
objobj_template_t descriptor for the missing parm
strvalstring representation of the parm value (may be NULL if parm btype is NCX_BT_EMPTY
scriptTRUE if CLI script mode
FALSE if CLI plain mode
bad_dataenum defining how bad data should be handled
Returns
status

Here is the call graph for this function:

status_t cli_parse_parm_ret ( runstack_context_t rcxt,
val_value_t val,
obj_template_t obj,
const xmlChar *  strval,
boolean  script,
val_value_t **  retval 
)

Create a val_value_t struct for the specified parm value, and insert it into the parent container value.

Return the new parm ONLY CALLED FROM CLI PARSING FUNCTIONS IN ncxcli.c ALLOWS SCRIPT EXTENSIONS TO BE PRESENT

A new val_value_t will be inserted in the val->v.childQ as required to fill in the parm.

Parameters
rcxtrunstack context to use
valparent value struct to adjust
objobj_template_t descriptor for the missing parm
strvalstring representation of the parm value (may be NULL if parm btype is NCX_BT_EMPTY
scriptTRUE if CLI script mode
FALSE if CLI plain mode
retvaladdress of return parm
Return values
*retvalcreated parm
Returns
status
status_t cli_parse_raw ( int  argc,
char *  argv[],
dlq_hdr_t *  rawparmQ 
)

Generate N sets of variable/value pairs for the specified boot-strap CLI parameters.

There are no modules loaded yet, and nothing has been initialized, not even logging This function is almost the first thing done by the application

  CLI Syntax Supported
  [prefix] parmname
  [prefix] parmname=value
     prefix ==  0 to 2 dashes    foo  -foo --foo
     parmname == any valid NCX identifier string
     value == string
  No spaces are allowed after 'parmname' if 'value' is entered
  Each parameter is allowed to occur zero or one times.
  If multiple instances of a parameter are entered, then
  the last one entered will win.
  The 'autocomp' parameter is set to TRUE
  The 'value' string cannot be split across multiple argv segments.
  Use quotation chars within the CLI shell to pass a string
  containing whitespace to the CLI parser:
    --foo="quoted string if whitespace needed"
    --foo="quoted string if setting a variable \
          as a top-level assignment"
    --foo=unquoted-string-without-whitespace
  • There are no 1-char aliases for CLI parameters.
  • Position-dependent, unnamed parameters are not supported
Parameters
argcnumber of strings passed in 'argv'
argvarray of command line argument strings
rawparmQQ of cli_rawparm_t entries that should be used to validate the CLI input and store the results
Return values
*rawparmQ(rawparm within parmQ):
  • 'value' will be recorded if it is present
  • count will be set to the number of times this parameter was entered (set even if no value)
Returns
status

Here is the call graph for this function:

status_t conf_parse_val_from_filespec ( const xmlChar *  filespec,
val_value_t val,
boolean  keepvals,
boolean  fileerr 
)

Parse a file as an NCX text config file against a specific parmset definition.

Fill in an initialized parmset (and could be partially filled in)

Error messages are printed by this function!!

If a value is already set, and only one value is allowed then the 'keepvals' parameter will control whether that value will be kept or overwitten

Parameters
filespecabsolute path or relative path This string is used as-is without adjustment.
valvalue struct to fill in, must be initialized already with val_new_value or val_init_value
keepvals== TRUE if old values should always be kept
FALSE if old vals should be overwritten
fileerrTRUE to generate a missing file error
FALSE to return NO_ERR instead, if file not found
Returns
status of the operation

Here is the call graph for this function:

Here is the caller graph for this function:

status_t conf_parse_val_from_filespec_ex ( const xmlChar *  filespec,
const xmlChar *  banner_object,
val_value_t val,
boolean  keepvals,
boolean  fileerr,
boolean *  fileopened 
)

Parse a file as an NCX text config file against a specific parmset definition.

Fill in an initialized parmset (and could be partially filled in)

Error messages are printed by this function!!

If a value is already set, and only one value is allowed then the 'keepvals' parameter will control whether that value will be kept or overwitten

Parameters
filespecabsolute path or relative path This string is used as-is without adjustment.
banner_objectstring to display in debug-stmt about what is being loaded
valvalue struct to fill in, must be initialized already with val_new_value or val_init_value
keepvalsTRUE if old values should always be kept
FALSE if old vals should be overwritten
fileerrTRUE to generate a missing file error
FALSE to return NO_ERR instead, if file not found
fileopenedaddress of return file opened status
Return values
*fileopenedreturn file opened status
Returns
status of the operation

Here is the call graph for this function:

Here is the caller graph for this function: