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/controlAddRoute.c | 50 ++++++++++++++++------------ 1 file changed, 28 insertions(+), 22 deletions(-) (limited to 'hicn-light/src/hicn/config/controlAddRoute.c') diff --git a/hicn-light/src/hicn/config/controlAddRoute.c b/hicn-light/src/hicn/config/controlAddRoute.c index 8a1adf6d6..78c0173ea 100644 --- a/hicn-light/src/hicn/config/controlAddRoute.c +++ b/hicn-light/src/hicn/config/controlAddRoute.c @@ -32,10 +32,14 @@ #include static CommandReturn _controlAddRoute_Execute(CommandParser *parser, - CommandOps *ops, PARCList *args); + CommandOps *ops, PARCList *args, + char *output, + size_t output_size); static CommandReturn _controlAddRoute_HelpExecute(CommandParser *parser, CommandOps *ops, - PARCList *args); + PARCList *args, + char *output, + size_t output_size); static const char *_commandAddRoute = "add route"; static const char *_commandAddRouteHelp = "help add route"; @@ -54,26 +58,29 @@ CommandOps *controlAddRoute_HelpCreate(ControlState *state) { static CommandReturn _controlAddRoute_HelpExecute(CommandParser *parser, CommandOps *ops, - PARCList *args) { - printf("commands:\n"); - printf(" add route \n"); - printf("\n"); - printf(" symbolic: The symbolic name for an exgress\n"); - printf( - " connid: The egress connection id (see 'help list connections')\n"); - printf( - " prefix: The hicn name as IPv4 or IPv6 address (e.g 1234::0/64)\n"); - printf(" cost: positive integer representing cost\n"); - printf("\n"); + PARCList *args, + char *output, + size_t output_size) { + snprintf(output, output_size, "commands:\n" + " add route \n" + "\n" + " symbolic: The symbolic name for an exgress\n" + " connid: The egress connection id (see 'help list connections')\n" + " prefix: The hicn name as IPv4 or IPv6 address (e.g 1234::0/64)\n" + " cost: positive integer representing cost\n" + "\n"); return CommandReturn_Success; } static CommandReturn _controlAddRoute_Execute(CommandParser *parser, - CommandOps *ops, PARCList *args) { + CommandOps *ops, + PARCList *args, + char *output, + size_t output_size) { ControlState *state = ops->closure; if (parcList_Size(args) != 5) { - _controlAddRoute_HelpExecute(parser, ops, args); + _controlAddRoute_HelpExecute(parser, ops, args, output, output_size); return CommandReturn_Failure; } @@ -81,16 +88,15 @@ static CommandReturn _controlAddRoute_Execute(CommandParser *parser, if (!utils_ValidateSymbolicName(symbolicOrConnid) && !utils_IsNumber(symbolicOrConnid)) { - printf( - "ERROR: Invalid symbolic or connid:\nsymbolic name must begin with an " - "alpha followed by alphanum;\nconnid must be an integer\n"); + snprintf(output, output_size, "ERROR: Invalid symbolic or connid:\nsymbolic name must begin with an " + "alpha followed by alphanum;\nconnid must be an integer\n"); return CommandReturn_Failure; } unsigned cost = atoi(parcList_GetAtIndex(args, 4)); if (cost == 0) { - printf("ERROR: cost must be positive integer, got %u from '%s'\n", cost, + snprintf(output, output_size, "ERROR: cost must be positive integer, got %u from '%s'\n", cost, (char *)parcList_GetAtIndex(args, 4)); return CommandReturn_Failure; } @@ -115,7 +121,7 @@ static CommandReturn _controlAddRoute_Execute(CommandParser *parser, // check and set IP address if (inet_pton(AF_INET, addr, &addRouteCommand->address.v4.as_u32) == 1) { if (len > 32) { - printf("ERROR: exceeded INET mask length, max=32\n"); + snprintf(output, output_size, "ERROR: exceeded INET mask length, max=32\n"); parcMemory_Deallocate(&addRouteCommand); free(addr); return CommandReturn_Failure; @@ -123,14 +129,14 @@ static CommandReturn _controlAddRoute_Execute(CommandParser *parser, addRouteCommand->addressType = ADDR_INET; } else if (inet_pton(AF_INET6, addr, &addRouteCommand->address.v6.as_in6addr) == 1) { if (len > 128) { - printf("ERROR: exceeded INET6 mask length, max=128\n"); + snprintf(output, output_size, "ERROR: exceeded INET6 mask length, max=128\n"); parcMemory_Deallocate(&addRouteCommand); free(addr); return CommandReturn_Failure; } addRouteCommand->addressType = ADDR_INET6; } else { - printf("Error: %s is not a valid network address \n", addr); + snprintf(output, output_size, "Error: %s is not a valid network address \n", addr); parcMemory_Deallocate(&addRouteCommand); free(addr); return CommandReturn_Failure; -- cgit 1.2.3-korg