From: Alan T. DeKok Date: Mon, 2 Jul 2018 19:16:53 +0000 (-0400) Subject: make callbacks take fr_cmd_info_t X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=00962a97cb8b580a1416ebe720e618551df7e0fa;p=thirdparty%2Ffreeradius-server.git make callbacks take fr_cmd_info_t --- diff --git a/src/include/command.h b/src/include/command.h index 9b1d64e467e..81db28be976 100644 --- a/src/include/command.h +++ b/src/include/command.h @@ -33,8 +33,6 @@ extern "C" { typedef struct fr_cmd_t fr_cmd_t; -typedef int (*fr_cmd_func_t)(FILE *fp, void *ctx, int argc, char *argv[]); - typedef struct fr_cmd_info_t { int argc; //!< current argument count int max_argc; //!< maximum number of arguments @@ -43,6 +41,8 @@ typedef struct fr_cmd_info_t { fr_value_box_t **box; //!< value_box version of commands. } fr_cmd_info_t; +typedef int (*fr_cmd_func_t)(FILE *fp, void *ctx, fr_cmd_info_t const *info); + typedef int (*fr_cmd_tab_t)(TALLOC_CTX *talloc_ctx, void *ctx, fr_cmd_info_t *info, int max_expansions, char const **expansions); typedef struct fr_cmd_table_t { diff --git a/src/main/command.c b/src/main/command.c index bb21bfc9d99..9f064b8155e 100644 --- a/src/main/command.c +++ b/src/main/command.c @@ -856,6 +856,7 @@ int fr_command_run(FILE *fp, fr_cmd_t *head, fr_cmd_info_t *info) for (i = 0; i < info->argc; i++) { int rcode; + fr_cmd_info_t my_info; cmd = fr_command_find(&start, info->argv[i], NULL); if (!cmd) { @@ -899,7 +900,12 @@ int fr_command_run(FILE *fp, fr_cmd_t *head, fr_cmd_info_t *info) * fr_command_str_to_argv(). */ run: - rcode = cmd->func(fp, cmd->ctx, info->argc - i - 1, &info->argv[i + 1]); + my_info.argc = info->argc - i - 1; + my_info.max_argc = info->max_argc - info->argc; + my_info.runnable = true; + my_info.argv = &info->argv[i + 1]; + my_info.box = &info->box[i + 1]; + rcode = cmd->func(fp, cmd->ctx, &my_info); // @todo - clean up value boxes, too! info->argc = 0; diff --git a/src/main/radmin.c b/src/main/radmin.c index a21ebcfd032..28345f6e25d 100644 --- a/src/main/radmin.c +++ b/src/main/radmin.c @@ -129,7 +129,7 @@ static fr_cmd_t *radmin_cmd = NULL; #define CMD_MAX_ARGV (32) -static int cmd_help(FILE *fp, UNUSED void *ctx, int argc, char *argv[]); +static int cmd_help(FILE *fp, UNUSED void *ctx, fr_cmd_info_t const *info); static void *fr_radmin(UNUSED void *input_ctx) { @@ -183,7 +183,7 @@ static void *fr_radmin(UNUSED void *input_ctx) * It's just polite. */ if (strcmp(line, "help") == 0) { - cmd_help(stdout, NULL, context, info.argv); + cmd_help(stdout, NULL, &info); goto next; } @@ -311,7 +311,7 @@ static void *fr_radmin(UNUSED void *input_ctx) */ static struct timeval start_time; -static int cmd_exit(UNUSED FILE *fp, UNUSED void *ctx, UNUSED int argc, UNUSED char *argv[]) +static int cmd_exit(UNUSED FILE *fp, UNUSED void *ctx, UNUSED fr_cmd_info_t const *info) { radius_signal_self(RADIUS_SIGNAL_SELF_TERM); stop = true; @@ -319,16 +319,16 @@ static int cmd_exit(UNUSED FILE *fp, UNUSED void *ctx, UNUSED int argc, UNUSED c return 0; } -static int cmd_help(FILE *fp, UNUSED void *ctx, int argc, char *argv[]) +static int cmd_help(FILE *fp, UNUSED void *ctx, fr_cmd_info_t const *info) { char const *help; - if (argc == 0) { + if (info->argc == 0) { fr_command_debug(fp, radmin_cmd); return 0; } - help = fr_command_help(radmin_cmd, argc, argv); + help = fr_command_help(radmin_cmd, info->argc, info->argv); if (help) { fprintf(fp, "%s\n", help); return 0; @@ -337,7 +337,7 @@ static int cmd_help(FILE *fp, UNUSED void *ctx, int argc, char *argv[]) return 0; } -static int cmd_uptime(FILE *fp, UNUSED void *ctx, UNUSED int argc, UNUSED char *argv[]) +static int cmd_uptime(FILE *fp, UNUSED void *ctx, UNUSED fr_cmd_info_t const *info) { struct timeval now; @@ -351,9 +351,9 @@ static int cmd_uptime(FILE *fp, UNUSED void *ctx, UNUSED int argc, UNUSED char * return 0; } -static int cmd_test(FILE *fp, UNUSED void *ctx, UNUSED int argc, char *argv[]) +static int cmd_test(FILE *fp, UNUSED void *ctx, fr_cmd_info_t const *info) { - fprintf(fp, "woo! %s %s\n", argv[0], argv[2]); + fprintf(fp, "woo! %s %s\n", info->argv[0], info->argv[2]); return 0; } diff --git a/src/main/unit_test_attribute.c b/src/main/unit_test_attribute.c index cd93e946ab5..7bd73dca2b8 100644 --- a/src/main/unit_test_attribute.c +++ b/src/main/unit_test_attribute.c @@ -667,7 +667,7 @@ static size_t load_test_point_by_command(void **symbol, char *command, size_t of static fr_cmd_t *command_head = NULL; -static int command_func(UNUSED FILE *fp, UNUSED void *ctx, UNUSED int argc, UNUSED char *argv[]) +static int command_func(UNUSED FILE *fp, UNUSED void *ctx, UNUSED fr_cmd_info_t const *info) { return 0; }