From 9e2c045d6118ef264d6cf8fc655b72d7c4c403dc Mon Sep 17 00:00:00 2001 From: Angelo Mantellini Date: Tue, 9 Jun 2020 14:48:02 +0200 Subject: [HICN-626] Return output from libhicnlight Signed-off-by: Angelo Mantellini Change-Id: I2351ce4dcefa1311fa09049f87e8317c8fe449f4 --- hicn-light/src/hicn/config/controlRoot.c | 78 ++++++++++++++++++++------------ 1 file changed, 50 insertions(+), 28 deletions(-) (limited to 'hicn-light/src/hicn/config/controlRoot.c') diff --git a/hicn-light/src/hicn/config/controlRoot.c b/hicn-light/src/hicn/config/controlRoot.c index 8c8cc1804..39a1fa6b5 100644 --- a/hicn-light/src/hicn/config/controlRoot.c +++ b/hicn-light/src/hicn/config/controlRoot.c @@ -37,9 +37,15 @@ static void _controlRoot_Init(CommandParser *parser, CommandOps *ops); static CommandReturn _controlRoot_Execute(CommandParser *parser, - CommandOps *ops, PARCList *args); + CommandOps *ops, + PARCList *args, + char *output, + size_t output_size); static CommandReturn _controlRoot_HelpExecute(CommandParser *parser, - CommandOps *ops, PARCList *args); + CommandOps *ops, + PARCList *args, + char *output, + size_t output_size); static const char *_commandRoot = ""; static const char *_commandRootHelp = "help"; @@ -59,20 +65,21 @@ CommandOps *controlRoot_HelpCreate(ControlState *state) { // =================================================== static CommandReturn _controlRoot_HelpExecute(CommandParser *parser, - CommandOps *ops, PARCList *args) { - printf("Command-line execution:\n"); - printf( - " controller [--server ] [--port ] " - "command\n"); - printf("\n"); - printf("Interactive execution:\n"); - printf(" controller [--server ] [--port ]\n"); - printf("\n"); - printf( - "If the keystore is not specified, the default path is used. Keystore " - "must exist prior to running program.\n"); - printf("If the password is not specified, the user will be prompted.\n"); - printf("\n"); + CommandOps *ops, + PARCList *args, + char *output, + size_t output_size) { + size_t output_offset = snprintf(output, output_size, "Command-line execution:\n" + " controller [--server ] [--port ] " + "command\n" + "\n" + "Interactive execution:\n" + " controller [--server ] [--port ]\n" + "\n" + "If the keystore is not specified, the default path is used. Keystore " + "must exist prior to running program.\n" + "If the password is not specified, the user will be prompted.\n" + "\n"); CommandOps *ops_help_add = controlAdd_CreateHelp(NULL); CommandOps *ops_help_list = controlList_HelpCreate(NULL); @@ -86,19 +93,31 @@ static CommandReturn _controlRoot_HelpExecute(CommandParser *parser, CommandOps *ops_help_update = controlUpdate_HelpCreate(NULL); #endif /* WITH_POLICY */ - printf("Available commands:\n"); - printf(" %s\n", ops_help_add->command); - printf(" %s\n", ops_help_list->command); - printf(" %s\n", ops_help_quit->command); - printf(" %s\n", ops_help_remove->command); - printf(" %s\n", ops_help_set->command); - printf(" %s\n", ops_help_unset->command); - printf(" %s\n", ops_help_cache->command); - printf(" %s\n", ops_help_mapme->command); + snprintf(output + output_offset, output_size - output_offset,"Available commands:\n" + " %s\n" + " %s\n" + " %s\n" + " %s\n" + " %s\n" + " %s\n" + " %s\n" + " %s\n" #ifdef WITH_POLICY - printf(" %s\n", ops_help_update->command); + " %s\n" #endif /* WITH_POLICY */ - printf("\n"); + "\n", + ops_help_add->command, + ops_help_list->command, + ops_help_quit->command, + ops_help_remove->command, + ops_help_set->command, + ops_help_unset->command, + ops_help_cache->command, + ops_help_mapme->command +#ifdef WITH_POLICY + , ops_help_update->command +#endif /* WITH_POLICY */ + ); commandOps_Destroy(&ops_help_add); commandOps_Destroy(&ops_help_list); @@ -144,7 +163,10 @@ static void _controlRoot_Init(CommandParser *parser, CommandOps *ops) { } static CommandReturn _controlRoot_Execute(CommandParser *parser, - CommandOps *ops, PARCList *args) { + CommandOps *ops, + PARCList *args, + char *output, + size_t output_size) { return CommandReturn_Success; } -- cgit 1.2.3-korg