]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
make callbacks take fr_cmd_info_t
authorAlan T. DeKok <aland@freeradius.org>
Mon, 2 Jul 2018 19:16:53 +0000 (15:16 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 2 Jul 2018 19:16:53 +0000 (15:16 -0400)
src/include/command.h
src/main/command.c
src/main/radmin.c
src/main/unit_test_attribute.c

index 9b1d64e467ee98cb95d91181811518bbc4112308..81db28be9767307c5e53f1b81824c18ae915c406 100644 (file)
@@ -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 {
index bb21bfc9d99dbdbc5d28ce57ac8a8e77fbbb24f5..9f064b8155e20faecc8341bc06ed6622a2c81edf 100644 (file)
@@ -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;
index a21ebcfd0324fc913079f13f97a97a18aec884c0..28345f6e25de65c315ddd06786b6f81f90a2545e 100644 (file)
@@ -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;
 }
 
index cd93e946ab589920c81ec535e54bd62a4a1839c1..7bd73dca2b808e93408a553a0d0c29330212d194 100644 (file)
@@ -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;
 }