CliXoN
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Macros | Functions
cli_plugin.c File Reference
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdarg.h>
#include <syslog.h>
#include <errno.h>
#include <assert.h>
#include <dlfcn.h>
#include <dirent.h>
#include <libgen.h>
#include <grp.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/param.h>
#include <netinet/in.h>
#include <cligen/cligen.h>
#include <clixon/clixon.h>
#include "clixon_cli_api.h"
#include "cli_plugin.h"
#include "cli_handle.h"

Macros

#define PLUGIN_PROMPT_HOOK   "plugin_prompt_hook"
 
#define PLUGIN_PARSE_HOOK   "plugin_parse_hook"
 
#define PLUGIN_SUSP_HOOK   "plugin_susp_hook"
 

Functions

static cli_syntaxmode_tsyntax_mode_find (cli_syntax_t *stx, const char *mode, int create)
 
static struct cli_pluginplugin_find_cli (cli_syntax_t *stx, char *plgnam)
 
static int gen_parse_tree (clicon_handle h, cli_syntaxmode_t *m)
 
static int syntax_append (clicon_handle h, cli_syntax_t *stx, const char *name, parse_tree pt)
 
static int plugin_unload (clicon_handle h, void *handle)
 
static int syntax_unload (clicon_handle h)
 
void * clixon_str2fn (char *name, void *handle, char **error)
 
static plghndl_t cli_plugin_load (clicon_handle h, char *file, int dlflags, const char *cnklbl)
 
static int cli_load_syntax (clicon_handle h, const char *filename, const char *clispec_dir)
 
static int cli_plugin_load_dir (clicon_handle h, char *dir, cli_syntax_t *stx)
 
int cli_syntax_load (clicon_handle h)
 
int cli_plugin_start (clicon_handle h, int argc, char **argv)
 
int cli_plugin_finish (clicon_handle h)
 
int cli_handler_err (FILE *f)
 
int clicon_eval (clicon_handle h, char *cmd, cg_obj *match_obj, cvec *vr)
 
int clicon_parse (clicon_handle h, char *cmd, char **mode, int *result)
 
char * clicon_cliread (clicon_handle h)
 
static void * cli_find_plugin (clicon_handle h, char *plugin)
 
int cli_plugin_init (clicon_handle h)
 
int cli_set_syntax_mode (clicon_handle h, const char *name)
 
char * cli_syntax_mode (clicon_handle h)
 
int cli_set_prompt (clicon_handle h, const char *name, const char *prompt)
 
static int prompt_fmt (char *prompt, size_t plen, char *fmt,...)
 
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)
 
int clicon_valcb (void *arg, cvec *vars, cg_var *cgv, char *fname, cg_var *funcarg)
 

Macro Definition Documentation

#define PLUGIN_PARSE_HOOK   "plugin_parse_hook"
#define PLUGIN_PROMPT_HOOK   "plugin_prompt_hook"
#define PLUGIN_SUSP_HOOK   "plugin_susp_hook"

Function Documentation

int cli_exec ( clicon_handle  h,
char *  cmd,
char **  mode,
int *  result 
)
static void* cli_find_plugin ( clicon_handle  h,
char *  plugin 
)
static
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'.

static int cli_load_syntax ( clicon_handle  h,
const char *  filename,
const char *  clispec_dir 
)
static
int cli_plugin_finish ( clicon_handle  h)
int cli_plugin_init ( clicon_handle  h)

Initialize plugin code (not the plugins themselves)

static plghndl_t cli_plugin_load ( clicon_handle  h,
char *  file,
int  dlflags,
const char *  cnklbl 
)
static
static int cli_plugin_load_dir ( clicon_handle  h,
char *  dir,
cli_syntax_t stx 
)
static
int cli_plugin_start ( clicon_handle  h,
int  argc,
char **  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_set_prompt ( clicon_handle  h,
const char *  name,
const char *  prompt 
)
int cli_set_syntax_mode ( clicon_handle  h,
const char *  name 
)
int cli_syntax_load ( clicon_handle  h)
char* cli_syntax_mode ( clicon_handle  h)
char* clicon_cliread ( clicon_handle  h)
int clicon_eval ( clicon_handle  h,
char *  cmd,
cg_obj *  match_obj,
cvec *  vr 
)
int clicon_parse ( clicon_handle  h,
char *  cmd,
char **  mode,
int *  result 
)
int clicon_valcb ( void *  arg,
cvec *  vars,
cg_var *  cgv,
char *  fname,
cg_var *  funcarg 
)
void* clixon_str2fn ( char *  name,
void *  handle,
char **  error 
)

Dynamic linking loader string to function mapper

Maps strings from the CLI specification file to real funtions using dlopen mapping. First look for function name in local namespace if handle given (given plugin) Then check global namespace, i.e.m lib*.so

Parameters
[in]nameName of function
[in]handleHandle to plugin .so module as returned by dlopen
[out]errorStatic error string, if set indicates error
Return values
fnFunction pointer
NULLFUnction not found or symbol NULL (check error for proper handling)
See Also
see cli_plugin_load where (optional) handle opened
Note
the returned function is not type-checked which may result in segv at runtime
static int gen_parse_tree ( clicon_handle  h,
cli_syntaxmode_t m 
)
static
static struct cli_plugin* plugin_find_cli ( cli_syntax_t stx,
char *  plgnam 
)
static
static int plugin_unload ( clicon_handle  h,
void *  handle 
)
static
static int prompt_fmt ( char *  prompt,
size_t  plen,
char *  fmt,
  ... 
)
static
static int syntax_append ( clicon_handle  h,
cli_syntax_t stx,
const char *  name,
parse_tree  pt 
)
static
static cli_syntaxmode_t* syntax_mode_find ( cli_syntax_t stx,
const char *  mode,
int  create 
)
static
static int syntax_unload ( clicon_handle  h)
static