The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Data Structures | Macros | Typedefs | Functions | Variables
command.h File Reference

Structures and prototypes command functions. More...

#include <freeradius-devel/util/value.h>
+ Include dependency graph for command.h:

Go to the source code of this file.

Data Structures

struct  fr_cmd_info_t
 
struct  fr_cmd_table_t
 
struct  fr_cmd_walk_info_t
 

Macros

#define CMD_MAX_ARGV   (32)
 
#define CMD_TABLE_END   { .help = NULL }
 
#define FR_COMMAND_OPTION_HELP   (1 << 2)
 
#define FR_COMMAND_OPTION_LIST_CHILD   (1 << 0)
 
#define FR_COMMAND_OPTION_NAME   (1 << 1)
 
#define FR_COMMAND_OPTION_NONE   (0)
 

Typedefs

typedef int(* fr_cmd_func_t) (FILE *fp, FILE *fp_err, void *ctx, fr_cmd_info_t const *info)
 
typedef struct fr_cmd_s fr_cmd_t
 
typedef int(* fr_cmd_tab_t) (TALLOC_CTX *talloc_ctx, void *ctx, fr_cmd_info_t *info, int max_expansions, char const **expansions)
 
typedef int(* fr_cmd_walk_t) (void *ctx, fr_cmd_walk_info_t *)
 
typedef int(* fr_command_register_hook_t) (TALLOC_CTX *talloc_ctx, char const *name, void *ctx, fr_cmd_table_t *table)
 

Functions

int fr_command_add (TALLOC_CTX *talloc_ctx, fr_cmd_t **head_p, char const *name, void *ctx, fr_cmd_table_t const *table)
 Add one command to the global command tree. More...
 
int fr_command_add_multi (TALLOC_CTX *talloc_ctx, fr_cmd_t **heap_p, char const *name, void *ctx, fr_cmd_table_t const *table)
 Add multiple commands to the global command tree. More...
 
int fr_command_clear (int new_argc, fr_cmd_info_t *info)
 Clear out any value boxes etc. More...
 
int fr_command_complete (fr_cmd_t *head, char const *text, int start, int max_expansions, char const **expansions)
 Do readline-style command completions. More...
 
void fr_command_debug (FILE *fp, fr_cmd_t *head)
 
char const * fr_command_help (fr_cmd_t *head, int argc, char *argv[])
 Get help text for a particular command. More...
 
void fr_command_info_init (TALLOC_CTX *ctx, fr_cmd_info_t *info)
 Initialize an fr_cmd_info_t structure. More...
 
void fr_command_list (FILE *fp, int max_depth, fr_cmd_t *head, int options)
 
int fr_command_print_help (FILE *fp, fr_cmd_t *head, char const *text)
 Do readline-style help completions. More...
 
int fr_command_run (FILE *fp, FILE *fp_err, fr_cmd_info_t *info, bool read_only)
 Run a particular command. More...
 
int fr_command_str_to_argv (fr_cmd_t *head, fr_cmd_info_t *info, char const *str)
 Split a string in-place, updating argv[]. More...
 
bool fr_command_strncmp (const char *text, const char *name)
 
int fr_command_tab_expand (TALLOC_CTX *ctx, fr_cmd_t *head, fr_cmd_info_t *info, int max_expansions, char const **expansions)
 Get the commands && help at a particular level. More...
 
int fr_command_walk (fr_cmd_t *head, void **walk_ctx, void *ctx, fr_cmd_walk_t callback)
 Walk over a command hierarchy. More...
 

Variables

fr_command_register_hook_t fr_command_register_hook
 

Detailed Description

Structures and prototypes command functions.

Id
3cdf8eb3ff240c43af3443982f1ad669233e2a1e

Definition in file command.h.


Data Structure Documentation

◆ fr_cmd_info_t

struct fr_cmd_info_t

Definition at line 38 of file command.h.

+ Collaboration diagram for fr_cmd_info_t:
Data Fields
int argc current argument count
char const ** argv text version of commands
fr_value_box_t ** box value_box version of commands.
fr_cmd_t ** cmd cached commands at each offset
int max_argc maximum number of arguments
bool runnable is the command runnable?

◆ fr_cmd_table_t

struct fr_cmd_table_t

Definition at line 51 of file command.h.

+ Collaboration diagram for fr_cmd_table_t:
Data Fields
bool add_name do we add a name here?
fr_cmd_func_t func function to process this command
char const * help help text
char const * name e.g. "stats"
char const * parent e.g. "show module"
bool read_only
char const * syntax e.g. "STRING"
fr_cmd_tab_t tab_expand tab expand things in the syntax string

◆ fr_cmd_walk_info_t

struct fr_cmd_walk_info_t

Definition at line 64 of file command.h.

Data Fields
char const * help
char const * name
int num_parents
char const ** parents
char const * syntax

Macro Definition Documentation

◆ CMD_MAX_ARGV

#define CMD_MAX_ARGV   (32)

Definition at line 34 of file command.h.

◆ CMD_TABLE_END

#define CMD_TABLE_END   { .help = NULL }

Definition at line 62 of file command.h.

◆ FR_COMMAND_OPTION_HELP

#define FR_COMMAND_OPTION_HELP   (1 << 2)

Definition at line 90 of file command.h.

◆ FR_COMMAND_OPTION_LIST_CHILD

#define FR_COMMAND_OPTION_LIST_CHILD   (1 << 0)

Definition at line 88 of file command.h.

◆ FR_COMMAND_OPTION_NAME

#define FR_COMMAND_OPTION_NAME   (1 << 1)

Definition at line 89 of file command.h.

◆ FR_COMMAND_OPTION_NONE

#define FR_COMMAND_OPTION_NONE   (0)

Definition at line 87 of file command.h.

Typedef Documentation

◆ fr_cmd_func_t

typedef int(* fr_cmd_func_t) (FILE *fp, FILE *fp_err, void *ctx, fr_cmd_info_t const *info)

Definition at line 47 of file command.h.

◆ fr_cmd_t

typedef struct fr_cmd_s fr_cmd_t

Definition at line 1 of file command.h.

◆ fr_cmd_tab_t

typedef int(* fr_cmd_tab_t) (TALLOC_CTX *talloc_ctx, void *ctx, fr_cmd_info_t *info, int max_expansions, char const **expansions)

Definition at line 49 of file command.h.

◆ fr_cmd_walk_t

typedef int(* fr_cmd_walk_t) (void *ctx, fr_cmd_walk_info_t *)

Definition at line 72 of file command.h.

◆ fr_command_register_hook_t

typedef int(* fr_command_register_hook_t) (TALLOC_CTX *talloc_ctx, char const *name, void *ctx, fr_cmd_table_t *table)

Definition at line 73 of file command.h.

Function Documentation

◆ fr_command_add()

int fr_command_add ( TALLOC_CTX *  talloc_ctx,
fr_cmd_t **  head,
char const *  name,
void *  ctx,
fr_cmd_table_t const *  table 
)

Add one command to the global command tree.

We do not do any sanity checks on "name". If it has spaces in it, or "special" characters, that's up to you. We assume that other things in the server will sanity check them.

Parameters
talloc_ctxthe talloc context
headpointer to the head of the command table.
nameof the command to allocate. Can be NULL for "top level" commands
ctxfor any callback function
tableof information about the current command
Returns
  • <0 on error
  • 0 on success

Definition at line 725 of file command.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_command_add_multi()

int fr_command_add_multi ( TALLOC_CTX *  talloc_ctx,
fr_cmd_t **  head,
char const *  name,
void *  ctx,
fr_cmd_table_t const *  table 
)

Add multiple commands to the global command tree.

e.g. for module "foo", add "show module foo", "set module foo", etc.

Parameters
talloc_ctxthe talloc context
headpointer to the head of the command table.
nameof the command to allocate
ctxfor any callback function
tablearray of tables, terminated by "help == NULL"
Returns
  • <0 on error
  • 0 on success

Definition at line 985 of file command.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_command_clear()

int fr_command_clear ( int  new_argc,
fr_cmd_info_t info 
)

Clear out any value boxes etc.

Parameters
new_argcthe argc to set inside of info
infothe information with the current argc

Definition at line 2369 of file command.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_command_complete()

int fr_command_complete ( fr_cmd_t head,
char const *  text,
int  start,
int  max_expansions,
char const **  expansions 
)

Do readline-style command completions.

Most useful as part of readline tab expansions. The expansions are strdup() strings, and MUST be free'd by the caller.

Parameters
headof the command tree
textthe text to check
startoffset in the text where the completions should start
max_expansionshow many entries in the "expansions" array.
[in,out]expansionswhere the expansions are stored.
Returns
  • <0 on error
  • >= 0 number of expansions in the array

Definition at line 2659 of file command.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_command_debug()

void fr_command_debug ( FILE *  fp,
fr_cmd_t head 
)

Definition at line 1602 of file command.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_command_help()

char const* fr_command_help ( fr_cmd_t head,
int  argc,
char *  argv[] 
)

Get help text for a particular command.

Parameters
headthe head of the hierarchy.
argcthe number of arguments in argv
argvthe arguments
Returns
  • NULL on "no help text"
  • !NULL is the help text. Do not free or access it.

Definition at line 1553 of file command.c.

+ Here is the call graph for this function:

◆ fr_command_info_init()

void fr_command_info_init ( TALLOC_CTX *  ctx,
fr_cmd_info_t info 
)

Initialize an fr_cmd_info_t structure.

Definition at line 2397 of file command.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_command_list()

void fr_command_list ( FILE *  fp,
int  max_depth,
fr_cmd_t head,
int  options 
)

Definition at line 1649 of file command.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_command_print_help()

int fr_command_print_help ( FILE *  fp,
fr_cmd_t head,
char const *  text 
)

Do readline-style help completions.

Most useful as part of readline.

Parameters
fpwhere the help is printed
headof the command tree
textthe text to check

Definition at line 2802 of file command.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_command_run()

int fr_command_run ( FILE *  fp,
FILE *  fp_err,
fr_cmd_info_t info,
bool  read_only 
)

Run a particular command.

info->argc is left alone, as are all other fields. If you want to run multiple commands, call fr_command_clear(0, info) to zero out the relevant information.

Parameters
fpwhere the output is sent
fp_errwhere the error output is sent
infothe structure describing the command to expand
read_onlywhether or not this command should be run in read-only mode.
Returns
  • <0 on error
  • 0 the command was run successfully

Definition at line 1473 of file command.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_command_str_to_argv()

int fr_command_str_to_argv ( fr_cmd_t head,
fr_cmd_info_t info,
char const *  text 
)

Split a string in-place, updating argv[].

This function also respects the various data types (mostly). Strings can have quotes. Nothing else can have quotes. Non-string data types are skipped and only parsed to data types by fr_command_run().

Parameters
headthe head of the hierarchy.
infothe structure describing the command to expand
textthe string to split
Returns
  • <0 on error.
  • total number of arguments in the argv[] array. Always >= argc.

Definition at line 2141 of file command.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_command_strncmp()

bool fr_command_strncmp ( const char *  text,
const char *  name 
)

Definition at line 2906 of file command.c.

+ Here is the caller graph for this function:

◆ fr_command_tab_expand()

int fr_command_tab_expand ( TALLOC_CTX *  ctx,
fr_cmd_t head,
fr_cmd_info_t info,
int  max_expansions,
char const **  expansions 
)

Get the commands && help at a particular level.

Parameters
ctxtalloc context for dynamically allocated expansions. The caller should free it to free all expansions it created. Expansions added by this function are "const char *", and are managed by the command hierarchy.
headthe head of the hierarchy.
infothe structure describing the command to expand
max_expansionsthe maximum number of entries in the expansions array
expansionswhere the expansions will be stored.
Returns
  • <0 on error
  • number of entries in the expansions array

Definition at line 1290 of file command.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_command_walk()

int fr_command_walk ( fr_cmd_t head,
void **  walk_ctx,
void *  ctx,
fr_cmd_walk_t  callback 
)

Walk over a command hierarchy.

Parameters
headthe head of the hierarchy. Call it with NULL to clean up walk_ctx
[in,out]walk_ctxto track across multiple function calls. MUST point to a void* when starting
ctxfor the callback
callbackto call with fr_walk_info_t about each command
Returns
  • <0 on error
  • 0 for nothing more to do.
  • 1 for "please call me again to get the next command". and walk_ctx now points to data allocated by, and managed by this function. It MUST be cleaned up via another call to this function.

Definition at line 1019 of file command.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ fr_command_register_hook

fr_command_register_hook_t fr_command_register_hook
extern

Definition at line 42 of file command.c.