CliXoN
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Macros | Functions
clixon_cli_api.h File Reference

Go to the source code of this file.

Macros

#define CLI_PROMPT_LEN   64
 
#define CLI_DEFAULT_PROMPT   ">"
 
#define cli_output   cligen_output
 

Functions

int cli_set_syntax_mode (clicon_handle h, const char *mode)
 
char * cli_syntax_mode (clicon_handle h)
 
int cli_syntax_load (clicon_handle h)
 
int cli_handler_err (FILE *fd)
 
int cli_set_prompt (clicon_handle h, const char *mode, const char *prompt)
 
char * cli_prompt (char *fmt)
 
int cli_exec (clicon_handle h, char *cmd, char **mode, int *result)
 
int cli_ptpush (clicon_handle h, char *mode, char *string, char *op)
 
int cli_ptpop (clicon_handle h, char *mode, char *op)
 
char cli_set_comment (clicon_handle h, char c)
 
char cli_comment (clicon_handle h)
 
int cli_set_exiting (clicon_handle h, int exiting)
 
int cli_exiting (clicon_handle h)
 
clicon_handle cli_handle_init (void)
 
int cli_handle_exit (clicon_handle h)
 
cligen_handle cli_cligen (clicon_handle h)
 
int cli_notification_register (clicon_handle h, char *stream, enum format_enum format, char *filter, int status, int(*fn)(int, void *), void *arg)
 
int cli_set (clicon_handle h, cvec *vars, cvec *argv)
 
int cli_setv (clicon_handle h, cvec *vars, cvec *argv)
 
int cli_merge (clicon_handle h, cvec *vars, cvec *argv)
 
int cli_mergev (clicon_handle h, cvec *vars, cvec *argv)
 
int cli_del (clicon_handle h, cvec *vars, cvec *argv)
 
int cli_delv (clicon_handle h, cvec *vars, cvec *argv)
 
int cli_debug_cli (clicon_handle h, cvec *vars, cvec *argv)
 
int cli_debug_cliv (clicon_handle h, cvec *vars, cvec *argv)
 
int cli_debug_backend (clicon_handle h, cvec *vars, cvec *argv)
 
int cli_debug_backendv (clicon_handle h, cvec *vars, cvec *argv)
 
int cli_set_mode (clicon_handle h, cvec *vars, cvec *argv)
 
int cli_set_modev (clicon_handle h, cvec *vars, cvec *argv)
 
int cli_start_shell (clicon_handle h, cvec *vars, cvec *argv)
 
int cli_start_shellv (clicon_handle h, cvec *vars, cvec *argv)
 
int cli_quit (clicon_handle h, cvec *vars, cvec *argv)
 
int cli_quitv (clicon_handle h, cvec *vars, cvec *argv)
 
int cli_commit (clicon_handle h, cvec *vars, cvec *argv)
 
int cli_commitv (clicon_handle h, cvec *vars, cvec *argv)
 
int cli_validate (clicon_handle h, cvec *vars, cvec *argv)
 
int cli_validatev (clicon_handle h, cvec *vars, cvec *argv)
 
int compare_dbs (clicon_handle h, cvec *vars, cvec *argv)
 
int compare_dbsv (clicon_handle h, cvec *vars, cvec *argv)
 
int load_config_file (clicon_handle h, cvec *vars, cvec *argv)
 
int load_config_filev (clicon_handle h, cvec *vars, cvec *argv)
 
int save_config_file (clicon_handle h, cvec *vars, cvec *argv)
 
int save_config_filev (clicon_handle h, cvec *vars, cvec *argv)
 
int delete_all (clicon_handle h, cvec *vars, cvec *argv)
 
int delete_allv (clicon_handle h, cvec *vars, cvec *argv)
 
int discard_changes (clicon_handle h, cvec *vars, cvec *argv)
 
int discard_changesv (clicon_handle h, cvec *vars, cvec *argv)
 
int cli_notify (clicon_handle h, cvec *cvv, cvec *argv)
 
int cli_notifyv (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 expand_dir (char *dir, int *nr, char ***commands, mode_t flags, int detail)
 
int expand_dbvar (void *h, char *name, cvec *cvv, cvec *argv, cvec *commands, cvec *helptexts)
 
int expandv_dbvar (void *h, char *name, cvec *cvv, cvec *argv, cvec *commands, cvec *helptexts)
 
int show_yang (clicon_handle h, cvec *vars, cvec *argv)
 
int show_yangv (clicon_handle h, cvec *vars, cvec *argv)
 
int show_conf_xpath (clicon_handle h, cvec *cvv, cvec *argv)
 
int show_confv_xpath (clicon_handle h, cvec *cvv, cvec *argv)
 
int cli_show_config (clicon_handle h, cvec *cvv, cvec *argv)
 

Macro Definition Documentation

#define CLI_DEFAULT_PROMPT   ">"
#define cli_output   cligen_output
#define CLI_PROMPT_LEN   64

Function Documentation

cligen_handle cli_cligen ( clicon_handle  h)
char cli_comment ( clicon_handle  h)
int cli_commit ( clicon_handle  h,
cvec *  vars,
cvec *  argv 
)

Generic commit callback

Parameters
[in]argvNo arguments expected
int cli_commitv ( clicon_handle  h,
cvec *  vars,
cvec *  argv 
)
int cli_copy_config ( clicon_handle  h,
cvec *  cvv,
cvec *  argv 
)

Copy one configuration object to antother

Works for objects that are items ina yang list with a keyname, eg as: list sender{ key name; leaf name{...

Parameters
[in]hCLICON handle
[in]cvvVector of variables from CLIgen command-line
[in]argvVector: <db>, <xpath>, <field>, <fromvar>, <tovar> Explanation of argv fields: db: Database name, eg candidate|tmp|startup xpath: XPATH expression with exactly two s pointing to field and from name field: Name of list key, eg name fromvar:Name of variable containing name of object to copy from (given by xpath) tovar: Name of variable containing name of object to copy to.
cli spec:
copy snd <n1:string> to <n2:string>, cli_copy_config("candidate", "/sender[%s=%s]", "from", "n1", "n2");
cli command:
copy snd from to to
int cli_debug_backend ( clicon_handle  h,
cvec *  vars,
cvec *  argv 
)

Set debug level on backend daemon (not CLI)

Parameters
[in]hClicon handle
[in]varsIf variable "level" exists, its integer value is used
[in]argElse use the integer value of argument
Note
The level is either what is specified in arg as int argument. or if a 'level' variable is present in vars use that value instead.
int cli_debug_backendv ( clicon_handle  h,
cvec *  vars,
cvec *  argv 
)
int cli_debug_cli ( clicon_handle  h,
cvec *  vars,
cvec *  argv 
)

Set debug level on CLI client (not backend daemon)

Parameters
[in]hClicon handle
[in]varsIf variable "level" exists, its integer value is used
[in]argElse use the integer value of argument
Note
The level is either what is specified in arg as int argument. or if a 'level' variable is present in vars use that value instead.
int cli_debug_cliv ( clicon_handle  h,
cvec *  vars,
cvec *  argv 
)
int cli_del ( clicon_handle  h,
cvec *  vars,
cvec *  argv 
)
int cli_delv ( clicon_handle  h,
cvec *  vars,
cvec *  argv 
)
int cli_exec ( clicon_handle  h,
char *  cmd,
char **  mode,
int *  result 
)
int cli_exiting ( clicon_handle  h)
int cli_handle_exit ( clicon_handle  h)
clicon_handle cli_handle_init ( void  )
int cli_handler_err ( FILE *  f)

Help function to print a meaningful error string. Sometimes the libraries specify an error string, if so print that. Otherwise just print 'command error'.

int cli_lock ( clicon_handle  h,
cvec *  cvv,
cvec *  argv 
)

Lock database

Parameters
[in]hClicon handle
[in]cvvNot used
[in]argA string with <database>
lock("comment"), cli_lock("running");
XXX: format is a memory leak
int cli_merge ( clicon_handle  h,
cvec *  vars,
cvec *  argv 
)
int cli_mergev ( clicon_handle  h,
cvec *  vars,
cvec *  argv 
)
int cli_notification_register ( clicon_handle  h,
char *  stream,
enum format_enum  format,
char *  filter,
int  status,
int(*)(int, void *)  fn,
void *  arg 
)

Register log notification stream

Parameters
[in]hClicon handle
[in]streamEvent stream. CLICON is predefined, others are application-defined
[in]filterFilter. For xml notification ie xpath: .[name=kalle]
[in]status0 for stop, 1 to start
[in]fnCallback function called when notification occurs
[in]argArgument to function note Note this calls cligen_regfd which may callback on cli command interpretator
int cli_notify ( clicon_handle  h,
cvec *  cvv,
cvec *  argv 
)

Make a notify subscription to backend and un/register callback for return messages.

Parameters
[in]hClicon handle
[in]cvvNot used
[in]argA string with <log stream="" name>=""> <stream status>=""> [<format>] where <status> is "0" or "1" and <format> is XXX Example code: Start logging of mystream and show logs as xml
cmd("comment"), cli_notifyv("mystream","1","xml");
XXX: format is a memory leak
int cli_notifyv ( clicon_handle  h,
cvec *  cvv,
cvec *  argv 
)
char* cli_prompt ( char *  fmt)
int cli_ptpop ( clicon_handle  h,
char *  mode,
char *  op 
)
int cli_ptpush ( clicon_handle  h,
char *  mode,
char *  string,
char *  op 
)
int cli_quit ( clicon_handle  h,
cvec *  vars,
cvec *  argv 
)

Generic quit callback

int cli_quitv ( clicon_handle  h,
cvec *  vars,
cvec *  argv 
)
int cli_set ( clicon_handle  h,
cvec *  vars,
cvec *  argv 
)
char cli_set_comment ( clicon_handle  h,
char  c 
)
int cli_set_exiting ( clicon_handle  h,
int  exiting 
)
int cli_set_mode ( clicon_handle  h,
cvec *  vars,
cvec *  argv 
)

Set syntax mode

int cli_set_modev ( clicon_handle  h,
cvec *  vars,
cvec *  argv 
)
int cli_set_prompt ( clicon_handle  h,
const char *  mode,
const char *  prompt 
)
int cli_set_syntax_mode ( clicon_handle  h,
const char *  mode 
)
int cli_setv ( clicon_handle  h,
cvec *  vars,
cvec *  argv 
)
int cli_show_config ( clicon_handle  h,
cvec *  cvv,
cvec *  argv 
)

Generic show configuration CLIGEN callback Utility function used by cligen spec file

Parameters
[in]hCLICON handle
[in]cvvVector of variables from CLIgen command-line
[in]argvString vector: <dbname> <format> <xpath> [<varname>] Format of argv: <dbname> "running"|"candidate"|"startup" <dbname> "text"|"xml"|"json"|"cli"|"netconf" (see format_enum) <xpath> xpath expression, that may contain one %, eg "/sender[name=%s]" <varname> optional name of variable in cvv. If set, xpath must have a 's'
show config id <n:string>, cli_show_config("running","xml","iface[name=%s]","n");
int cli_start_shell ( clicon_handle  h,
cvec *  vars,
cvec *  argv 
)

Start bash from cli callback XXX Application specific??

int cli_start_shellv ( clicon_handle  h,
cvec *  vars,
cvec *  argv 
)
int cli_syntax_load ( clicon_handle  h)
char* cli_syntax_mode ( clicon_handle  h)
int cli_unlock ( clicon_handle  h,
cvec *  cvv,
cvec *  argv 
)

Unlock database

Parameters
[in]hClicon handle
[in]cvvNot used
[in]argA string with <database>
lock("comment"), cli_lock("running");
XXX: format is a memory leak
int cli_validate ( clicon_handle  h,
cvec *  vars,
cvec *  argv 
)

Generic validate callback

int cli_validatev ( clicon_handle  h,
cvec *  vars,
cvec *  argv 
)
int compare_dbs ( clicon_handle  h,
cvec *  cvv,
cvec *  argv 
)

Compare two dbs using XML. Write to file and run diff

Parameters
[in]hClicon handle
[in]cvv
[in]argarg: 0 as xml, 1: as text
int compare_dbsv ( clicon_handle  h,
cvec *  vars,
cvec *  argv 
)
int db_copy ( clicon_handle  h,
cvec *  cvv,
cvec *  argv 
)

Copy from one database to another, eg running->startup

Parameters
[in]argva string: "<db1> <db2>" Copy from db1 to db2
int delete_all ( clicon_handle  h,
cvec *  cvv,
cvec *  argv 
)

Delete all elements in a database Utility function used by cligen spec file

int delete_allv ( clicon_handle  h,
cvec *  vars,
cvec *  argv 
)
int discard_changes ( clicon_handle  h,
cvec *  cvv,
cvec *  argv 
)

Discard all changes in candidate and replace with running

int discard_changesv ( clicon_handle  h,
cvec *  vars,
cvec *  argv 
)
int expand_dbvar ( void *  h,
char *  name,
cvec *  cvv,
cvec *  argv,
cvec *  commands,
cvec *  helptexts 
)

Completion callback intended for automatically generated data model

Returns an expand-type list of commands as used by cligen 'expand' functionality.

Assume callback given in a cligen spec: a <x:int expand_dbvar("arg")

Parameters
[in]hclicon handle
[in]nameName of this function (eg "expand_dbvar")
[in]cvvThe command so far. Eg: cvec [0]:"a 5 b"; [1]: x=5;
[in]argvArguments given at the callback ("<db>" "<xmlkeyfmt>")
[out]lenlen of return commands & helptxt
[out]commandsvector of function pointers to callback functions
[out]helptxtvector of pointers to helptexts
See Also
cli_expand_var_generate This is where arg is generated XXX: helptexts?
int expand_dir ( char *  dir,
int *  nr,
char ***  commands,
mode_t  flags,
int  detail 
)

List files in a directory

int expandv_dbvar ( void *  h,
char *  name,
cvec *  cvv,
cvec *  argv,
cvec *  commands,
cvec *  helptexts 
)
int load_config_file ( clicon_handle  h,
cvec *  cvv,
cvec *  argv 
)

Load a configuration file to candidate database Utility function used by cligen spec file

Parameters
[in]hCLICON handle
[in]cvvVector of variables (where <varname> is found)
[in]argvA string: "<varname> (merge|replace)" <varname> is name of a variable occuring in "cvv" containing filename
Note
that "filename" is local on client filesystem not backend.
file is assumed to have a dummy top-tag, eg <clicon></clicon>
# cligen spec
load file <name2:string>, load_config_filev("name2","merge");
See Also
save_config_file
int load_config_filev ( clicon_handle  h,
cvec *  vars,
cvec *  argv 
)
int save_config_file ( clicon_handle  h,
cvec *  cvv,
cvec *  argv 
)

Copy database to local file Utility function used by cligen spec file

Parameters
[in]hCLICON handle
[in]cvvvariable vector (containing <varname>)
[in]argva string: "<dbname> <varname>" <dbname> is running, candidate, or startup <varname> is name of cligen variable in the "cvv" vector containing file name Note that "filename" is local on client filesystem not backend. The function can run without a local database
Note
The file is saved with dummy top-tag: clicon: <clicon></clicon>
save file <name:string>, save_config_file("running name");
See Also
load_config_file
int save_config_filev ( clicon_handle  h,
cvec *  vars,
cvec *  argv 
)
int show_conf_xpath ( clicon_handle  h,
cvec *  cvv,
cvec *  argv 
)

Show configuration as text given an xpath Utility function used by cligen spec file

Parameters
[in]hCLICON handle
[in]cvvVector of variables from CLIgen command-line
[in]argA string: <dbname> <xpath>
Note
Hardcoded that a variable in cvv is named "xpath"
int show_confv_xpath ( clicon_handle  h,
cvec *  cvv,
cvec *  argv 
)
int show_yang ( clicon_handle  h,
cvec *  cvv,
cvec *  argv 
)

CLI callback show yang spec. If arg given matches yang argument string

int show_yangv ( clicon_handle  h,
cvec *  vars,
cvec *  argv 
)