CliXoN
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Functions
cli_common.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <errno.h>
#include <stdarg.h>
#include <time.h>
#include <ctype.h>
#include <unistd.h>
#include <dirent.h>
#include <syslog.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/wait.h>
#include <sys/param.h>
#include <sys/mount.h>
#include <pwd.h>
#include <assert.h>
#include <cligen/cligen.h>
#include <clixon/clixon.h>
#include "clixon_cli_api.h"
#include "cli_common.h"

Functions

int cli_notification_register (clicon_handle h, char *stream, enum format_enum format, char *filter, int status, int(*fn)(int, void *), void *arg)
 
void cli_signal_block (clicon_handle h)
 
void cli_signal_unblock (clicon_handle h)
 
void cli_signal_flush (clicon_handle h)
 
static int cli_dbxml (clicon_handle h, cvec *cvv, cvec *argv, enum operation_type op)
 
int cli_set (clicon_handle h, cvec *cvv, cvec *argv)
 
int cli_setv (clicon_handle h, cvec *vars, cvec *argv)
 
int cli_merge (clicon_handle h, cvec *cvv, cvec *argv)
 
int cli_mergev (clicon_handle h, cvec *vars, cvec *argv)
 
int cli_del (clicon_handle h, cvec *cvv, 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)
 
static int compare_xmls (cxobj *xc1, cxobj *xc2, int astext)
 
int compare_dbs (clicon_handle h, cvec *cvv, cvec *argv)
 
int compare_dbsv (clicon_handle h, cvec *vars, cvec *argv)
 
int load_config_file (clicon_handle h, cvec *cvv, cvec *argv)
 
int load_config_filev (clicon_handle h, cvec *vars, cvec *argv)
 
int save_config_file (clicon_handle h, cvec *cvv, cvec *argv)
 
int save_config_filev (clicon_handle h, cvec *vars, cvec *argv)
 
int delete_all (clicon_handle h, cvec *cvv, cvec *argv)
 
int delete_allv (clicon_handle h, cvec *vars, cvec *argv)
 
int discard_changes (clicon_handle h, cvec *cvv, cvec *argv)
 
int discard_changesv (clicon_handle h, cvec *vars, cvec *argv)
 
int db_copy (clicon_handle h, cvec *cvv, cvec *argv)
 
static int cli_notification_cb (int s, void *arg)
 
int cli_notify (clicon_handle h, cvec *cvv, cvec *argv)
 
int cli_notifyv (clicon_handle h, cvec *vars, cvec *argv)
 
int cli_lock (clicon_handle h, cvec *cvv, cvec *argv)
 
int cli_unlock (clicon_handle h, cvec *cvv, cvec *argv)
 
int cli_copy_config (clicon_handle h, cvec *cvv, cvec *argv)
 
int cli_debug (clicon_handle h, cvec *vars, cg_var *arg)
 

Function Documentation

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
static int cli_dbxml ( clicon_handle  h,
cvec *  cvv,
cvec *  argv,
enum operation_type  op 
)
static

Modify xml database from a callback using xml key format strings

Parameters
[in]hClicon handle
[in]cvvVector of cli string and instantiated variables
[in]argvVector. First element xml key format string, eg "/aaa/%s"
[in]opOperation to perform on database Cvv will contain first the complete cli string, and then a set of optional instantiated variables. Example: cvv[0] = "set interfaces interface eth0 type bgp" cvv[1] = "eth0" cvv[2] = "bgp" argv[0] = "/interfaces/interface/%s/type" op: OP_MERGE
See Also
cli_callback_generate where arg is generated
int cli_debug ( clicon_handle  h,
cvec *  vars,
cg_var *  arg 
)

set debug level on stderr (not syslog). 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. XXX obsolete. Use cli_debug_cliv or cli_debug_backendv instead

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 *  cvv,
cvec *  argv 
)
int cli_delv ( clicon_handle  h,
cvec *  vars,
cvec *  argv 
)
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 *  cvv,
cvec *  argv 
)
int cli_mergev ( clicon_handle  h,
cvec *  vars,
cvec *  argv 
)
static int cli_notification_cb ( int  s,
void *  arg 
)
static

This is the callback used by cli_setlog to print log message in CLI param[in] s UNIX socket from backend where message should be read param[in] arg format: txt, xml, xml2txt, xml2json

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 *  vars,
cvec *  argv 
)
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 *  cvv,
cvec *  argv 
)
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_setv ( clicon_handle  h,
cvec *  vars,
cvec *  argv 
)
void cli_signal_block ( clicon_handle  h)
void cli_signal_flush ( clicon_handle  h)
void cli_signal_unblock ( clicon_handle  h)
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_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 
)
static int compare_xmls ( cxobj *  xc1,
cxobj *  xc2,
int  astext 
)
static

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

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