Structures and prototypes command functions.
More...
#include <freeradius-devel/util/value.h>
Go to the source code of this file.
|
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) |
|
|
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...
|
|
Structures and prototypes command functions.
- Id
- 3cdf8eb3ff240c43af3443982f1ad669233e2a1e
- Copyright
- 2007 Alan DeKok
Definition in file command.h.
◆ fr_cmd_info_t
Definition at line 38 of file command.h.
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
Definition at line 51 of file command.h.
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 |
|
◆ CMD_MAX_ARGV
◆ CMD_TABLE_END
#define CMD_TABLE_END { .help = NULL } |
◆ FR_COMMAND_OPTION_HELP
#define FR_COMMAND_OPTION_HELP (1 << 2) |
◆ FR_COMMAND_OPTION_LIST_CHILD
#define FR_COMMAND_OPTION_LIST_CHILD (1 << 0) |
◆ FR_COMMAND_OPTION_NAME
#define FR_COMMAND_OPTION_NAME (1 << 1) |
◆ FR_COMMAND_OPTION_NONE
#define FR_COMMAND_OPTION_NONE (0) |
◆ fr_cmd_func_t
typedef int(* fr_cmd_func_t) (FILE *fp, FILE *fp_err, void *ctx, fr_cmd_info_t const *info) |
◆ fr_cmd_t
◆ 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) |
◆ fr_cmd_walk_t
◆ 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) |
◆ 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_ctx | the talloc context |
head | pointer to the head of the command table. |
name | of the command to allocate. Can be NULL for "top level" commands |
ctx | for any callback function |
table | of information about the current command |
- Returns
-
Definition at line 725 of file command.c.
◆ 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_ctx | the talloc context |
head | pointer to the head of the command table. |
name | of the command to allocate |
ctx | for any callback function |
table | array of tables, terminated by "help == NULL" |
- Returns
-
Definition at line 985 of file command.c.
◆ fr_command_clear()
Clear out any value boxes etc.
- Parameters
-
new_argc | the argc to set inside of info |
info | the information with the current argc |
Definition at line 2369 of file command.c.
◆ 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
-
| head | of the command tree |
| text | the text to check |
| start | offset in the text where the completions should start |
| max_expansions | how many entries in the "expansions" array. |
[in,out] | expansions | where the expansions are stored. |
- Returns
- <0 on error
- >= 0 number of expansions in the array
Definition at line 2659 of file command.c.
◆ fr_command_debug()
void fr_command_debug |
( |
FILE * |
fp, |
|
|
fr_cmd_t * |
head |
|
) |
| |
◆ fr_command_help()
char const* fr_command_help |
( |
fr_cmd_t * |
head, |
|
|
int |
argc, |
|
|
char * |
argv[] |
|
) |
| |
Get help text for a particular command.
- Parameters
-
head | the head of the hierarchy. |
argc | the number of arguments in argv |
argv | the 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.
◆ fr_command_info_init()
void fr_command_info_init |
( |
TALLOC_CTX * |
ctx, |
|
|
fr_cmd_info_t * |
info |
|
) |
| |
◆ fr_command_list()
void fr_command_list |
( |
FILE * |
fp, |
|
|
int |
max_depth, |
|
|
fr_cmd_t * |
head, |
|
|
int |
options |
|
) |
| |
◆ 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
-
fp | where the help is printed |
head | of the command tree |
text | the text to check |
Definition at line 2802 of file command.c.
◆ 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
-
fp | where the output is sent |
fp_err | where the error output is sent |
info | the structure describing the command to expand |
read_only | whether 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.
◆ fr_command_str_to_argv()
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
-
head | the head of the hierarchy. |
info | the structure describing the command to expand |
text | the 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.
◆ fr_command_strncmp()
bool fr_command_strncmp |
( |
const char * |
text, |
|
|
const char * |
name |
|
) |
| |
◆ 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
-
ctx | talloc 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. |
head | the head of the hierarchy. |
info | the structure describing the command to expand |
max_expansions | the maximum number of entries in the expansions array |
expansions | where the expansions will be stored. |
- Returns
- <0 on error
- number of entries in the expansions array
Definition at line 1290 of file command.c.
◆ fr_command_walk()
Walk over a command hierarchy.
- Parameters
-
| head | the head of the hierarchy. Call it with NULL to clean up walk_ctx |
[in,out] | walk_ctx | to track across multiple function calls. MUST point to a void* when starting |
| ctx | for the callback |
| callback | to 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.
◆ fr_command_register_hook