]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
radmin commands have a FILE*fp for output
authorAlan T. DeKok <aland@freeradius.org>
Wed, 27 Jun 2018 20:48:20 +0000 (16:48 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 27 Jun 2018 20:48:20 +0000 (16:48 -0400)
src/include/command.h
src/main/command.c
src/main/radiusd.c
src/main/radmin.c
src/main/unit_test_attribute.c

index d24bd7118d06db2f15bc1863547ce9c328002657..7d009cb3b5c5e61143aba8b5fa8540225133491d 100644 (file)
@@ -31,7 +31,7 @@ extern "C" {
 
 typedef struct fr_cmd_t fr_cmd_t;
 
-typedef int (*fr_cmd_func_t)(void *ctx, int argc, char const *argv[]);
+typedef int (*fr_cmd_func_t)(FILE *fp, void *ctx, int argc, char const *argv[]);
 
 typedef struct fr_cmd_tab_info_t {
        int             argc;
@@ -66,8 +66,8 @@ int fr_command_add_multi(TALLOC_CTX *talloc_ctx, fr_cmd_t **heap_p, char const *
 int fr_command_walk(fr_cmd_t *head, void **walk_ctx, void *ctx, fr_cmd_walk_t callback);
 int fr_command_tab_expand(TALLOC_CTX *ctx, fr_cmd_t *head, int argc, char const *argv[], int max_expansions, char const **expansions);
 char const *fr_command_help(fr_cmd_t *head, int argc, char const *argv[]);
-int fr_command_run(fr_cmd_t *head, int argc, char const *argv[]);
-void fr_command_debug(fr_cmd_t *head, FILE *fp);
+int fr_command_run(FILE *fp, fr_cmd_t *head, int argc, char const *argv[]);
+void fr_command_debug(FILE *fp, fr_cmd_t *head);
 
 #ifdef __cplusplus
 }
index 044339dae42d847b30ce79daa47a24542e27003b..ded371097f16a24bda484357328b404426016fac 100644 (file)
@@ -844,14 +844,15 @@ int fr_command_tab_expand(TALLOC_CTX *ctx, fr_cmd_t *head, int argc, char const
 
 /** Run a particular command
  *
- * @param head the head of the hierarchy.
+ * @param fp   where the output is sent
+ * @param head the head of the command hierarchy.
  * @param argc the number of arguments in the argv array
  * @param argv the commands leading up to this one.
  * @return
  *     - <0 on error
  *     - 0 the command was run successfully
  */
-int fr_command_run(fr_cmd_t *head, int argc, char const *argv[])
+int fr_command_run(FILE *fp, fr_cmd_t *head, int argc, char const *argv[])
 {
        int i;
        fr_cmd_t *cmd, *start;
@@ -874,7 +875,7 @@ int fr_command_run(fr_cmd_t *head, int argc, char const *argv[])
                if (!cmd->syntax) {
                        if (cmd->func) {
                                rad_assert(cmd->func != NULL);
-                               return cmd->func(cmd->ctx, argc - i, &argv[i]);
+                               return cmd->func(fp, cmd->ctx, argc - i, &argv[i]);
                        }
 
                        rad_assert(cmd->child != NULL);
@@ -924,7 +925,7 @@ int fr_command_run(fr_cmd_t *head, int argc, char const *argv[])
                        fr_value_box_clear(&box);
                }
 
-               return cmd->func(cmd->ctx, argc - i, &argv[i]);
+               return cmd->func(fp, cmd->ctx, argc - i, &argv[i]);
        }
 
        return 0;
@@ -969,26 +970,26 @@ char const *fr_command_help(fr_cmd_t *head, int argc, char const *argv[])
 
 static const char *tabs = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
 
-static void fr_command_debug_node(fr_cmd_t *cmd, FILE *fp, int depth)
+static void fr_command_debug_node(FILE *fp, fr_cmd_t *cmd, int depth)
 {
        fprintf(fp, "%.*s%s\n", depth, tabs, cmd->name);
        if (cmd->syntax) fprintf(fp, "%.*s  -> %s\n", depth, tabs, cmd->syntax);
        if (cmd->help) fprintf(fp,   "%.*s   ? %s\n", depth, tabs, cmd->help);
 }
 
-static void fr_command_debug_internal(fr_cmd_t *head, FILE *fp, int depth)
+static void fr_command_debug_internal(FILE *fp, fr_cmd_t *head, int depth)
 {
        fr_cmd_t *cmd;
 
        for (cmd = head; cmd != NULL; cmd = cmd->next) {
-               fr_command_debug_node(cmd, fp, depth);
+               fr_command_debug_node(fp, cmd, depth);
                if (cmd->child) {
-                       fr_command_debug_internal(cmd->child, fp, depth + 1);
+                       fr_command_debug_internal(fp, cmd->child, depth + 1);
                }
        }
 }
 
-void fr_command_debug(fr_cmd_t *head, FILE *fp)
+void fr_command_debug(FILE *fp, fr_cmd_t *head)
 {
-       fr_command_debug_internal(head, fp, 0);
+       fr_command_debug_internal(fp, head, 0);
 }
index 83b03fcced99ea91963e0f53d7ce465628c09653..16bf108a6c3b465641cbcaa47e079b34f2249ca3 100644 (file)
@@ -128,17 +128,16 @@ static int talloc_config_set(main_config_t *config)
  */
 static struct timeval start_time;
 
-static int fr_uptime(UNUSED void *ctx, UNUSED int argc, UNUSED char const *argv[])
+static int fr_uptime(FILE *fp, UNUSED void *ctx, UNUSED int argc, UNUSED char const *argv[])
 {
        struct timeval now;
 
        gettimeofday(&now, NULL);
        fr_timeval_subtract(&now, &now, &start_time);
 
-
-       printf("Uptime: %u.%06u seconds\n",
-              (int) now.tv_sec,
-              (int) now.tv_usec);
+       fprintf(fp, "Uptime: %u.%06u seconds\n",
+               (int) now.tv_sec,
+               (int) now.tv_usec);
 
        return 0;
 }
index 0a9c9fc77a08fe28bf3d3f72fd5d92895c53db6d..251eb4caa3507bc736cc9792ff5f9fc8a2c96155 100644 (file)
@@ -158,7 +158,7 @@ static void *fr_radmin(UNUSED void *ctx)
                }
 
                if (strcmp(line, "help") == 0) {
-                       fr_command_debug(radmin_cmd, stdout);
+                       fr_command_debug(stdout, radmin_cmd);
                        continue;
                }
 
@@ -166,7 +166,7 @@ static void *fr_radmin(UNUSED void *ctx)
 
                argc = fr_dict_str_to_argv(line, argv, MAX_ARGV);
 
-               if (fr_command_run(radmin_cmd, argc, const_argv) < 0) {
+               if (fr_command_run(stdout, radmin_cmd, argc, const_argv) < 0) {
                        fprintf(stderr, "Failing running command: %s\n", fr_strerror());
                }
 
index a5e08b414952d1088dfb9443a90702edb1c3c68c..5358375f4871c3b4ded2658131071023084c098e 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 void *ctx, UNUSED int argc, UNUSED char const *argv[])
+static int command_func(UNUSED FILE *fp, UNUSED void *ctx, UNUSED int argc, UNUSED char const *argv[])
 {
        return 0;
 }
@@ -692,7 +692,7 @@ static void command_print(void)
        void *walk_ctx = NULL;
 
        printf("Command hierarchy --------\n");
-       fr_command_debug(command_head, stdout);
+       fr_command_debug(stdout, command_head);
 
        printf("Command list --------\n");
        while (fr_command_walk(command_head, &walk_ctx, NULL, command_walk) == 1) {