The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
command.h
Go to the documentation of this file.
1 #pragma once
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16  */
17 
18 /**
19  * $Id: 3cdf8eb3ff240c43af3443982f1ad669233e2a1e $
20  *
21  * @file lib/server/command.h
22  * @brief Structures and prototypes command functions
23  *
24  * @copyright 2007 Alan DeKok
25  */
26 RCSIDH(command_h, "$Id: 3cdf8eb3ff240c43af3443982f1ad669233e2a1e $")
27 
28 #include <freeradius-devel/util/value.h>
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 #define CMD_MAX_ARGV (32)
35 
36 typedef struct fr_cmd_s fr_cmd_t;
37 
38 typedef struct {
39  int argc; //!< current argument count
40  int max_argc; //!< maximum number of arguments
41  bool runnable; //!< is the command runnable?
42  char const **argv; //!< text version of commands
43  fr_value_box_t **box; //!< value_box version of commands.
44  fr_cmd_t **cmd; //!< cached commands at each offset
46 
47 typedef int (*fr_cmd_func_t)(FILE *fp, FILE *fp_err, void *ctx, fr_cmd_info_t const *info);
48 
49 typedef int (*fr_cmd_tab_t)(TALLOC_CTX *talloc_ctx, void *ctx, fr_cmd_info_t *info, int max_expansions, char const **expansions);
50 
51 typedef struct {
52  char const *parent; //!< e.g. "show module"
53  char const *name; //!< e.g. "stats"
54  char const *syntax; //!< e.g. "STRING"
55  char const *help; //!< help text
56  fr_cmd_func_t func; //!< function to process this command
57  fr_cmd_tab_t tab_expand; //!< tab expand things in the syntax string
58  bool read_only;
59  bool add_name; //!< do we add a name here?
61 
62 #define CMD_TABLE_END { .help = NULL }
63 
64 typedef struct {
66  char const **parents;
67  char const *name;
68  char const *syntax;
69  char const *help;
71 
72 typedef int (*fr_cmd_walk_t)(void *ctx, fr_cmd_walk_info_t *);
73 typedef int (*fr_command_register_hook_t)(TALLOC_CTX *talloc_ctx, char const *name, void *ctx, fr_cmd_table_t *table);
75 
76 int fr_command_add(TALLOC_CTX *talloc_ctx, fr_cmd_t **head_p, char const *name, void *ctx, fr_cmd_table_t const *table);
77 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);
78 int fr_command_walk(fr_cmd_t *head, void **walk_ctx, void *ctx, fr_cmd_walk_t callback);
79 int fr_command_tab_expand(TALLOC_CTX *ctx, fr_cmd_t *head, fr_cmd_info_t *info, int max_expansions, char const **expansions);
80 char const *fr_command_help(fr_cmd_t *head, int argc, char *argv[]);
81 int fr_command_run(FILE *fp, FILE *fp_err, fr_cmd_info_t *info, bool read_only);
82 void fr_command_debug(FILE *fp, fr_cmd_t *head);
83 int fr_command_str_to_argv(fr_cmd_t *head, fr_cmd_info_t *info, char const *str);
84 int fr_command_clear(int new_argc, fr_cmd_info_t *info) CC_HINT(nonnull);
85 
86 
87 #define FR_COMMAND_OPTION_NONE (0)
88 #define FR_COMMAND_OPTION_LIST_CHILD (1 << 0)
89 #define FR_COMMAND_OPTION_NAME (1 << 1)
90 #define FR_COMMAND_OPTION_HELP (1 << 2)
91 
92 void fr_command_list(FILE *fp, int max_depth, fr_cmd_t *head, int options);
93 void fr_command_info_init(TALLOC_CTX *ctx, fr_cmd_info_t *info);
94 
95 int fr_command_complete(fr_cmd_t *head, char const *text, int start,
96  int max_expansions, char const **expansions);
97 int fr_command_print_help(FILE *fp, fr_cmd_t *head, char const *text);
98 bool fr_command_strncmp(const char *text, const char *name) CC_HINT(nonnull);
99 
100 #ifdef __cplusplus
101 }
102 #endif
#define RCSIDH(h, id)
Definition: build.h:445
int(* fr_cmd_walk_t)(void *ctx, fr_cmd_walk_info_t *)
Definition: command.h:72
int fr_command_clear(int new_argc, fr_cmd_info_t *info)
Clear out any value boxes etc.
Definition: command.c:2369
void fr_command_list(FILE *fp, int max_depth, fr_cmd_t *head, int options)
Definition: command.c:1649
char const ** parents
Definition: command.h:66
int fr_command_walk(fr_cmd_t *head, void **walk_ctx, void *ctx, fr_cmd_walk_t callback)
Walk over a command hierarchy.
Definition: command.c:1019
bool add_name
do we add a name here?
Definition: command.h:59
int fr_command_run(FILE *fp, FILE *fp_err, fr_cmd_info_t *info, bool read_only)
Run a particular command.
Definition: command.c:1473
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.
Definition: command.c:985
char const * help
help text
Definition: command.h:55
int argc
current argument count
Definition: command.h:39
void fr_command_info_init(TALLOC_CTX *ctx, fr_cmd_info_t *info)
Initialize an fr_cmd_info_t structure.
Definition: command.c:2397
int(* fr_cmd_func_t)(FILE *fp, FILE *fp_err, void *ctx, fr_cmd_info_t const *info)
Definition: command.h:47
bool fr_command_strncmp(const char *text, const char *name)
Definition: command.c:2906
fr_cmd_func_t func
function to process this command
Definition: command.h:56
char const * syntax
Definition: command.h:68
char const * syntax
e.g. "STRING"
Definition: command.h:54
fr_value_box_t ** box
value_box version of commands.
Definition: command.h:43
bool read_only
Definition: command.h:58
char const * parent
e.g. "show module"
Definition: command.h:52
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.
Definition: command.c:725
int fr_command_print_help(FILE *fp, fr_cmd_t *head, char const *text)
Do readline-style help completions.
Definition: command.c:2802
fr_command_register_hook_t fr_command_register_hook
Definition: command.c:42
void fr_command_debug(FILE *fp, fr_cmd_t *head)
Definition: command.c:1602
int fr_command_complete(fr_cmd_t *head, char const *text, int start, int max_expansions, char const **expansions)
Do readline-style command completions.
Definition: command.c:2659
fr_cmd_tab_t tab_expand
tab expand things in the syntax string
Definition: command.h:57
bool runnable
is the command runnable?
Definition: command.h:41
int(* fr_command_register_hook_t)(TALLOC_CTX *talloc_ctx, char const *name, void *ctx, fr_cmd_table_t *table)
Definition: command.h:73
char const * fr_command_help(fr_cmd_t *head, int argc, char *argv[])
Get help text for a particular command.
Definition: command.c:1553
int max_argc
maximum number of arguments
Definition: command.h:40
char const * name
e.g. "stats"
Definition: command.h:53
char const * help
Definition: command.h:69
char const ** argv
text version of commands
Definition: command.h:42
int(* fr_cmd_tab_t)(TALLOC_CTX *talloc_ctx, void *ctx, fr_cmd_info_t *info, int max_expansions, char const **expansions)
Definition: command.h:49
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.
Definition: command.c:1290
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[].
Definition: command.c:2141
char const * name
Definition: command.h:67
fr_cmd_t ** cmd
cached commands at each offset
Definition: command.h:44
static char const * name
static fr_slen_t head
Definition: xlat.h:408
int nonnull(2, 5))