The FreeRADIUS server
$Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
|
Internal commands for the server. More...
#include <freeradius-devel/server/command.h>
#include <freeradius-devel/server/log.h>
#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/util/misc.h>
Go to the source code of this file.
Data Structures | |
struct | fr_cmd_argv_s |
struct | fr_cmd_s |
struct | fr_cmd_stack_t |
A stack for walking commands. More... | |
Macros | |
#define | FR_TYPE_ALTERNATE FR_TYPE_VSA |
#define | FR_TYPE_ALTERNATE_CHOICE FR_TYPE_GROUP |
#define | FR_TYPE_FIXED FR_TYPE_TIME_DELTA |
#define | FR_TYPE_OPTIONAL FR_TYPE_STRUCT |
#define | FR_TYPE_VARARGS FR_TYPE_TLV |
#define | MATCHED_NAME ((!*p || isspace((uint8_t) *p)) && !*q) |
#define | MATCHED_START ((text + start) >= word) && ((text + start) <= p) |
#define | SKIP_NAME(name) |
#define | TOO_FAR (*p && (*q > *p)) |
Typedefs | |
typedef struct fr_cmd_argv_s | fr_cmd_argv_t |
Functions | |
static int | expand_all (fr_cmd_t *cmd, fr_cmd_info_t *info, fr_cmd_argv_t *argv, int count, int max_expansions, char const **expansions) |
static int | expand_syntax (fr_cmd_t *cmd, fr_cmd_info_t *info, fr_cmd_argv_t *argv, char const *text, int start, char const **word_p, int count, int max_expansions, char const **expansions) |
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. More... | |
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. More... | |
static int | fr_command_add_syntax (TALLOC_CTX *ctx, char *syntax, fr_cmd_argv_t **head, bool allow_varargs) |
static fr_cmd_t * | fr_command_alloc (TALLOC_CTX *ctx, fr_cmd_t **head, char const *name) |
Allocate an fr_cmd_t structure. 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) |
static void | fr_command_debug_internal (FILE *fp, fr_cmd_t *head, int depth) |
static void | fr_command_debug_node (FILE *fp, fr_cmd_t *cmd, int depth) |
static fr_cmd_t * | fr_command_find (fr_cmd_t **head, char const *name, fr_cmd_t ***insert) |
Find a command. More... | |
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) |
static void | fr_command_list_internal (FILE *fp, fr_cmd_t *head, int depth, int max_depth, char const **argv, int options) |
static void | fr_command_list_node (FILE *fp, fr_cmd_t *cmd, int depth, char const **argv, int options) |
int | fr_command_print_help (FILE *fp, fr_cmd_t *head, char const *text) |
Do readline-style help completions. More... | |
static int | fr_command_register (UNUSED TALLOC_CTX *talloc_ctx, UNUSED char const *name, UNUSED void *ctx, UNUSED fr_cmd_table_t *table) |
int | fr_command_run (FILE *fp, FILE *fp_err, fr_cmd_info_t *info, bool read_only) |
Run a particular command. More... | |
static int | fr_command_run_partial (FILE *fp, FILE *fp_err, fr_cmd_info_t *info, bool read_only, int offset, fr_cmd_t *head) |
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[]. More... | |
bool | fr_command_strncmp (const char *word, 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... | |
static int | fr_command_tab_expand_argv (TALLOC_CTX *ctx, fr_cmd_t *cmd, fr_cmd_info_t *info, char const *name, fr_cmd_argv_t *argv, int max_expansions, char const **expansions) |
static int | fr_command_tab_expand_partial (fr_cmd_t *head, char const *partial, int max_expansions, char const **expansions) |
static int | fr_command_tab_expand_syntax (TALLOC_CTX *ctx, fr_cmd_t *cmd, int syntax_offset, fr_cmd_info_t *info, int max_expansions, char const **expansions) |
static bool | fr_command_valid_name (char const *name) |
static bool | fr_command_valid_syntax (fr_cmd_argv_t *argv) |
static int | fr_command_verify_argv (fr_cmd_info_t *info, int start, int verify, int argc, fr_cmd_argv_t **argv_p, bool optional) |
int | fr_command_walk (fr_cmd_t *head, void **walk_ctx, void *ctx, fr_cmd_walk_t callback) |
Walk over a command hierarchy. More... | |
static void | print_help (FILE *fp, fr_cmd_t *cmd) |
static char const * | skip_word (char const *text) |
static int | split (char **input, char **output, bool syntax_string) |
static int | split_alternation (char **input, char **output) |
static int | syntax_str_to_argv (int start_argc, fr_cmd_argv_t *start, fr_cmd_info_t *info, char const **text, bool *runnable) |
Check the syntax of a command, starting at *text More... | |
Variables | |
fr_command_register_hook_t | fr_command_register_hook = fr_command_register |
static const char * | tabs = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" |
Internal commands for the server.
Definition in file command.c.
struct fr_cmd_argv_s |
Data Fields | ||
---|---|---|
fr_cmd_argv_t * | child | |
char const * | name | |
fr_cmd_argv_t * | next | |
fr_type_t | type |
struct fr_cmd_s |
Data Fields | ||
---|---|---|
bool | added_name | was this name added? |
struct fr_cmd_s * | child | if there are subcommands |
void * | ctx | |
fr_cmd_func_t | func | |
char const * | help |
|
bool | intermediate | intermediate commands can't have callbacks |
bool | live | is this entry live? |
char const * | name | |
struct fr_cmd_s * | next | |
bool | read_only | |
char const * | syntax | only for terminal nodes |
fr_cmd_argv_t * | syntax_argv | arguments and types |
fr_cmd_tab_t | tab_expand |
struct fr_cmd_stack_t |
Data Fields | ||
---|---|---|
int | depth | |
fr_cmd_t * | entry[CMD_MAX_ARGV] | |
char const ** | parents |
#define FR_TYPE_ALTERNATE FR_TYPE_VSA |
#define FR_TYPE_ALTERNATE_CHOICE FR_TYPE_GROUP |
#define FR_TYPE_FIXED FR_TYPE_TIME_DELTA |
#define FR_TYPE_OPTIONAL FR_TYPE_STRUCT |
#define FR_TYPE_VARARGS FR_TYPE_TLV |
#define MATCHED_START ((text + start) >= word) && ((text + start) <= p) |
typedef struct fr_cmd_argv_s fr_cmd_argv_t |
|
static |
|
static |
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.
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 |
Definition at line 725 of file command.c.
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.
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" |
Definition at line 985 of file command.c.
|
static |
Allocate an fr_cmd_t structure.
We presume that this allocation is done after a call to fr_command_find()
ctx | talloc ctx for the allocation |
head | of the command list (singly linked) |
name | of the command to allocate |
Definition at line 150 of file command.c.
int fr_command_clear | ( | int | new_argc, |
fr_cmd_info_t * | info | ||
) |
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.
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. |
Definition at line 2659 of file command.c.
void fr_command_debug | ( | FILE * | fp, |
fr_cmd_t * | head | ||
) |
|
static |
|
static |
|
static |
Find a command.
head | the head of the list |
name | of the command to find |
insert | where the new command should be inserted |
Definition at line 100 of file command.c.
char const* fr_command_help | ( | fr_cmd_t * | head, |
int | argc, | ||
char * | argv[] | ||
) |
Get help text for a particular command.
head | the head of the hierarchy. |
argc | the number of arguments in argv |
argv | the arguments |
Definition at line 1553 of file command.c.
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.
void fr_command_list | ( | FILE * | fp, |
int | max_depth, | ||
fr_cmd_t * | head, | ||
int | options | ||
) |
|
static |
|
static |
int fr_command_print_help | ( | FILE * | fp, |
fr_cmd_t * | head, | ||
char const * | text | ||
) |
|
static |
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.
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. |
Definition at line 1473 of file command.c.
|
static |
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().
head | the head of the hierarchy. |
info | the structure describing the command to expand |
text | the string to split |
Definition at line 2141 of file command.c.
bool fr_command_strncmp | ( | const char * | word, |
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.
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. |
Definition at line 1290 of file command.c.
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
int fr_command_walk | ( | fr_cmd_t * | head, |
void ** | walk_ctx, | ||
void * | ctx, | ||
fr_cmd_walk_t | callback | ||
) |
Walk over a command hierarchy.
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 |
Definition at line 1019 of file command.c.
|
static |
|
static |
|
static |
|
static |
|
static |
fr_command_register_hook_t fr_command_register_hook = fr_command_register |