aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--hicn-light/src/hicn/command_line/controller/hicnLightControl_main.c7
-rw-r--r--hicn-light/src/hicn/config/commandOps.c4
-rw-r--r--hicn-light/src/hicn/config/commandOps.h14
-rw-r--r--hicn-light/src/hicn/config/commandParser.c9
-rw-r--r--hicn-light/src/hicn/config/commandParser.h6
-rw-r--r--hicn-light/src/hicn/config/configurationFile.c3
-rw-r--r--hicn-light/src/hicn/config/controlAdd.c49
-rw-r--r--hicn-light/src/hicn/config/controlAddConnection.c159
-rw-r--r--hicn-light/src/hicn/config/controlAddListener.c78
-rw-r--r--hicn-light/src/hicn/config/controlAddPolicy.c56
-rw-r--r--hicn-light/src/hicn/config/controlAddPunting.c38
-rw-r--r--hicn-light/src/hicn/config/controlAddRoute.c50
-rw-r--r--hicn-light/src/hicn/config/controlCache.c31
-rw-r--r--hicn-light/src/hicn/config/controlCacheClear.c21
-rw-r--r--hicn-light/src/hicn/config/controlCacheServe.c24
-rw-r--r--hicn-light/src/hicn/config/controlCacheStore.c23
-rw-r--r--hicn-light/src/hicn/config/controlList.c42
-rw-r--r--hicn-light/src/hicn/config/controlListConnections.c53
-rw-r--r--hicn-light/src/hicn/config/controlListInterfaces.c22
-rw-r--r--hicn-light/src/hicn/config/controlListListeners.c29
-rw-r--r--hicn-light/src/hicn/config/controlListPolicies.c66
-rw-r--r--hicn-light/src/hicn/config/controlListRoutes.c51
-rw-r--r--hicn-light/src/hicn/config/controlMapMe.c33
-rw-r--r--hicn-light/src/hicn/config/controlMapMeDiscovery.c23
-rw-r--r--hicn-light/src/hicn/config/controlMapMeEnable.c23
-rw-r--r--hicn-light/src/hicn/config/controlMapMeRetx.c24
-rw-r--r--hicn-light/src/hicn/config/controlMapMeTimescale.c24
-rw-r--r--hicn-light/src/hicn/config/controlQuit.c24
-rw-r--r--hicn-light/src/hicn/config/controlRemove.c42
-rw-r--r--hicn-light/src/hicn/config/controlRemoveConnection.c26
-rw-r--r--hicn-light/src/hicn/config/controlRemoveListener.c26
-rw-r--r--hicn-light/src/hicn/config/controlRemovePolicy.c28
-rw-r--r--hicn-light/src/hicn/config/controlRemovePunting.c22
-rw-r--r--hicn-light/src/hicn/config/controlRemoveRoute.c30
-rw-r--r--hicn-light/src/hicn/config/controlRoot.c78
-rw-r--r--hicn-light/src/hicn/config/controlSet.c35
-rw-r--r--hicn-light/src/hicn/config/controlSetDebug.c24
-rw-r--r--hicn-light/src/hicn/config/controlSetStrategy.c75
-rw-r--r--hicn-light/src/hicn/config/controlSetWldr.c30
-rw-r--r--hicn-light/src/hicn/config/controlState.c23
-rw-r--r--hicn-light/src/hicn/config/controlState.h7
-rw-r--r--hicn-light/src/hicn/config/controlUnset.c26
-rw-r--r--hicn-light/src/hicn/config/controlUnsetDebug.c23
-rw-r--r--hicn-light/src/hicn/config/controlUpdate.c32
-rw-r--r--hicn-light/src/hicn/config/controlUpdateConnection.c37
45 files changed, 984 insertions, 566 deletions
diff --git a/hicn-light/src/hicn/command_line/controller/hicnLightControl_main.c b/hicn-light/src/hicn/command_line/controller/hicnLightControl_main.c
index 8f56dc60a..31b9674ca 100644
--- a/hicn-light/src/hicn/command_line/controller/hicnLightControl_main.c
+++ b/hicn-light/src/hicn/command_line/controller/hicnLightControl_main.c
@@ -340,6 +340,9 @@ int main(int argc, char *argv[]) {
mainState.controlState =
controlState_Create(&mainState, _writeAndReadMessage, true,
server_ip, server_port);
+ if (mainState.controlState == NULL) {
+ exit(EXIT_FAILURE);
+ }
controlState_RegisterCommand(mainState.controlState,
controlRoot_HelpCreate(mainState.controlState));
@@ -348,7 +351,9 @@ int main(int argc, char *argv[]) {
if (parcList_Size(commands) > 0) {
controlState_SetInteractiveFlag(mainState.controlState, false);
- controlState_DispatchCommand(mainState.controlState, commands);
+ char output[8192];
+ controlState_DispatchCommand(mainState.controlState, commands, output, sizeof(output));
+ printf("%s", output);
char **commandOutputMain =
controlState_GetCommandOutput(mainState.controlState);
if (commandOutputMain != NULL && commandOutputLen > 0) {
diff --git a/hicn-light/src/hicn/config/commandOps.c b/hicn-light/src/hicn/config/commandOps.c
index fa2dc7a7d..dd8e148d0 100644
--- a/hicn-light/src/hicn/config/commandOps.c
+++ b/hicn-light/src/hicn/config/commandOps.c
@@ -40,7 +40,9 @@ CommandOps *commandOps_Create(void *closure, const char *command,
CommandOps *ops),
CommandReturn (*execute)(CommandParser *parser,
CommandOps *ops,
- PARCList *args),
+ PARCList *args,
+ char *output,
+ size_t output_size),
void (*destroyer)(CommandOps **opsPtr)) {
parcAssertNotNull(command, "Parameter command must be non-null");
parcAssertNotNull(execute, "Parameter execute must be non-null");
diff --git a/hicn-light/src/hicn/config/commandOps.h b/hicn-light/src/hicn/config/commandOps.h
index 0d685f1b8..784b91eb8 100644
--- a/hicn-light/src/hicn/config/commandOps.h
+++ b/hicn-light/src/hicn/config/commandOps.h
@@ -82,8 +82,11 @@ struct command_ops {
void *closure;
char *command;
void (*init)(struct command_parser *parser, CommandOps *ops);
- CommandReturn (*execute)(struct command_parser *parser, CommandOps *ops,
- PARCList *args);
+ CommandReturn (*execute)(struct command_parser *parser,
+ CommandOps *ops,
+ PARCList *args,
+ char *output,
+ size_t output_size);
void (*destroyer)(CommandOps **opsPtr);
};
@@ -104,8 +107,11 @@ struct command_ops {
CommandOps *commandOps_Create(
void *closure, const char *command,
void (*init)(struct command_parser *parser, CommandOps *ops),
- CommandReturn (*execute)(struct command_parser *parser, CommandOps *ops,
- PARCList *args),
+ CommandReturn (*execute)(struct command_parser *parser,
+ CommandOps *ops,
+ PARCList *args,
+ char *output,
+ size_t output_size),
void (*destroyer)(CommandOps **opsPtr));
/**
diff --git a/hicn-light/src/hicn/config/commandParser.c b/hicn-light/src/hicn/config/commandParser.c
index fa3269c9a..f4652fe39 100644
--- a/hicn-light/src/hicn/config/commandParser.c
+++ b/hicn-light/src/hicn/config/commandParser.c
@@ -201,14 +201,17 @@ static CommandOps *commandParser_MatchCommand(CommandParser *state,
}
CommandReturn commandParser_DispatchCommand(CommandParser *state,
- PARCList *args) {
+ PARCList *args,
+ char *output,
+ size_t output_size) {
+ parcAssertNotNull(output, "output buffer is null\n");
CommandOps *ops = commandParser_MatchCommand(state, args);
if (ops == NULL) {
- printf("Command not found.\n");
+ snprintf(output, output_size, "Command not found.\n");
return CommandReturn_Failure;
} else {
- return ops->execute(state, ops, args);
+ return ops->execute(state, ops, args, output, output_size);
}
}
diff --git a/hicn-light/src/hicn/config/commandParser.h b/hicn-light/src/hicn/config/commandParser.h
index 0bd2ee7b0..882d55d26 100644
--- a/hicn-light/src/hicn/config/commandParser.h
+++ b/hicn-light/src/hicn/config/commandParser.h
@@ -131,6 +131,8 @@ void commandParser_RegisterCommand(CommandParser *state, CommandOps *command);
*
* @param [in] state The allocated ControlState
* @param [in] args Each command_line word parsed to the ordered list
+ * @param [in] output The allocated output string, if null, the normal printf is executed
+ * @param [in] output_size the size of output array string. It is ignored if the output string is null
*
* @return CommandReturn_Success the command was successful
* @return CommandReturn_Failure the command failed or was not found
@@ -143,7 +145,9 @@ void commandParser_RegisterCommand(CommandParser *state, CommandOps *command);
* @endcode
*/
CommandReturn commandParser_DispatchCommand(CommandParser *state,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
/**
* Sets the Debug mode, which will print out much more information.
diff --git a/hicn-light/src/hicn/config/configurationFile.c b/hicn-light/src/hicn/config/configurationFile.c
index 5f9c9ce9d..ebf057fa6 100644
--- a/hicn-light/src/hicn/config/configurationFile.c
+++ b/hicn-light/src/hicn/config/configurationFile.c
@@ -273,8 +273,9 @@ bool configurationFile_Process(ConfigurationFile *configFile) {
char *copy =
parcMemory_StringDuplicate(stripedBuffer, strlen(stripedBuffer));
PARCList *args = _parseArgs(copy);
+ char output[8192];
CommandReturn result =
- controlState_DispatchCommand(configFile->controlState, args);
+ controlState_DispatchCommand(configFile->controlState, args, output, sizeof(output));
// we ignore EXIT from the configuration file
if (result == CommandReturn_Failure) {
diff --git a/hicn-light/src/hicn/config/controlAdd.c b/hicn-light/src/hicn/config/controlAdd.c
index e10b56e99..cac8e7913 100644
--- a/hicn-light/src/hicn/config/controlAdd.c
+++ b/hicn-light/src/hicn/config/controlAdd.c
@@ -35,10 +35,18 @@
// ===================================================
static void _controlAdd_Init(CommandParser *parser, CommandOps *ops);
-static CommandReturn _controlAdd_Execute(CommandParser *parser, CommandOps *ops,
- PARCList *args);
+
+static CommandReturn _controlAdd_Execute(CommandParser *parser,
+ CommandOps *ops,
+ PARCList *args,
+ char *output,
+ size_t output_size);
+
static CommandReturn _controlAdd_HelpExecute(CommandParser *parser,
- CommandOps *ops, PARCList *args);
+ CommandOps *ops,
+ PARCList *args,
+ char *output,
+ size_t output_size);
// ===================================================
@@ -58,7 +66,10 @@ CommandOps *controlAdd_CreateHelp(ControlState *state) {
// ===================================================
static CommandReturn _controlAdd_HelpExecute(CommandParser *parser,
- CommandOps *ops, PARCList *args) {
+ CommandOps *ops,
+ PARCList *args,
+ char *output,
+ size_t output_size) {
CommandOps *ops_add_connection = controlAddConnection_Create(NULL);
CommandOps *ops_add_route = controlAddRoute_Create(NULL);
CommandOps *ops_add_punting = controlAddPunting_Create(NULL);
@@ -66,16 +77,21 @@ static CommandReturn _controlAdd_HelpExecute(CommandParser *parser,
#ifdef WITH_POLICY
CommandOps *ops_add_policy = controlAddPolicy_Create(NULL);
#endif /* WITH_POLICY */
-
- printf("Available commands:\n");
- printf(" %s\n", ops_add_connection->command);
- printf(" %s\n", ops_add_route->command);
- printf(" %s\n", ops_add_punting->command);
- printf(" %s\n", ops_add_listener->command);
#ifdef WITH_POLICY
- printf(" %s\n", ops_add_policy->command);
+ snprintf(output, output_size, "Available commands:\n %s\n %s\n %s\n %s\n %s\n\n",
+ ops_add_connection->command,
+ ops_add_route->command,
+ ops_add_punting->command,
+ ops_add_listener->command,
+ ops_add_policy->command);
+#else
+ snprintf(output, output_size, "Available commands:\n %s\n %s\n %s\n %s\n\n",
+ ops_add_connection->command,
+ ops_add_route->command,
+ ops_add_punting->command,
+ ops_add_listener->command);
+
#endif /* WITH_POLICY */
- printf("\n");
commandOps_Destroy(&ops_add_connection);
commandOps_Destroy(&ops_add_route);
@@ -103,7 +119,10 @@ static void _controlAdd_Init(CommandParser *parser, CommandOps *ops) {
#endif /* WITH_POLICY */
}
-static CommandReturn _controlAdd_Execute(CommandParser *parser, CommandOps *ops,
- PARCList *args) {
- return _controlAdd_HelpExecute(parser, ops, args);
+static CommandReturn _controlAdd_Execute(CommandParser *parser,
+ CommandOps *ops,
+ PARCList *args,
+ char *output,
+ size_t output_size) {
+ return _controlAdd_HelpExecute(parser, ops, args, output, output_size);
}
diff --git a/hicn-light/src/hicn/config/controlAddConnection.c b/hicn-light/src/hicn/config/controlAddConnection.c
index e5af5a251..eed37f3ad 100644
--- a/hicn-light/src/hicn/config/controlAddConnection.c
+++ b/hicn-light/src/hicn/config/controlAddConnection.c
@@ -35,34 +35,51 @@
static void _controlAddConnection_Init(CommandParser *parser, CommandOps *ops);
static CommandReturn _controlAddConnection_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static CommandReturn _controlAddConnection_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
// ===================================================
#ifdef __linux__
-static CommandReturn _controlAddConnection_HicnHelpExecute(
- CommandParser *parser, CommandOps *ops, PARCList *args);
+static CommandReturn _controlAddConnection_HicnHelpExecute(CommandParser *parser,
+ CommandOps *ops,
+ PARCList *args,
+ char *output,
+ size_t output_size);
static CommandReturn _controlAddConnection_HicnExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
#endif
static CommandReturn _controlAddConnection_UdpHelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static CommandReturn _controlAddConnection_UdpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static CommandReturn _controlAddConnection_TcpHelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static CommandReturn _controlAddConnection_TcpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
// ===================================================
@@ -140,14 +157,19 @@ static CommandOps *_controlAddConnection_TcpHelpCreate(ControlState *state) {
static CommandReturn _controlAddConnection_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
- printf("Available commands:\n");
+ PARCList *args,
+ char *output,
+ size_t output_size) {
#ifdef __linux__
- printf(" %s\n", _commandAddConnectionHicn);
+ snprintf(output, output_size, "Available commands:\n %s\n %s\n %s\n\n",
+ _commandAddConnectionHicn,
+ _commandAddConnectionUdp,
+ _commandAddConnectionTcp);
+#else
+ snprintf(output, output_size, "Available commands:\n %s\n %s\n\n",
+ _commandAddConnectionUdp,
+ _commandAddConnectionTcp);
#endif
- printf(" %s\n", _commandAddConnectionUdp);
- printf(" %s\n", _commandAddConnectionTcp);
- printf("\n");
return CommandReturn_Success;
}
@@ -170,8 +192,10 @@ static void _controlAddConnection_Init(CommandParser *parser, CommandOps *ops) {
static CommandReturn _controlAddConnection_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
- return _controlAddConnection_HelpExecute(parser, ops, args);
+ PARCList *args,
+ char *output,
+ size_t output_size) {
+ return _controlAddConnection_HelpExecute(parser, ops, args, output, output_size);
}
// ===================================================
@@ -191,6 +215,8 @@ static CommandReturn _controlAddConnection_Execute(CommandParser *parser,
* @param [in] remoteAddress The remote IP and port (both must be specified)
* @param [in] tunnelType The tunneling protocol
* @param [in] symbolic The symbolic name for the connection (must be unique)
+ * @param [in] output Output buffer
+ * @param [in] output_size Output buffer size
*
* @return <#value#> <#explanation#>
*
@@ -215,10 +241,15 @@ static CommandReturn _controlAddConnection_Execute(CommandParser *parser,
* @endcode
*/
-static CommandReturn _controlAddConnection_CreateTunnel(
- CommandParser *parser, CommandOps *ops, const char *local_ip,
- const char *local_port, const char *remote_ip, const char *remote_port,
- connection_type tunnelType, const char *symbolic) {
+static CommandReturn _controlAddConnection_CreateTunnel(CommandParser *parser,
+ CommandOps *ops, const char *local_ip,
+ const char *local_port,
+ const char *remote_ip,
+ const char *remote_port,
+ connection_type tunnelType,
+ const char *symbolic,
+ char *output,
+ size_t output_size) {
ControlState *state = ops->closure;
// a request like this always has an interface index of 0 [FIELD REMOVED]
// unsigned int interfaceIndex = 0;
@@ -240,7 +271,7 @@ static CommandReturn _controlAddConnection_CreateTunnel(
addConnectionCommand->ipType = ADDR_INET6;
} else {
- printf("Error: local address %s not same type as remote address %s\n",
+ snprintf(output, output_size, "Error: local address %s not same type as remote address %s\n",
local_ip, remote_ip);
parcMemory_Deallocate(&addConnectionCommand);
return CommandReturn_Failure;
@@ -268,47 +299,51 @@ static CommandReturn _controlAddConnection_CreateTunnel(
static CommandReturn _controlAddConnection_IpHelp(CommandParser *parser,
CommandOps *ops,
PARCList *args,
- const char *protocol) {
-#ifdef __linux__
- printf("add connection hicn <symbolic> <remote_ip> <local_ip>\n");
-#endif
- printf(
- "add connection udp <symbolic> <remote_ip> <port> <local_ip> <port>\n");
- printf(
- " <symbolic> : symbolic name, e.g. 'conn1' (must be "
- "unique, start with alpha)\n");
- printf(
- " <remote_ip> : the IPv4 or IPv6 or hostname of the remote system\n");
- printf(" <local_ip> : optional local IP address to bind to\n");
- printf("\n");
+ const char *protocol,
+ char *output,
+ size_t output_size) {
+ snprintf(output, output_size,
+ #ifdef __linux__
+ "add connection hicn <symbolic> <remote_ip> <local_ip>\n"
+ #endif
+ "add connection udp <symbolic> <remote_ip> <port> <local_ip> <port>\n"
+ " <symbolic> : symbolic name, e.g. 'conn1' (must be "
+ "unique, start with alpha)\n"
+ " <remote_ip> : the IPv4 or IPv6 or hostname of the remote system\n"
+ " <local_ip> : optional local IP address to bind to\n"
+ "\n");
return CommandReturn_Success;
}
#ifdef __linux__
-static CommandReturn _controlAddConnection_HicnHelpExecute(
- CommandParser *parser, CommandOps *ops, PARCList *args) {
- _controlAddConnection_IpHelp(parser, ops, args, "hicn");
+static CommandReturn _controlAddConnection_HicnHelpExecute(CommandParser *parser,
+ CommandOps *ops,
+ PARCList *args,
+ char *output,
+ size_t output_size) {
+ _controlAddConnection_IpHelp(parser, ops, args, "hicn", output, output_size);
return CommandReturn_Success;
}
static CommandReturn _controlAddConnection_HicnExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
+ PARCList *args,
+ char *output,
+ size_t output_size) {
static const int _indexSymbolic = 3;
static const int _indexRemAddr = 4;
static const int _indexLocAddr = 5;
if (parcList_Size(args) != 6) {
- _controlAddConnection_HicnHelpExecute(parser, ops, args);
+ _controlAddConnection_HicnHelpExecute(parser, ops, args, output, output_size);
return CommandReturn_Failure;
}
char *symbolic = parcList_GetAtIndex(args, _indexSymbolic);
if (!utils_ValidateSymbolicName(symbolic)) {
- printf(
- "Invalid symbolic name. Must begin with alpha and contain only "
+ snprintf(output, output_size, "Invalid symbolic name. Must begin with alpha and contain only "
"alphanum.\n");
return CommandReturn_Failure;
}
@@ -318,21 +353,25 @@ static CommandReturn _controlAddConnection_HicnExecute(CommandParser *parser,
char *port = "1234"; // this is a random port number that will be ignored
return _controlAddConnection_CreateTunnel(
- parser, ops, local_ip, port, remote_ip, port, HICN_CONN, symbolic);
+ parser, ops, local_ip, port, remote_ip, port, HICN_CONN, symbolic, output, output_size);
}
#endif
static CommandReturn _controlAddConnection_UdpHelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
- _controlAddConnection_IpHelp(parser, ops, args, "udp");
+ PARCList *args,
+ char *output,
+ size_t output_size) {
+ _controlAddConnection_IpHelp(parser, ops, args, "udp", output, output_size);
return CommandReturn_Success;
}
static CommandReturn _controlAddConnection_UdpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
+ PARCList *args,
+ char *output,
+ size_t output_size) {
static const int _indexSymbolic = 3;
static const int _indexRemAddr = 4;
static const int _indexRemPort = 5;
@@ -340,14 +379,14 @@ static CommandReturn _controlAddConnection_UdpExecute(CommandParser *parser,
static const int _indexLocPort = 7;
if (parcList_Size(args) != 8) {
- _controlAddConnection_UdpHelpExecute(parser, ops, args);
+ _controlAddConnection_UdpHelpExecute(parser, ops, args, output, output_size);
return CommandReturn_Failure;
}
char *symbolic = parcList_GetAtIndex(args, _indexSymbolic);
-
+ size_t offset = 0;
if (!utils_ValidateSymbolicName(symbolic)) {
- printf(
+ snprintf(output, output_size,
"Invalid symbolic name. Must begin with alpha and contain only "
"alphanum.\n");
return CommandReturn_Failure;
@@ -361,20 +400,25 @@ static CommandReturn _controlAddConnection_UdpExecute(CommandParser *parser,
return _controlAddConnection_CreateTunnel(parser, ops, local_ip, local_port,
remote_ip, remote_port, UDP_CONN,
- symbolic);
+ symbolic,
+ output + offset, output_size - offset);
}
static CommandReturn _controlAddConnection_TcpHelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
- _controlAddConnection_IpHelp(parser, ops, args, "tcp");
+ PARCList *args,
+ char *output,
+ size_t output_size) {
+ _controlAddConnection_IpHelp(parser, ops, args, "tcp", output, output_size);
return CommandReturn_Success;
}
static CommandReturn _controlAddConnection_TcpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
+ PARCList *args,
+ char *output,
+ size_t output_size) {
static const int _indexSymbolic = 3;
static const int _indexRemAddr = 4;
static const int _indexRemPort = 5;
@@ -382,15 +426,13 @@ static CommandReturn _controlAddConnection_TcpExecute(CommandParser *parser,
static const int _indexLocPort = 7;
if (parcList_Size(args) != 8) {
- _controlAddConnection_UdpHelpExecute(parser, ops, args);
+ _controlAddConnection_UdpHelpExecute(parser, ops, args, output, output_size);
return CommandReturn_Failure;
}
char *symbolic = parcList_GetAtIndex(args, _indexSymbolic);
-
if (!utils_ValidateSymbolicName(symbolic)) {
- printf(
- "Invalid symbolic name. Must begin with alpha and contain only "
+ snprintf(output, output_size, "Invalid symbolic name. Must begin with alpha and contain only "
"alphanum.\n");
return CommandReturn_Failure;
}
@@ -403,5 +445,6 @@ static CommandReturn _controlAddConnection_TcpExecute(CommandParser *parser,
return _controlAddConnection_CreateTunnel(parser, ops, local_ip, local_port,
remote_ip, remote_port, TCP_CONN,
- symbolic);
+ symbolic,
+ output, output_size);
}
diff --git a/hicn-light/src/hicn/config/controlAddListener.c b/hicn-light/src/hicn/config/controlAddListener.c
index 2f0fd3f67..df84c4691 100644
--- a/hicn-light/src/hicn/config/controlAddListener.c
+++ b/hicn-light/src/hicn/config/controlAddListener.c
@@ -34,10 +34,14 @@
static CommandReturn _controlAddListener_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static CommandReturn _controlAddListener_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static const char *command_add_listener = "add listener";
static const char *command_help_add_listener = "help add listener";
@@ -62,43 +66,45 @@ static const int _indexInterfaceName = 6;
static CommandReturn _controlAddListener_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
- printf("commands:\n");
+ PARCList *args,
+ char *output,
+ size_t output_size) {
+ snprintf(output, output_size,
+ "commands:\n"
#ifdef __linux__
- printf(" add listener hicn <symbolic> <localAddress> \n");
+ " add listener hicn <symbolic> <localAddress> \n"
#endif
- printf(" add listener udp <symbolic> <localAddress> <port> <interface>\n");
- printf(" add listener tcp <symbolic> <localAddress> <port> <interface>\n");
- printf("\n");
- printf(
- " symbolic: User defined name for listener, must start with "
- "alpha and be alphanum\n");
+ " add listener udp <symbolic> <localAddress> <port> <interface>\n"
+ " add listener tcp <symbolic> <localAddress> <port> <interface>\n"
+ "\n"
+ " symbolic: User defined name for listener, must start with "
+ "alpha and be alphanum\n"
#ifdef __linux__
- printf(" protocol: hicn | udp\n");
+ " protocol: hicn | udp\n"
#else
- printf(" protocol: udp\n");
+ " protocol: udp\n"
#endif
- printf(
- " localAddress: IPv4 or IPv6 address (or prefix protocol = hicn) "
- "assigend to the local interface\n");
- printf(" port: Udp port\n");
-
- printf(" interface: interface\n");
- printf("\n");
- printf("Notes:\n");
- printf(" The symblic name must be unique or the source will reject it.\n");
+ " localAddress: IPv4 or IPv6 address (or prefix protocol = hicn) "
+ "assigend to the local interface\n"
+ " port: Udp port\n"
+ " interface: interface\n"
+ "\n"
+ "Notes:\n"
+ " The symblic name must be unique or the source will reject it.\n"
#ifdef __linux__
- printf(
- " If protocol = hicn: the address 0::0 indicates the main listern, "
- "for which we can set punting rules.\n");
+ " If protocol = hicn: the address 0::0 indicates the main listern, "
+ "for which we can set punting rules.\n"
#endif
+ );
return CommandReturn_Success;
}
static CommandReturn _CreateListener(CommandParser *parser, CommandOps *ops,
const char *symbolic, const char *addr,
const char *port, char *interfaceName, listener_mode mode,
- connection_type type) {
+ connection_type type,
+ char *output,
+ size_t output_size) {
ControlState *state = ops->closure;
// allocate command payload
@@ -113,7 +119,7 @@ static CommandReturn _CreateListener(CommandParser *parser, CommandOps *ops,
addListenerCommand->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(&addListenerCommand);
return CommandReturn_Failure;
}
@@ -145,9 +151,11 @@ static CommandReturn _CreateListener(CommandParser *parser, CommandOps *ops,
static CommandReturn _controlAddListener_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
+ PARCList *args,
+ char *output,
+ size_t output_size) {
if (parcList_Size(args) != 5 && parcList_Size(args) != 7) {
- _controlAddListener_HelpExecute(parser, ops, args);
+ _controlAddListener_HelpExecute(parser, ops, args, output, output_size);
return CommandReturn_Failure;
}
@@ -156,7 +164,7 @@ static CommandReturn _controlAddListener_Execute(CommandParser *parser,
const char *symbolic = parcList_GetAtIndex(args, _indexSymbolic);
if (!utils_ValidateSymbolicName(symbolic)) {
- printf(
+ snprintf(output, output_size,
"Error: symbolic name must begin with an alpha and be alphanum "
"after\n");
return result;
@@ -172,22 +180,22 @@ static CommandReturn _controlAddListener_Execute(CommandParser *parser,
// here we discard the prefix len if it exists, since we don't use it in
// code but we let libhicn to find the right ip address.
return _CreateListener(parser, ops, symbolic, host, port, "hicn", HICN_MODE,
- HICN_CONN);
+ HICN_CONN, output, output_size);
}
const char *port = parcList_GetAtIndex(args, _indexPort);
if ((strcasecmp("udp", protocol) == 0)) {
return _CreateListener(parser, ops, symbolic, host, port, interfaceName, IP_MODE,
- UDP_CONN);
+ UDP_CONN, output, output_size);
} else if ((strcasecmp("tcp", protocol) == 0)) {
return _CreateListener(parser, ops, symbolic, host, port, interfaceName, IP_MODE,
- TCP_CONN);
+ TCP_CONN, output, output_size);
} else {
- _controlAddListener_HelpExecute(parser, ops, args);
+ _controlAddListener_HelpExecute(parser, ops, args, output, output_size);
return CommandReturn_Failure;
}
- if (result == CommandReturn_Failure) printf("creation failed\n");
+ if (result == CommandReturn_Failure) snprintf(output, output_size, "creation failed\n");
return result;
}
diff --git a/hicn-light/src/hicn/config/controlAddPolicy.c b/hicn-light/src/hicn/config/controlAddPolicy.c
index 29120446b..8618c6246 100644
--- a/hicn-light/src/hicn/config/controlAddPolicy.c
+++ b/hicn-light/src/hicn/config/controlAddPolicy.c
@@ -35,10 +35,14 @@
#include <hicn/utils/token.h>
static CommandReturn _controlAddPolicy_Execute(CommandParser *parser,
- CommandOps *ops, PARCList *args);
+ CommandOps *ops, PARCList *args,
+ char *output,
+ size_t output_size);
static CommandReturn _controlAddPolicy_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static const char *_commandAddPolicy = "add policy";
static const char *_commandAddPolicyHelp = "help add policy";
@@ -57,32 +61,36 @@ CommandOps *controlAddPolicy_HelpCreate(ControlState *state) {
static CommandReturn _controlAddPolicy_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
- printf("commands:\n");
- printf(" add policy <prefix> <app_name>"
- #define _(x, y) " FLAG:%s"
- foreach_policy_tag
- #undef _
- "%s",
- #define _(x, y) policy_tag_str[POLICY_TAG_ ## x],
- foreach_policy_tag
- #undef _
- "\n");
- printf("\n");
- printf(
- " prefix: The hicn name as IPv4 or IPv6 address (e.g 1234::0/64)\n");
- printf(" app_name: The application name associated to this policy\n");
- printf(" FLAG:*: A value among [neutral|require|prefer|avoid|prohibit] with an optional '!' character prefix for disabling changes\n");
+ PARCList *args,
+ char *output,
+ size_t output_size) {
+ size_t output_offset = snprintf(output, output_size, "commands:\n"
+ " add policy <prefix> <app_name>");
+
+ #define _(x, y) output_offset += snprintf(output + output_offset, output_size - output_offset, " FLAG:%s", policy_tag_str[POLICY_TAG_ ## x]);
+ foreach_policy_tag
+ #undef _
+
+ output_offset += snprintf(output + output_offset, output_size - output_offset,"\n");
printf("\n");
+ output_offset += snprintf(output + output_offset, output_size - output_offset,
+ " prefix: The hicn name as IPv4 or IPv6 address (e.g 1234::0/64)\n"
+ " app_name: The application name associated to this policy\n"
+ " FLAG:*: A value among [neutral|require|prefer|avoid|prohibit] with an optional '!' character prefix for disabling changes\n"
+ "\n");
+
return CommandReturn_Success;
}
static CommandReturn _controlAddPolicy_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) != 11) {
- _controlAddPolicy_HelpExecute(parser, ops, args);
+ _controlAddPolicy_HelpExecute(parser, ops, args, output, output_size);
return CommandReturn_Failure;
}
@@ -106,7 +114,7 @@ static CommandReturn _controlAddPolicy_Execute(CommandParser *parser,
// check and set IP address
if (inet_pton(AF_INET, addr, &addPolicyCommand->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(&addPolicyCommand);
free(addr);
return CommandReturn_Failure;
@@ -114,14 +122,14 @@ static CommandReturn _controlAddPolicy_Execute(CommandParser *parser,
addPolicyCommand->addressType = ADDR_INET;
} else if (inet_pton(AF_INET6, addr, &addPolicyCommand->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(&addPolicyCommand);
free(addr);
return CommandReturn_Failure;
}
addPolicyCommand->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(&addPolicyCommand);
free(addr);
return CommandReturn_Failure;
@@ -148,7 +156,7 @@ static CommandReturn _controlAddPolicy_Execute(CommandParser *parser,
} else if (strcmp(&tag[tag_state.disabled], "prohibit") == 0) {
tag_state.state = POLICY_STATE_PROHIBIT;
} else {
- printf("ERROR: invalid tag value '%s'\n", tag);
+ snprintf(output, output_size, "ERROR: invalid tag value '%s'\n", tag);
parcMemory_Deallocate(&addPolicyCommand);
free(addr);
return CommandReturn_Failure;
diff --git a/hicn-light/src/hicn/config/controlAddPunting.c b/hicn-light/src/hicn/config/controlAddPunting.c
index e3fb57c6b..41d846d55 100644
--- a/hicn-light/src/hicn/config/controlAddPunting.c
+++ b/hicn-light/src/hicn/config/controlAddPunting.c
@@ -34,10 +34,14 @@
static CommandReturn _controlAddPunting_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static CommandReturn _controlAddPunting_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static const char *_commandAddPunting = "add punting";
static const char *_commandAddPuntingHelp = "help add punting";
@@ -59,24 +63,26 @@ CommandOps *controlAddPunting_HelpCreate(ControlState *state) {
static CommandReturn _controlAddPunting_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
- printf("add punting <symbolic> <prefix>\n");
- printf(" <symbolic> : listener symbolic name\n");
- printf(
- " <address> : prefix to add as a punting rule. (example "
- "1234::0/64)\n");
- printf("\n");
-
+ PARCList *args,
+ char *output,
+ size_t output_size) {
+ snprintf(output, output_size, "add punting <symbolic> <prefix>\n"
+ " <symbolic> : listener symbolic name\n"
+ " <address> : prefix to add as a punting rule. (example "
+ "1234::0/64)\n"
+ "\n");
return CommandReturn_Success;
}
static CommandReturn _controlAddPunting_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
+ PARCList *args,
+ char *output,
+ size_t output_size) {
ControlState *state = ops->closure;
if (parcList_Size(args) != 4) {
- _controlAddPunting_HelpExecute(parser, ops, args);
+ _controlAddPunting_HelpExecute(parser, ops, args, output, output_size);
return CommandReturn_Failure;
}
@@ -84,7 +90,7 @@ static CommandReturn _controlAddPunting_Execute(CommandParser *parser,
if (!utils_ValidateSymbolicName(symbolicOrConnid) &&
!utils_IsNumber(symbolicOrConnid)) {
- printf(
+ snprintf(output, output_size,
"ERROR: Invalid symbolic or connid:\n"
"symbolic name must begin with an alpha followed by alphanum;\nconnid "
"must be an integer\n");
@@ -111,7 +117,7 @@ static CommandReturn _controlAddPunting_Execute(CommandParser *parser,
// check and set IP address
if (inet_pton(AF_INET, addr, &addPuntingCommand->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(&addPuntingCommand);
free(addr);
return CommandReturn_Failure;
@@ -119,14 +125,14 @@ static CommandReturn _controlAddPunting_Execute(CommandParser *parser,
addPuntingCommand->addressType = ADDR_INET;
} else if (inet_pton(AF_INET6, addr, &addPuntingCommand->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(&addPuntingCommand);
free(addr);
return CommandReturn_Failure;
}
addPuntingCommand->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(&addPuntingCommand);
free(addr);
return CommandReturn_Failure;
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 <hicn/utils/utils.h>
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 <symbolic | connid> <prefix> <cost>\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 <symbolic | connid> <prefix> <cost>\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;
diff --git a/hicn-light/src/hicn/config/controlCache.c b/hicn-light/src/hicn/config/controlCache.c
index 1c830c956..b6010fcfd 100644
--- a/hicn-light/src/hicn/config/controlCache.c
+++ b/hicn-light/src/hicn/config/controlCache.c
@@ -33,9 +33,14 @@
static void _controlCache_Init(CommandParser *parser, CommandOps *ops);
static CommandReturn _controlCache_Execute(CommandParser *parser,
- CommandOps *ops, PARCList *args);
+ CommandOps *ops,
+ PARCList *args,
+ char *output,
+ size_t output_size);
static CommandReturn _controlCache_HelpExecute(CommandParser *parser,
- CommandOps *ops, PARCList *args);
+ CommandOps *ops, PARCList *args,
+ char *output,
+ size_t output_size);
static const char *_commandCache = "cache";
static const char *_commandCacheHelp = "help cache";
@@ -54,17 +59,18 @@ CommandOps *controlCache_HelpCreate(ControlState *state) {
static CommandReturn _controlCache_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
+ PARCList *args,
+ char *output,
+ size_t output_size) {
CommandOps *ops_cache_serve = controlCacheServe_HelpCreate(NULL);
CommandOps *ops_cache_store = controlCacheStore_HelpCreate(NULL);
CommandOps *ops_cache_clear = controlCacheClear_HelpCreate(NULL);
- printf("Available commands:\n");
- printf(" %s\n", ops_cache_serve->command);
- printf(" %s\n", ops_cache_store->command);
- printf(" %s\n", ops_cache_clear->command);
- printf("\n");
-
+ snprintf(output, output_size, "Available commands:\n"
+ " %s\n %s\n %s\n\n",
+ ops_cache_serve->command,
+ ops_cache_store->command,
+ ops_cache_clear->command);
commandOps_Destroy(&ops_cache_serve);
commandOps_Destroy(&ops_cache_store);
commandOps_Destroy(&ops_cache_clear);
@@ -83,8 +89,11 @@ static void _controlCache_Init(CommandParser *parser, CommandOps *ops) {
}
static CommandReturn _controlCache_Execute(CommandParser *parser,
- CommandOps *ops, PARCList *args) {
- return _controlCache_HelpExecute(parser, ops, args);
+ CommandOps *ops,
+ PARCList *args,
+ char *output,
+ size_t output_size) {
+ return _controlCache_HelpExecute(parser, ops, args, output, output_size);
}
// ======================================================================
diff --git a/hicn-light/src/hicn/config/controlCacheClear.c b/hicn-light/src/hicn/config/controlCacheClear.c
index f412faa29..afd8f6fc1 100644
--- a/hicn-light/src/hicn/config/controlCacheClear.c
+++ b/hicn-light/src/hicn/config/controlCacheClear.c
@@ -31,10 +31,14 @@
static CommandReturn _controlCacheClear_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static CommandReturn _controlCacheClear_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static const char *_commandCacheClear = "cache clear";
static const char *_commandCacheClearHelp = "help cache clear";
@@ -55,18 +59,21 @@ CommandOps *controlCacheClear_HelpCreate(ControlState *state) {
static CommandReturn _controlCacheClear_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
- printf("cache clear\n");
- printf("\n");
+ PARCList *args,
+ char *output,
+ size_t output_size) {
+ snprintf(output, output_size, "cache clear\n\n");
return CommandReturn_Success;
}
static CommandReturn _controlCacheClear_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
+ PARCList *args,
+ char *output,
+ size_t output_size) {
if (parcList_Size(args) != 2) {
- _controlCacheClear_HelpExecute(parser, ops, args);
+ _controlCacheClear_HelpExecute(parser, ops, args, output, output_size);
return CommandReturn_Failure;
}
diff --git a/hicn-light/src/hicn/config/controlCacheServe.c b/hicn-light/src/hicn/config/controlCacheServe.c
index 881c49ed3..a4454037d 100644
--- a/hicn-light/src/hicn/config/controlCacheServe.c
+++ b/hicn-light/src/hicn/config/controlCacheServe.c
@@ -31,10 +31,14 @@
static CommandReturn _controlCacheServe_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static CommandReturn _controlCacheServe_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static const char *_commandCacheServe = "cache serve";
static const char *_commandCacheServeHelp = "help cache serve";
@@ -55,18 +59,20 @@ CommandOps *controlCacheServe_HelpCreate(ControlState *state) {
static CommandReturn _controlCacheServe_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
- printf("cache serve [on|off]\n");
- printf("\n");
-
+ PARCList *args,
+ char *output,
+ size_t output_size) {
+ snprintf(output, output_size, "cache serve [on|off]\n\n");
return CommandReturn_Success;
}
static CommandReturn _controlCacheServe_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
+ PARCList *args,
+ char *output,
+ size_t output_size) {
if (parcList_Size(args) != 3) {
- _controlCacheServe_HelpExecute(parser, ops, args);
+ _controlCacheServe_HelpExecute(parser, ops, args, output, output_size);
return CommandReturn_Failure;
}
@@ -76,7 +82,7 @@ static CommandReturn _controlCacheServe_Execute(CommandParser *parser,
} else if (strcmp(parcList_GetAtIndex(args, 2), "off") == 0) {
active = false;
} else {
- _controlCacheServe_HelpExecute(parser, ops, args);
+ _controlCacheServe_HelpExecute(parser, ops, args, output, output_size);
return CommandReturn_Failure;
}
diff --git a/hicn-light/src/hicn/config/controlCacheStore.c b/hicn-light/src/hicn/config/controlCacheStore.c
index e54eae4f7..9f2a18146 100644
--- a/hicn-light/src/hicn/config/controlCacheStore.c
+++ b/hicn-light/src/hicn/config/controlCacheStore.c
@@ -31,10 +31,14 @@
static CommandReturn _controlCacheStore_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static CommandReturn _controlCacheStore_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static const char *_commandCacheStore = "cache store";
static const char *_commandCacheStoreHelp = "help cache store";
@@ -55,18 +59,21 @@ CommandOps *controlCacheStore_HelpCreate(ControlState *state) {
static CommandReturn _controlCacheStore_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
- printf("cache store [on|off]\n");
- printf("\n");
+ PARCList *args,
+ char *output,
+ size_t output_size) {
+ snprintf(output, output_size, "cache store [on|off]\n\n");
return CommandReturn_Success;
}
static CommandReturn _controlCacheStore_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
+ PARCList *args,
+ char *output,
+ size_t output_size) {
if (parcList_Size(args) != 3) {
- _controlCacheStore_HelpExecute(parser, ops, args);
+ _controlCacheStore_HelpExecute(parser, ops, args, output, output_size);
return CommandReturn_Failure;
}
@@ -76,7 +83,7 @@ static CommandReturn _controlCacheStore_Execute(CommandParser *parser,
} else if (strcmp(parcList_GetAtIndex(args, 2), "off") == 0) {
active = false;
} else {
- _controlCacheStore_HelpExecute(parser, ops, args);
+ _controlCacheStore_HelpExecute(parser, ops, args, output, output_size);
return CommandReturn_Failure;
}
diff --git a/hicn-light/src/hicn/config/controlList.c b/hicn-light/src/hicn/config/controlList.c
index c45f05428..353856c43 100644
--- a/hicn-light/src/hicn/config/controlList.c
+++ b/hicn-light/src/hicn/config/controlList.c
@@ -37,9 +37,15 @@
static void _controlList_Init(CommandParser *parser, CommandOps *ops);
static CommandReturn _controlList_Execute(CommandParser *parser,
- CommandOps *ops, PARCList *args);
+ CommandOps *ops,
+ PARCList *args,
+ char *output,
+ size_t output_size);
static CommandReturn _controlList_HelpExecute(CommandParser *parser,
- CommandOps *ops, PARCList *args);
+ CommandOps *ops,
+ PARCList *args,
+ char *output,
+ size_t output_size);
static const char *_commandList = "list";
static const char *_commandListHelp = "help list";
@@ -57,7 +63,10 @@ CommandOps *controlList_HelpCreate(ControlState *state) {
// =====================================================
static CommandReturn _controlList_HelpExecute(CommandParser *parser,
- CommandOps *ops, PARCList *args) {
+ CommandOps *ops,
+ PARCList *args,
+ char *output,
+ size_t output_size) {
CommandOps *ops_list_connections = controlListConnections_HelpCreate(NULL);
// CommandOps *ops_list_interfaces = controlListInterfaces_HelpCreate(NULL);
CommandOps *ops_list_routes = controlListRoutes_HelpCreate(NULL);
@@ -66,15 +75,21 @@ static CommandReturn _controlList_HelpExecute(CommandParser *parser,
CommandOps *ops_list_policies = controlListPolicies_HelpCreate(NULL);
#endif /* WITH_POLICY */
- printf("Available commands:\n");
- printf(" %s\n", ops_list_connections->command);
- // printf(" %s\n", ops_list_interfaces->command);
- printf(" %s\n", ops_list_routes->command);
- printf(" %s\n", ops_list_listeners->command);
+ snprintf(output, output_size, "Available commands:\n"
+ " %s\n"
+ " %s\n"
+ " %s\n"
#ifdef WITH_POLICY
- printf(" %s\n", ops_list_policies->command);
+ " %s\n"
#endif /* WITH_POLICY */
- printf("\n");
+ "\n",
+ ops_list_connections->command,
+ ops_list_routes->command,
+ ops_list_listeners->command
+#ifdef WITH_POLICY
+ , ops_list_policies->command
+#endif /* WITH_POLICY */
+ );
commandOps_Destroy(&ops_list_connections);
// commandOps_Destroy(&ops_list_interfaces);
@@ -105,8 +120,11 @@ static void _controlList_Init(CommandParser *parser, CommandOps *ops) {
}
static CommandReturn _controlList_Execute(CommandParser *parser,
- CommandOps *ops, PARCList *args) {
- return _controlList_HelpExecute(parser, ops, args);
+ CommandOps *ops,
+ PARCList *args,
+ char *output,
+ size_t output_size) {
+ return _controlList_HelpExecute(parser, ops, args, output, output_size);
}
// ======================================================================
diff --git a/hicn-light/src/hicn/config/controlListConnections.c b/hicn-light/src/hicn/config/controlListConnections.c
index cbed8a79c..6406ba8c3 100644
--- a/hicn-light/src/hicn/config/controlListConnections.c
+++ b/hicn-light/src/hicn/config/controlListConnections.c
@@ -31,10 +31,14 @@
static CommandReturn _controlListConnections_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static CommandReturn _controlListConnections_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static const char *_commandListConnections = "list connections";
static const char *_commandListConnectionsHelp = "help list connections";
@@ -56,30 +60,31 @@ CommandOps *controlListConnections_HelpCreate(ControlState *state) {
static CommandReturn _controlListConnections_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
- printf("list connections: displays a 1-line summary of each connection\n");
- printf("\n");
- printf("The columns are:\n");
- printf(" connection id : an integer index for the connection\n");
- printf(" state : UP or DOWN\n");
- printf(
- " local address : the local network address associated with the "
- "connection\n");
- printf(
- " remote address: the remote network address associated with the "
- "connection\n");
- printf(
- " protocol : the network protocol (tcp, udp, gre, mcast, "
- "ether)\n");
- printf("\n");
+ PARCList *args,
+ char *output,
+ size_t output_size) {
+snprintf(output, output_size, "%s", "list connections: displays a 1-line summary of each connection\n"
+ "\n"
+ "The columns are:\n"
+ " connection id : an integer index for the connection\n"
+ " state : UP or DOWN\n"
+ " local address : the local network address associated with the "
+ "connection\n"
+ " remote address: the remote network address associated with the "
+ "connection\n"
+ " protocol : the network protocol (tcp, udp, gre, mcast, "
+ "ether)\n"
+ "\n");
return CommandReturn_Success;
}
static CommandReturn _controlListConnections_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
+ PARCList *args,
+ char *output,
+ size_t output_size) {
if (parcList_Size(args) != 2) {
- _controlListConnections_HelpExecute(parser, ops, args);
+ _controlListConnections_HelpExecute(parser, ops, args, output, output_size);
return CommandReturn_Failure;
}
#ifdef WITH_POLICY
@@ -112,11 +117,12 @@ static CommandReturn _controlListConnections_Execute(CommandParser *parser,
commandOutputMain[j] = parcMemory_Allocate(sizeof(char) * 256);
}
}
+size_t output_offset = 0;
#ifdef WITH_POLICY
- printf("%5s %10s %12s %6s %40s %40s %5s %s %s\n", "id", "name", "admin_state", "state", "source", "destination", "type", "priority", "flags");
+ output_offset = snprintf(output, output_size, "%5s %10s %12s %6s %40s %40s %5s %s %s\n", "id", "name", "admin_state", "state", "source", "destination", "type", "priority", "flags");
#else
- printf("%5s %10s %12s %6s %40s %40s %5s\n", "id", "name", "admin_state", "state", "source", "destination", "type");
+ output_offset = snprintf(output, output_size, "%5s %10s %12s %6s %40s %40s %5s\n", "id", "name", "admin_state", "state", "source", "destination", "type");
#endif /* WITH_POLICY */
// Process/Print payload
@@ -171,8 +177,7 @@ foreach_policy_tag
if (!controlState_IsInteractive(state)) {
strcpy(commandOutputMain[i], result);
}
-
- puts(result);
+ output_offset += snprintf(output + output_offset, output_size - output_offset, "%s\n", result);
parcMemory_Deallocate((void **)&result);
parcBufferComposer_Release(&composer);
}
diff --git a/hicn-light/src/hicn/config/controlListInterfaces.c b/hicn-light/src/hicn/config/controlListInterfaces.c
index 9800dca74..c632a1d21 100644
--- a/hicn-light/src/hicn/config/controlListInterfaces.c
+++ b/hicn-light/src/hicn/config/controlListInterfaces.c
@@ -28,10 +28,14 @@
static CommandReturn _controlListInterfaces_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static CommandReturn _controlListInterfaces_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static const char *_commandListInterfaces = "list interfaces";
static const char *_commandListInterfacesHelp = "help list interfaces";
@@ -53,18 +57,20 @@ CommandOps *controlListInterfaces_HelpCreate(ControlState *state) {
static CommandReturn _controlListInterfaces_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
- printf("list interfaces\n");
- printf("\n");
-
+ PARCList *args,
+ char *output,
+ size_t output_size) {
+ snprintf(output, output_size, "list interfaces\n\n")
return CommandReturn_Success;
}
static CommandReturn _controlListInterfaces_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
+ PARCList *args,
+ char *output,
+ size_t output_size) {
if (parcList_Size(args) != 2) {
- _controlListInterfaces_HelpExecute(parser, ops, args);
+ _controlListInterfaces_HelpExecute(parser, ops, args, output, output_size);
return CommandReturn_Failure;
}
diff --git a/hicn-light/src/hicn/config/controlListListeners.c b/hicn-light/src/hicn/config/controlListListeners.c
index 1489470a8..c189dfc36 100644
--- a/hicn-light/src/hicn/config/controlListListeners.c
+++ b/hicn-light/src/hicn/config/controlListListeners.c
@@ -29,10 +29,14 @@
static CommandReturn _controlListListeners_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static CommandReturn _controlListListeners_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static const char *_commandListListeners = "list listeners";
static const char *_commandListListenersHelp = "help list listeners";
@@ -55,18 +59,21 @@ CommandOps *controlListListeners_HelpCreate(ControlState *state) {
static CommandReturn _controlListListeners_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
- printf("list listeners\n");
- printf("\n");
+ PARCList *args,
+ char *output,
+ size_t output_size) {
+ snprintf(output, output_size, "list listeners\n\n");
return CommandReturn_Success;
}
static CommandReturn _controlListListeners_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
+ PARCList *args,
+ char *output,
+ size_t output_size) {
if (parcList_Size(args) != 2) {
- _controlListListeners_HelpExecute(parser, ops, args);
+ _controlListListeners_HelpExecute(parser, ops, args, output, output_size);
return CommandReturn_Failure;
}
@@ -94,11 +101,12 @@ static CommandReturn _controlListListeners_Execute(CommandParser *parser,
}
char *addrString = NULL;
+ size_t output_offset = 0;
if (receivedHeader->length > 0) {
- printf("%6.6s %.*s %50.70s %6s %10s\n", "iface", SYMBOLIC_NAME_LEN, "name", "address", "type", "interface");
+ output_offset = snprintf(output, output_size, "%6.6s %.*s %50.70s %6s %10s\n", "iface", SYMBOLIC_NAME_LEN, "name", "address", "type", "interface");
} else {
- printf(" --- No entry in the list \n");
+ output_offset = snprintf(output, output_size, " --- No entry in the list \n");
}
for (int i = 0; i < receivedHeader->length; i++) {
@@ -135,8 +143,7 @@ static CommandReturn _controlListListeners_Execute(CommandParser *parser,
if (!controlState_IsInteractive(state)) {
strncpy(commandOutputMain[i], result, 128);
}
-
- puts(result);
+ output_offset += snprintf(output + output_offset, output_size - output_offset, "%s\n", result);
parcMemory_Deallocate((void **)&result);
parcBufferComposer_Release(&composer);
}
diff --git a/hicn-light/src/hicn/config/controlListPolicies.c b/hicn-light/src/hicn/config/controlListPolicies.c
index 81be6ddfc..8eae6453b 100644
--- a/hicn-light/src/hicn/config/controlListPolicies.c
+++ b/hicn-light/src/hicn/config/controlListPolicies.c
@@ -33,10 +33,14 @@
static CommandReturn _controlListPolicies_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static CommandReturn _controlListPolicies_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static const char *_commandListPolicies = "list policies";
static const char *_commandListPoliciesHelp = "help list policies";
@@ -57,9 +61,10 @@ CommandOps *controlListPolicies_HelpCreate(ControlState *state) {
static CommandReturn _controlListPolicies_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
- printf("command: list policies\n");
- printf("\n");
+ PARCList *args,
+ char *output,
+ size_t output_size) {
+ snprintf(output, output_size, "command: list policies\n\n");
return CommandReturn_Success;
}
@@ -77,9 +82,11 @@ typedef struct {
static CommandReturn _controlListPolicies_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
+ PARCList *args,
+ char *output,
+ size_t output_size) {
if (parcList_Size(args) != 2) {
- _controlListPolicies_HelpExecute(parser, ops, args);
+ _controlListPolicies_HelpExecute(parser, ops, args, output, output_size);
return CommandReturn_Failure;
}
@@ -96,7 +103,7 @@ static CommandReturn _controlListPolicies_Execute(CommandParser *parser,
(header_control_message *)response[0].iov_base;
uint8_t *receivedPayload = (uint8_t *)response[1].iov_base;
if (!receivedPayload) {
- printf("No payload!\n");
+ snprintf(output, output_size, "No payload!\n");
return CommandReturn_Failure;
}
@@ -112,20 +119,15 @@ static CommandReturn _controlListPolicies_Execute(CommandParser *parser,
char *addrString = NULL;
in_port_t port = htons(1234); // this is a random port number that is ignored
-
+ size_t output_offset = 0;
if (receivedHeader->length > 0) {
- printf("%*s %*s"
- #define _(x, y) " %*s"
- foreach_policy_tag
- #undef _
- "%s",
- MAXSZ_PREFIX, "prefix", MAXSZ_APP_NAME /*APP_NAME_LEN*/, "app_name",
- #define _(x, y) MAXSZ_COLUMN, policy_tag_str[POLICY_TAG_ ## x],
- foreach_policy_tag
- #undef _
- "\n");
+ output_offset += snprintf(output, output_size, "%*s %*s", MAXSZ_PREFIX, "prefix", MAXSZ_APP_NAME /*APP_NAME_LEN*/, "app_name");
+ #define _(x, y) output_offset += snprintf(output + output_offset, output_size - output_offset, " %*s",MAXSZ_COLUMN, policy_tag_str[POLICY_TAG_ ## x]);
+ foreach_policy_tag
+ #undef _
+ output_offset += snprintf(output + output_offset, output_size - output_offset, "\n");
} else {
- printf(" --- No entry in the list \n");
+ output_offset += snprintf(output, output_size, " --- No entry in the list \n");
}
tag_state_str_t str;
@@ -177,26 +179,36 @@ static CommandReturn _controlListPolicies_Execute(CommandParser *parser,
parcMemory_Deallocate((void **)&result);
parcBufferComposer_Release(&composer);
#else
- printf("%*s %*s"
+
+ output_offset = snprintf(output + output_offset, output_size - output_offset, "%*s %*s",
+ MAXSZ_PREFIX, addrString, MAXSZ_APP_NAME /*APP_NAME_LEN*/, listPoliciesCommand->policy.app_name);
+ #define _(x, y) output_offset += snprintf(output + output_offset, output_size - output_offset, " %*s", MAXSZ_COLUMN, str.x);
+ foreach_policy_tag
+ #undef _
+
+ output_offset = snprintf(output + output_offset, output_size - output_offset, "\n");
+
+
+ /*printf("%*s %*s"
#define _(x, y) " %*s"
foreach_policy_tag
#undef _
"%s\n",
- MAXSZ_PREFIX, addrString, MAXSZ_APP_NAME /*APP_NAME_LEN*/, listPoliciesCommand->policy.app_name,
+ MAXSZ_PREFIX, addrString, MAXSZ_APP_NAME *//*APP_NAME_LEN*//*, listPoliciesCommand->policy.app_name,
#define _(x, y) MAXSZ_COLUMN, str.x,
foreach_policy_tag
#undef _
- "");
+ "");*/
#endif
}
- printf("\nSTATISTICS\n\n");
+ output_offset += snprintf(output + output_offset, output_size - output_offset, "\nSTATISTICS\n\n");
// STATISTICS
- printf("%*s %*s %*s | %*s | %*s | %*s\n",
+ output_offset += snprintf(output + output_offset, output_size - output_offset, "%*s %*s %*s | %*s | %*s | %*s\n",
MAXSZ_PREFIX, "", MAXSZ_APP_NAME /*APP_NAME_LEN*/, "",
3*MAXSZ_STR_STAT+2, "WIRED", 3*MAXSZ_STR_STAT+2, "WIFI", 3*MAXSZ_STR_STAT+2, "CELLULAR", 3*MAXSZ_STR_STAT+2, "ALL");
- printf("%*s %*s %*s %*s %*s | %*s %*s %*s | %*s %*s %*s | %*s %*s %*s\n",
+ output_offset += snprintf(output + output_offset, output_size - output_offset, "%*s %*s %*s %*s %*s | %*s %*s %*s | %*s %*s %*s | %*s %*s %*s\n",
MAXSZ_PREFIX, "prefix", MAXSZ_APP_NAME /*APP_NAME_LEN*/, "app_name",
MAXSZ_STR_STAT, "throughput", MAXSZ_STR_STAT, "latency", MAXSZ_STR_STAT, "loss_rate",
MAXSZ_STR_STAT, "throughput", MAXSZ_STR_STAT, "latency", MAXSZ_STR_STAT, "loss_rate",
@@ -208,7 +220,7 @@ static CommandReturn _controlListPolicies_Execute(CommandParser *parser,
(i * sizeof(list_policies_command)));
addrString = utils_CommandAddressToString(
listPoliciesCommand->addressType, &listPoliciesCommand->address, &port);
- printf("%*s %*s %*.2f %*.2f %*.2f | %*.2f %*.2f %*.2f | %*.2f %*.2f %*.2f | %*.2f %*.2f %*.2f\n",
+ output_offset += snprintf(output + output_offset, output_size - output_offset, "%*s %*s %*.2f %*.2f %*.2f | %*.2f %*.2f %*.2f | %*.2f %*.2f %*.2f | %*.2f %*.2f %*.2f\n",
MAXSZ_PREFIX, addrString, MAXSZ_APP_NAME, listPoliciesCommand->policy.app_name,
MAXSZ_STR_STAT, listPoliciesCommand->policy.stats.wired.throughput,
MAXSZ_STR_STAT, listPoliciesCommand->policy.stats.wired.latency,
diff --git a/hicn-light/src/hicn/config/controlListRoutes.c b/hicn-light/src/hicn/config/controlListRoutes.c
index 3dc8fa3a3..395251b94 100644
--- a/hicn-light/src/hicn/config/controlListRoutes.c
+++ b/hicn-light/src/hicn/config/controlListRoutes.c
@@ -32,10 +32,14 @@
static CommandReturn _controlListRoutes_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static CommandReturn _controlListRoutes_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static const char *_commandListRoutes = "list routes";
static const char *_commandListRoutesHelp = "help list routes";
@@ -56,29 +60,30 @@ CommandOps *controlListRoutes_HelpCreate(ControlState *state) {
static CommandReturn _controlListRoutes_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
- printf("command: list routes\n");
- printf("\n");
- printf(
- "This command will fetch the prefix routing table. For each route, it "
- "will list:\n");
- printf(" iface: interface\n");
- printf(
- " protocol: the routing protocol, such as STATIC, CONNECTED, etc.\n");
- printf(
- " type: LMP or EXACT (longest matching prefix or exact match)\n");
- printf(" cost: The route cost, lower being preferred\n");
- printf(" next: List of next hops by interface id\n");
- printf(" prefix: name prefix\n");
- printf("\n");
+ PARCList *args,
+ char *output,
+ size_t output_size) {
+ snprintf(output, output_size, "command: list routes\n"
+ "\n"
+ "This command will fetch the prefix routing table. For each route, it "
+ "will list:\n"
+ " iface: interface\n"
+ " protocol: the routing protocol, such as STATIC, CONNECTED, etc.\n"
+ " type: LMP or EXACT (longest matching prefix or exact match)\n"
+ " cost: The route cost, lower being preferred\n"
+ " next: List of next hops by interface id\n"
+ " prefix: name prefix\n"
+ "\n");
return CommandReturn_Success;
}
static CommandReturn _controlListRoutes_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
+ PARCList *args,
+ char *output,
+ size_t output_size) {
if (parcList_Size(args) != 2) {
- _controlListRoutes_HelpExecute(parser, ops, args);
+ _controlListRoutes_HelpExecute(parser, ops, args, output, output_size);
return CommandReturn_Failure;
}
@@ -107,11 +112,11 @@ static CommandReturn _controlListRoutes_Execute(CommandParser *parser,
char *addrString = NULL;
in_port_t port = htons(1234); // this is a random port number that is ignored
-
+ size_t output_offset = 0;
if (receivedHeader->length > 0) {
- printf("%6.6s %8.8s %70.70s %s\n", "iface", "cost", "prefix", "len");
+ output_offset = snprintf(output, output_size, "%6.6s %8.8s %70.70s %s\n", "iface", "cost", "prefix", "len");
} else {
- printf(" --- No entry in the list \n");
+ output_offset = snprintf(output, output_size, " --- No entry in the list \n");
}
for (int i = 0; i < receivedHeader->length; i++) {
@@ -136,7 +141,7 @@ static CommandReturn _controlListRoutes_Execute(CommandParser *parser,
strcpy(commandOutputMain[i], result);
}
- puts(result);
+ output_offset += snprintf(output + output_offset, output_size - output_offset, "%s\n", result);
parcMemory_Deallocate((void **)&result);
parcBufferComposer_Release(&composer);
}
diff --git a/hicn-light/src/hicn/config/controlMapMe.c b/hicn-light/src/hicn/config/controlMapMe.c
index a4901db17..b292ee0f0 100644
--- a/hicn-light/src/hicn/config/controlMapMe.c
+++ b/hicn-light/src/hicn/config/controlMapMe.c
@@ -31,9 +31,15 @@
static void _controlMapMe_Init(CommandParser *parser, CommandOps *ops);
static CommandReturn _controlMapMe_Execute(CommandParser *parser,
- CommandOps *ops, PARCList *args);
+ CommandOps *ops,
+ PARCList *args,
+ char *output,
+ size_t output_size);
static CommandReturn _controlMapMe_HelpExecute(CommandParser *parser,
- CommandOps *ops, PARCList *args);
+ CommandOps *ops,
+ PARCList *args,
+ char *output,
+ size_t output_size);
static const char *_commandMapMe = "mapme";
static const char *_commandMapMeHelp = "help mapme";
@@ -52,18 +58,20 @@ CommandOps *controlMapMe_HelpCreate(ControlState *state) {
static CommandReturn _controlMapMe_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
+ PARCList *args,
+ char *output,
+ size_t output_size) {
CommandOps *ops_mapme_enable = controlMapMeEnable_HelpCreate(NULL);
CommandOps *ops_mapme_discovery = controlMapMeDiscovery_HelpCreate(NULL);
CommandOps *ops_mapme_timescale = controlMapMeTimescale_HelpCreate(NULL);
CommandOps *ops_mapme_retx = controlMapMeRetx_HelpCreate(NULL);
- printf("Available commands:\n");
- printf(" %s\n", ops_mapme_enable->command);
- printf(" %s\n", ops_mapme_discovery->command);
- printf(" %s\n", ops_mapme_timescale->command);
- printf(" %s\n", ops_mapme_retx->command);
- printf("\n");
+ snprintf(output, output_size, "Available commands:\n"
+ " %s\n %s\n %s\n %s\n\n",
+ ops_mapme_enable->command,
+ ops_mapme_discovery->command,
+ ops_mapme_timescale->command,
+ ops_mapme_retx->command);
commandOps_Destroy(&ops_mapme_enable);
commandOps_Destroy(&ops_mapme_discovery);
@@ -86,8 +94,11 @@ static void _controlMapMe_Init(CommandParser *parser, CommandOps *ops) {
}
static CommandReturn _controlMapMe_Execute(CommandParser *parser,
- CommandOps *ops, PARCList *args) {
- return _controlMapMe_HelpExecute(parser, ops, args);
+ CommandOps *ops,
+ PARCList *args,
+ char *output,
+ size_t output_size) {
+ return _controlMapMe_HelpExecute(parser, ops, args, output, output_size);
}
// ======================================================================
diff --git a/hicn-light/src/hicn/config/controlMapMeDiscovery.c b/hicn-light/src/hicn/config/controlMapMeDiscovery.c
index 814c380de..6ec941141 100644
--- a/hicn-light/src/hicn/config/controlMapMeDiscovery.c
+++ b/hicn-light/src/hicn/config/controlMapMeDiscovery.c
@@ -29,10 +29,14 @@
static CommandReturn _controlMapMeDiscovery_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static CommandReturn _controlMapMeDiscovery_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static const char *_commandMapMeDiscovery = "mapme discovery";
static const char *_commandMapMeDiscoveryHelp = "help mapme discovery";
@@ -54,18 +58,21 @@ CommandOps *controlMapMeDiscovery_HelpCreate(ControlState *state) {
static CommandReturn _controlMapMeDiscovery_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
- printf("mapme discovery [on|off]\n");
- printf("\n");
+ PARCList *args,
+ char *output,
+ size_t output_size) {
+ snprintf(output, output_size, "mapme discovery [on|off]\n\n");
return CommandReturn_Success;
}
static CommandReturn _controlMapMeDiscovery_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
+ PARCList *args,
+ char *output,
+ size_t output_size) {
if (parcList_Size(args) != 3) {
- _controlMapMeDiscovery_HelpExecute(parser, ops, args);
+ _controlMapMeDiscovery_HelpExecute(parser, ops, args, output, output_size);
return CommandReturn_Failure;
}
@@ -75,7 +82,7 @@ static CommandReturn _controlMapMeDiscovery_Execute(CommandParser *parser,
} else if (strcmp(parcList_GetAtIndex(args, 2), "off") == 0) {
active = false;
} else {
- _controlMapMeDiscovery_HelpExecute(parser, ops, args);
+ _controlMapMeDiscovery_HelpExecute(parser, ops, args, output, output_size);
return CommandReturn_Failure;
}
diff --git a/hicn-light/src/hicn/config/controlMapMeEnable.c b/hicn-light/src/hicn/config/controlMapMeEnable.c
index a2733e600..0595cc346 100644
--- a/hicn-light/src/hicn/config/controlMapMeEnable.c
+++ b/hicn-light/src/hicn/config/controlMapMeEnable.c
@@ -29,10 +29,14 @@
static CommandReturn _controlMapMeEnable_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static CommandReturn _controlMapMeEnable_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static const char *_commandMapMeEnable = "mapme enable";
static const char *_commandMapMeEnableHelp = "help mapme enable";
@@ -53,18 +57,21 @@ CommandOps *controlMapMeEnable_HelpCreate(ControlState *state) {
static CommandReturn _controlMapMeEnable_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
- printf("mapme enable [on|off]\n");
- printf("\n");
+ PARCList *args,
+ char *output,
+ size_t output_size) {
+ snprintf(output, output_size, "mapme enable [on|off]\n\n");
return CommandReturn_Success;
}
static CommandReturn _controlMapMeEnable_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
+ PARCList *args,
+ char *output,
+ size_t output_size) {
if (parcList_Size(args) != 3) {
- _controlMapMeEnable_HelpExecute(parser, ops, args);
+ _controlMapMeEnable_HelpExecute(parser, ops, args, output, output_size);
return CommandReturn_Failure;
}
@@ -74,7 +81,7 @@ static CommandReturn _controlMapMeEnable_Execute(CommandParser *parser,
} else if (strcmp(parcList_GetAtIndex(args, 2), "off") == 0) {
active = false;
} else {
- _controlMapMeEnable_HelpExecute(parser, ops, args);
+ _controlMapMeEnable_HelpExecute(parser, ops, args, output, output_size);
return CommandReturn_Failure;
}
diff --git a/hicn-light/src/hicn/config/controlMapMeRetx.c b/hicn-light/src/hicn/config/controlMapMeRetx.c
index 49e5b419d..9f37ca6f5 100644
--- a/hicn-light/src/hicn/config/controlMapMeRetx.c
+++ b/hicn-light/src/hicn/config/controlMapMeRetx.c
@@ -28,10 +28,15 @@
#include <hicn/utils/utils.h>
static CommandReturn _controlMapMeRetx_Execute(CommandParser *parser,
- CommandOps *ops, PARCList *args);
+ CommandOps *ops,
+ PARCList *args,
+ char *output,
+ size_t output_size);
static CommandReturn _controlMapMeRetx_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static const char *_commandMapMeRetx = "mapme retx";
static const char *_commandMapMeRetxHelp = "help mapme retx";
@@ -52,24 +57,27 @@ CommandOps *controlMapMeRetx_HelpCreate(ControlState *state) {
static CommandReturn _controlMapMeRetx_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
- printf("mapme retx <milliseconds>n");
- printf("\n");
+ PARCList *args,
+ char *output,
+ size_t output_size) {
+ snprintf(output, output_size, "mapme retx <milliseconds>\n\n");
return CommandReturn_Success;
}
static CommandReturn _controlMapMeRetx_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
+ PARCList *args,
+ char *output,
+ size_t output_size) {
if (parcList_Size(args) != 3) {
- _controlMapMeRetx_HelpExecute(parser, ops, args);
+ _controlMapMeRetx_HelpExecute(parser, ops, args, output, output_size);
return CommandReturn_Failure;
}
const char *rtx = parcList_GetAtIndex(args, 2);
if (!utils_IsNumber(rtx)) {
- printf(
+ snprintf(output, output_size,
"ERROR: retransmission value (expressed in ms) must be a positive "
"integer \n");
return CommandReturn_Failure;
diff --git a/hicn-light/src/hicn/config/controlMapMeTimescale.c b/hicn-light/src/hicn/config/controlMapMeTimescale.c
index 3bfc98269..51701aa2f 100644
--- a/hicn-light/src/hicn/config/controlMapMeTimescale.c
+++ b/hicn-light/src/hicn/config/controlMapMeTimescale.c
@@ -29,10 +29,14 @@
static CommandReturn _controlMapMeTimescale_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static CommandReturn _controlMapMeTimescale_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static const char *_commandMapMeTimescale = "mapme timescale";
static const char *_commandMapMeTimescaleHelp = "help mapme timescale";
@@ -54,24 +58,26 @@ CommandOps *controlMapMeTimescale_HelpCreate(ControlState *state) {
static CommandReturn _controlMapMeTimescale_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
- printf("mapme timescale <milliseconds>n");
- printf("\n");
-
+ PARCList *args,
+ char *output,
+ size_t output_size) {
+ snprintf(output, output_size, "mapme timescale <milliseconds>\n\n");
return CommandReturn_Success;
}
static CommandReturn _controlMapMeTimescale_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
+ PARCList *args,
+ char *output,
+ size_t output_size) {
if (parcList_Size(args) != 3) {
- _controlMapMeTimescale_HelpExecute(parser, ops, args);
+ _controlMapMeTimescale_HelpExecute(parser, ops, args, output, output_size);
return CommandReturn_Failure;
}
const char *ts = parcList_GetAtIndex(args, 2);
if (!utils_IsNumber(ts)) {
- printf(
+ snprintf(output, output_size,
"ERROR: timescale value (expressed in ms) must be a positive integer "
"\n");
return CommandReturn_Failure;
diff --git a/hicn-light/src/hicn/config/controlQuit.c b/hicn-light/src/hicn/config/controlQuit.c
index 8c11e48c2..621880d13 100644
--- a/hicn-light/src/hicn/config/controlQuit.c
+++ b/hicn-light/src/hicn/config/controlQuit.c
@@ -28,9 +28,15 @@
#include <hicn/config/controlQuit.h>
static CommandReturn _controlQuit_Execute(CommandParser *parser,
- CommandOps *ops, PARCList *args);
+ CommandOps *ops,
+ PARCList *args,
+ char *output,
+ size_t output_size);
static CommandReturn _controlQuit_HelpExecute(CommandParser *parser,
- CommandOps *ops, PARCList *args);
+ CommandOps *ops,
+ PARCList *args,
+ char *output,
+ size_t output_size);
static const char *_commandQuit = "quit";
static const char *_commandQuitHelp = "help quit";
@@ -50,13 +56,19 @@ CommandOps *controlQuit_HelpCreate(ControlState *state) {
// ==============================================
static CommandReturn _controlQuit_HelpExecute(CommandParser *parser,
- CommandOps *ops, PARCList *args) {
- printf("Exits the interactive control program\n\n");
+ CommandOps *ops,
+ PARCList *args,
+ char *output,
+ size_t output_size) {
+ snprintf(output, output_size, "Exits the interactive control program\n\n");
return CommandReturn_Success;
}
static CommandReturn _controlQuit_Execute(CommandParser *parser,
- CommandOps *ops, PARCList *args) {
- printf("exiting interactive shell\n");
+ CommandOps *ops,
+ PARCList *args,
+ char *output,
+ size_t output_size) {
+ snprintf(output, output_size, "exiting interactive shell\n");
return CommandReturn_Exit;
}
diff --git a/hicn-light/src/hicn/config/controlRemove.c b/hicn-light/src/hicn/config/controlRemove.c
index ef0c15934..b1a88b5c1 100644
--- a/hicn-light/src/hicn/config/controlRemove.c
+++ b/hicn-light/src/hicn/config/controlRemove.c
@@ -37,10 +37,15 @@
static void _controlRemove_Init(CommandParser *parser, CommandOps *ops);
static CommandReturn _controlRemove_Execute(CommandParser *parser,
- CommandOps *ops, PARCList *args);
+ CommandOps *ops,
+ PARCList *args,
+ char *output,
+ size_t output_size);
static CommandReturn _controlRemove_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static const char *_commandRemove = "remove";
static const char *_commandRemoveHelp = "help remove";
@@ -61,7 +66,9 @@ CommandOps *controlRemove_HelpCreate(ControlState *state) {
static CommandReturn _controlRemove_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
+ PARCList *args,
+ char *output,
+ size_t output_size) {
CommandOps *ops_remove_connection = controlRemoveConnection_Create(NULL);
CommandOps *ops_remove_listener = controlRemoveListener_Create(NULL);
CommandOps *ops_remove_route = controlRemoveRoute_Create(NULL);
@@ -70,15 +77,23 @@ static CommandReturn _controlRemove_HelpExecute(CommandParser *parser,
CommandOps *ops_remove_policy = controlRemovePolicy_Create(NULL);
#endif /* WITH_POLICY */
- printf("Available commands:\n");
- printf(" %s\n", ops_remove_connection->command);
- printf(" %s\n", ops_remove_listener->command);
- printf(" %s\n", ops_remove_route->command);
- printf(" %s\n", ops_remove_punting->command);
+ snprintf(output, output_size, "Available commands:\n"
+ " %s\n"
+ " %s\n"
+ " %s\n"
+ " %s\n"
#ifdef WITH_POLICY
- printf(" %s\n", ops_remove_policy->command);
+ " %s\n"
#endif /* WITH_POLICY */
- printf("\n");
+ "\n",
+ ops_remove_connection->command,
+ ops_remove_listener->command,
+ ops_remove_route->command,
+ ops_remove_punting->command
+#ifdef WITH_POLICY
+ , ops_remove_policy->command
+#endif /* WITH_POLICY */
+ );
commandOps_Destroy(&ops_remove_connection);
commandOps_Destroy(&ops_remove_listener);
@@ -109,6 +124,9 @@ static void _controlRemove_Init(CommandParser *parser, CommandOps *ops) {
}
static CommandReturn _controlRemove_Execute(CommandParser *parser,
- CommandOps *ops, PARCList *args) {
- return _controlRemove_HelpExecute(parser, ops, args);
+ CommandOps *ops,
+ PARCList *args,
+ char *output,
+ size_t output_size) {
+ return _controlRemove_HelpExecute(parser, ops, args, output, output_size);
}
diff --git a/hicn-light/src/hicn/config/controlRemoveConnection.c b/hicn-light/src/hicn/config/controlRemoveConnection.c
index 7c79f9c2f..a6cfae1e5 100644
--- a/hicn-light/src/hicn/config/controlRemoveConnection.c
+++ b/hicn-light/src/hicn/config/controlRemoveConnection.c
@@ -34,10 +34,14 @@
static CommandReturn _controlRemoveConnection_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static CommandReturn _controlRemoveConnection_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
// ===================================================
@@ -62,25 +66,29 @@ CommandOps *controlRemoveConnection_HelpCreate(ControlState *state) {
static CommandReturn _controlRemoveConnection_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
- printf("command:\n");
- printf(" remove connection <symbolic|id>\n");
+ PARCList *args,
+ char *output,
+ size_t output_size) {
+ snprintf(output, output_size, "command:\n"
+ " remove connection <symbolic|id>\n");
return CommandReturn_Success;
}
static CommandReturn _controlRemoveConnection_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
+ PARCList *args,
+ char *output,
+ size_t output_size) {
ControlState *state = ops->closure;
if (parcList_Size(args) != 3) {
- _controlRemoveConnection_HelpExecute(parser, ops, args);
+ _controlRemoveConnection_HelpExecute(parser, ops, args, output, output_size);
return false;
}
if ((strcmp(parcList_GetAtIndex(args, 0), "remove") != 0) ||
(strcmp(parcList_GetAtIndex(args, 1), "connection") != 0)) {
- _controlRemoveConnection_HelpExecute(parser, ops, args);
+ _controlRemoveConnection_HelpExecute(parser, ops, args, output, output_size);
return false;
}
@@ -88,7 +96,7 @@ static CommandReturn _controlRemoveConnection_Execute(CommandParser *parser,
if (!utils_ValidateSymbolicName(symbolicOrConnid) &&
!utils_IsNumber(symbolicOrConnid)) {
- printf(
+ 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;
diff --git a/hicn-light/src/hicn/config/controlRemoveListener.c b/hicn-light/src/hicn/config/controlRemoveListener.c
index 545e189c0..7525316f1 100644
--- a/hicn-light/src/hicn/config/controlRemoveListener.c
+++ b/hicn-light/src/hicn/config/controlRemoveListener.c
@@ -34,10 +34,14 @@
static CommandReturn _controlRemoveListener_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static CommandReturn _controlRemoveListener_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
// ===================================================
@@ -62,25 +66,29 @@ CommandOps *controlRemoveListener_HelpCreate(ControlState *state) {
static CommandReturn _controlRemoveListener_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
- printf("command:\n");
- printf(" remove listener <symbolic|id>\n");
+ PARCList *args,
+ char *output,
+ size_t output_size) {
+ snprintf(output, output_size, "command:\n"
+ " remove listener <symbolic|id>\n");
return CommandReturn_Success;
}
static CommandReturn _controlRemoveListener_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
+ PARCList *args,
+ char *output,
+ size_t output_size) {
ControlState *state = ops->closure;
if (parcList_Size(args) != 3) {
- _controlRemoveListener_HelpExecute(parser, ops, args);
+ _controlRemoveListener_HelpExecute(parser, ops, args, output, output_size);
return false;
}
if ((strcmp(parcList_GetAtIndex(args, 0), "remove") != 0) ||
(strcmp(parcList_GetAtIndex(args, 1), "listener") != 0)) {
- _controlRemoveListener_HelpExecute(parser, ops, args);
+ _controlRemoveListener_HelpExecute(parser, ops, args, output, output_size);
return false;
}
@@ -88,7 +96,7 @@ static CommandReturn _controlRemoveListener_Execute(CommandParser *parser,
if (!utils_ValidateSymbolicName(listenerId) &&
!utils_IsNumber(listenerId)) {
- printf(
+ snprintf(output, output_size,
"ERROR: Invalid symbolic or listenerId:\nsymbolic name must begin with an "
"alpha followed by alphanum;\nlistenerId must be an integer\n");
return CommandReturn_Failure;
diff --git a/hicn-light/src/hicn/config/controlRemovePolicy.c b/hicn-light/src/hicn/config/controlRemovePolicy.c
index bd2e6e6d8..35741396e 100644
--- a/hicn-light/src/hicn/config/controlRemovePolicy.c
+++ b/hicn-light/src/hicn/config/controlRemovePolicy.c
@@ -36,10 +36,14 @@
static CommandReturn _controlRemovePolicy_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static CommandReturn _controlRemovePolicy_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
// ===================================================
@@ -62,19 +66,23 @@ CommandOps *controlRemovePolicy_HelpCreate(ControlState *state) {
static CommandReturn _controlRemovePolicy_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
- printf("commands:\n");
- printf(" remove policy <prefix>\n");
+ PARCList *args,
+ char *output,
+ size_t output_size) {
+ snprintf(output, output_size, "commands:\n"
+ " remove policy <prefix>\n");
return CommandReturn_Success;
}
static CommandReturn _controlRemovePolicy_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
+ PARCList *args,
+ char *output,
+ size_t output_size) {
ControlState *state = ops->closure;
if (parcList_Size(args) != 3) {
- _controlRemovePolicy_HelpExecute(parser, ops, args);
+ _controlRemovePolicy_HelpExecute(parser, ops, args, output, output_size);
return CommandReturn_Failure;
}
@@ -98,7 +106,7 @@ static CommandReturn _controlRemovePolicy_Execute(CommandParser *parser,
// check and set IP address
if (inet_pton(AF_INET, addr, &removePolicyCommand->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(&removePolicyCommand);
free(addr);
return CommandReturn_Failure;
@@ -107,14 +115,14 @@ static CommandReturn _controlRemovePolicy_Execute(CommandParser *parser,
} else if (inet_pton(AF_INET6, addr, &removePolicyCommand->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(&removePolicyCommand);
free(addr);
return CommandReturn_Failure;
}
removePolicyCommand->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(&removePolicyCommand);
free(addr);
return CommandReturn_Failure;
diff --git a/hicn-light/src/hicn/config/controlRemovePunting.c b/hicn-light/src/hicn/config/controlRemovePunting.c
index bf00389d6..84d096b81 100644
--- a/hicn-light/src/hicn/config/controlRemovePunting.c
+++ b/hicn-light/src/hicn/config/controlRemovePunting.c
@@ -31,10 +31,14 @@
static CommandReturn _controlRemovePunting_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static CommandReturn _controlRemovePunting_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
// ===================================================
@@ -60,16 +64,20 @@ CommandOps *controlRemovePunting_HelpCreate(ControlState *state) {
static CommandReturn _controlRemovePunting_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
- printf("remove punting <symbolic> <prefix>\n");
+ PARCList *args,
+ char *output,
+ size_t output_size) {
+ snprintf(output, output_size, "remove punting <symbolic> <prefix>\n");
return CommandReturn_Success;
}
static CommandReturn _controlRemovePunting_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
- printf("command not implemented\n");
- return _controlRemovePunting_HelpExecute(parser, ops, args);
+ PARCList *args,
+ char *output,
+ size_t output_size) {
+ snprintf(output, output_size, "command not implemented\n");
+ return _controlRemovePunting_HelpExecute(parser, ops, args, output, output_size);
}
// ==================================================
diff --git a/hicn-light/src/hicn/config/controlRemoveRoute.c b/hicn-light/src/hicn/config/controlRemoveRoute.c
index 0f46211c1..eb5642d98 100644
--- a/hicn-light/src/hicn/config/controlRemoveRoute.c
+++ b/hicn-light/src/hicn/config/controlRemoveRoute.c
@@ -34,10 +34,14 @@
static CommandReturn _controlRemoveRoute_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static CommandReturn _controlRemoveRoute_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
// ===================================================
@@ -60,19 +64,23 @@ CommandOps *controlRemoveRoute_HelpCreate(ControlState *state) {
static CommandReturn _controlRemoveRoute_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
- printf("commands:\n");
- printf(" remove route <symbolic | connid> <prefix>\n");
+ PARCList *args,
+ char *output,
+ size_t output_size) {
+ snprintf(output, output_size, "commands:\n"
+ " remove route <symbolic | connid> <prefix>\n");
return CommandReturn_Success;
}
static CommandReturn _controlRemoveRoute_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
+ PARCList *args,
+ char *output,
+ size_t output_size) {
ControlState *state = ops->closure;
if (parcList_Size(args) != 4) {
- _controlRemoveRoute_HelpExecute(parser, ops, args);
+ _controlRemoveRoute_HelpExecute(parser, ops, args, output, output_size);
return CommandReturn_Failure;
}
@@ -80,7 +88,7 @@ static CommandReturn _controlRemoveRoute_Execute(CommandParser *parser,
if (!utils_ValidateSymbolicName(symbolicOrConnid) &&
!utils_IsNumber(symbolicOrConnid)) {
- printf(
+ 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;
@@ -106,7 +114,7 @@ static CommandReturn _controlRemoveRoute_Execute(CommandParser *parser,
// check and set IP address
if (inet_pton(AF_INET, addr, &removeRouteCommand->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(&removeRouteCommand);
free(addr);
return CommandReturn_Failure;
@@ -115,14 +123,14 @@ static CommandReturn _controlRemoveRoute_Execute(CommandParser *parser,
} else if (inet_pton(AF_INET6, addr, &removeRouteCommand->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(&removeRouteCommand);
free(addr);
return CommandReturn_Failure;
}
removeRouteCommand->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(&removeRouteCommand);
free(addr);
return CommandReturn_Failure;
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 <server-ip>] [--port <server-port>] "
- "command\n");
- printf("\n");
- printf("Interactive execution:\n");
- printf(" controller [--server <server-ip>] [--port <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 <server-ip>] [--port <server-port>] "
+ "command\n"
+ "\n"
+ "Interactive execution:\n"
+ " controller [--server <server-ip>] [--port <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;
}
diff --git a/hicn-light/src/hicn/config/controlSet.c b/hicn-light/src/hicn/config/controlSet.c
index 4f6a17450..37d56e593 100644
--- a/hicn-light/src/hicn/config/controlSet.c
+++ b/hicn-light/src/hicn/config/controlSet.c
@@ -31,10 +31,16 @@
#include <hicn/config/controlSetWldr.h>
static void _controlSet_Init(CommandParser *parser, CommandOps *ops);
-static CommandReturn _controlSet_Execute(CommandParser *parser, CommandOps *ops,
- PARCList *args);
+static CommandReturn _controlSet_Execute(CommandParser *parser,
+ CommandOps *ops,
+ PARCList *args,
+ char *output,
+ size_t output_size);
static CommandReturn _controlSet_HelpExecute(CommandParser *parser,
- CommandOps *ops, PARCList *args);
+ CommandOps *ops,
+ PARCList *args,
+ char *output,
+ size_t output_size);
static const char *_commandSet = "set";
static const char *_commandSetHelp = "help set";
@@ -64,16 +70,18 @@ static void _controlSet_Init(CommandParser *parser, CommandOps *ops) {
}
static CommandReturn _controlSet_HelpExecute(CommandParser *parser,
- CommandOps *ops, PARCList *args) {
+ CommandOps *ops,
+ PARCList *args,
+ char *output,
+ size_t output_size) {
CommandOps *ops_help_set_debug = controlSetDebug_HelpCreate(NULL);
CommandOps *ops_help_set_strategy = controlSetStrategy_HelpCreate(NULL);
CommandOps *ops_help_set_wldr = controlSetWldr_HelpCreate(NULL);
- printf("Available commands:\n");
- printf(" %s\n", ops_help_set_debug->command);
- printf(" %s\n", ops_help_set_strategy->command);
- printf(" %s\n", ops_help_set_wldr->command);
- printf("\n");
+ snprintf(output, output_size, "Available commands:\n %s\n %s\n %s\n\n",
+ ops_help_set_debug->command,
+ ops_help_set_strategy->command,
+ ops_help_set_wldr->command);
commandOps_Destroy(&ops_help_set_debug);
commandOps_Destroy(&ops_help_set_strategy);
@@ -81,7 +89,10 @@ static CommandReturn _controlSet_HelpExecute(CommandParser *parser,
return CommandReturn_Success;
}
-static CommandReturn _controlSet_Execute(CommandParser *parser, CommandOps *ops,
- PARCList *args) {
- return _controlSet_HelpExecute(parser, ops, args);
+static CommandReturn _controlSet_Execute(CommandParser *parser,
+ CommandOps *ops,
+ PARCList *args,
+ char *output,
+ size_t output_size) {
+ return _controlSet_HelpExecute(parser, ops, args, output, output_size);
}
diff --git a/hicn-light/src/hicn/config/controlSetDebug.c b/hicn-light/src/hicn/config/controlSetDebug.c
index 75e0e5a44..a5dcc89c1 100644
--- a/hicn-light/src/hicn/config/controlSetDebug.c
+++ b/hicn-light/src/hicn/config/controlSetDebug.c
@@ -29,10 +29,14 @@
#include <hicn/core/forwarder.h>
static CommandReturn _controlSetDebug_Execute(CommandParser *parser,
- CommandOps *ops, PARCList *args);
+ CommandOps *ops, PARCList *args,
+ char *output,
+ size_t output_size);
static CommandReturn _controlSetDebug_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static const char *_commandSetDebug = "set debug";
static const char *_commandSetDebugHelp = "help set debug";
@@ -53,21 +57,25 @@ CommandOps *controlSetDebug_HelpCreate(ControlState *state) {
static CommandReturn _controlSetDebug_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
- printf("set debug: will enable the debug flag for more verbose output\n");
- printf("\n");
+ PARCList *args,
+ char *output,
+ size_t output_size) {
+ snprintf(output, output_size, "set debug: will enable the debug flag for more verbose output\n");
return CommandReturn_Success;
}
static CommandReturn _controlSetDebug_Execute(CommandParser *parser,
- CommandOps *ops, PARCList *args) {
+ CommandOps *ops,
+ PARCList *args,
+ char *output,
+ size_t output_size) {
if (parcList_Size(args) != 2) {
- _controlSetDebug_HelpExecute(parser, ops, args);
+ _controlSetDebug_HelpExecute(parser, ops, args, output, output_size);
return CommandReturn_Failure;
}
ControlState *state = ops->closure;
controlState_SetDebug(state, true);
- printf("Debug flag set\n\n");
+ snprintf(output, output_size, "Debug flag set\n\n");
return CommandReturn_Success;
}
diff --git a/hicn-light/src/hicn/config/controlSetStrategy.c b/hicn-light/src/hicn/config/controlSetStrategy.c
index 10fec964b..3229c1864 100644
--- a/hicn-light/src/hicn/config/controlSetStrategy.c
+++ b/hicn-light/src/hicn/config/controlSetStrategy.c
@@ -34,10 +34,14 @@
static CommandReturn _controlSetStrategy_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static CommandReturn _controlSetStrategy_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static const char *_commandSetStrategy = "set strategy";
static const char *_commandSetStrategyHelp = "help set strategy";
@@ -85,7 +89,11 @@ static void _getAddressAndLen(const char * prefixStr, char *addr, uint32_t *len)
}
static bool _checkAndSetIp(set_strategy_command * setStrategyCommand,
- int index, char * addr, uint32_t len){
+ int index,
+ char * addr,
+ uint32_t len,
+ char *output,
+ size_t output_size){
// check and set IP address
int res;
if(index == -1)
@@ -96,10 +104,10 @@ static bool _checkAndSetIp(set_strategy_command * setStrategyCommand,
if(res == 1) {
if (len == UINT32_MAX) {
- printf("Netmask not specified: set to 32 by default\n");
+ snprintf(output, output_size, "Netmask not specified: set to 32 by default\n");
len = 32;
} else if (len > 32) {
- printf("ERROR: exceeded INET mask length, max=32\n");
+ snprintf(output, output_size, "ERROR: exceeded INET mask length, max=32\n");
return false;
}
if(index == -1)
@@ -118,10 +126,10 @@ static bool _checkAndSetIp(set_strategy_command * setStrategyCommand,
if(res == 1) {
if (len == UINT32_MAX) {
- printf("Netmask not specified: set to 128 by default\n");
+ snprintf(output, output_size, "Netmask not specified: set to 128 by default\n");
len = 128;
} else if (len > 128) {
- printf("ERROR: exceeded INET6 mask length, max=128\n");
+ snprintf(output, output_size, "ERROR: exceeded INET6 mask length, max=128\n");
return false;
}
@@ -131,7 +139,8 @@ static bool _checkAndSetIp(set_strategy_command * setStrategyCommand,
setStrategyCommand->addresses_type[index] = 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);
+
return false;
}
}
@@ -140,36 +149,43 @@ static bool _checkAndSetIp(set_strategy_command * setStrategyCommand,
static CommandReturn _controlSetStrategy_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
- printf("set strategy <prefix> <strategy> ");
- printf("[related_prefix1 related_preifx2 ...]\n");
- printf("prefix: ipv4/ipv6 address (ex: 1234::/64)\n");
- printf("strategy: strategy identifier\n");
- printf("optinal: list of related prefixes (max %u)\n",
- MAX_FWD_STRATEGY_RELATED_PREFIXES);
- printf("available strategies:\n");
- printf(" random\n");
- printf(" loadbalancer\n");
- printf(" low_latency\n");
- printf("\n");
+ PARCList *args,
+ char *output,
+ size_t output_size) {
+ snprintf(output, output_size,
+ "set strategy <prefix> <strategy> "
+ "[related_prefix1 related_preifx2 ...]\n"
+ "prefix: ipv4/ipv6 address (ex: 1234::/64)\n"
+ "strategy: strategy identifier\n"
+ "optinal: list of related prefixes (max %u)\n"
+ "available strategies:\n"
+ " random\n"
+ " loadbalancer\n"
+ " low_latency\n\n",
+ MAX_FWD_STRATEGY_RELATED_PREFIXES);
return CommandReturn_Success;
}
static CommandReturn _controlSetStrategy_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
+ PARCList *args,
+ char *output,
+ size_t output_size) {
+ if (output) {
+ output[0] = '\0';
+ }
ControlState *state = ops->closure;
if (parcList_Size(args) < 4 ||
parcList_Size(args) > (4 + MAX_FWD_STRATEGY_RELATED_PREFIXES)) {
- _controlSetStrategy_HelpExecute(parser, ops, args);
+ _controlSetStrategy_HelpExecute(parser, ops, args, output, output_size);
return CommandReturn_Failure;
}
if (((strcmp(parcList_GetAtIndex(args, 0), "set") != 0) ||
(strcmp(parcList_GetAtIndex(args, 1), "strategy") != 0))) {
- _controlSetStrategy_HelpExecute(parser, ops, args);
+ _controlSetStrategy_HelpExecute(parser, ops, args, output, output_size);
return CommandReturn_Failure;
}
@@ -182,7 +198,7 @@ static CommandReturn _controlSetStrategy_Execute(CommandParser *parser,
set_strategy_command *setStrategyCommand =
parcMemory_AllocateAndClear(sizeof(set_strategy_command));
- bool success = _checkAndSetIp(setStrategyCommand, -1, addr, len);
+ bool success = _checkAndSetIp(setStrategyCommand, -1, addr, len, output, output_size);
if(!success){
parcMemory_Deallocate(&setStrategyCommand);
free(addr);
@@ -193,9 +209,11 @@ static CommandReturn _controlSetStrategy_Execute(CommandParser *parser,
// check valid strategy
strategy_type strategy;
if ((strategy = _validStrategy(strategyStr)) == LAST_STRATEGY_VALUE) {
- printf("Error: invalid strategy \n");
+ size_t output_offset = strlen(output);
+ output_offset += snprintf(output + output_offset, output_size - output_offset, "Error: invalid strategy \n");
+
parcMemory_Deallocate(&setStrategyCommand);
- _controlSetStrategy_HelpExecute(parser, ops, args);
+ _controlSetStrategy_HelpExecute(parser, ops, args, output + output_offset, output_size - output_offset);
free(addr);
return CommandReturn_Failure;
}
@@ -205,7 +223,7 @@ static CommandReturn _controlSetStrategy_Execute(CommandParser *parser,
// Fill remaining payload fields
setStrategyCommand->len = len;
setStrategyCommand->strategyType = strategy;
-
+ size_t output_offset = strlen(output);
//check additional prefixes
if(parcList_Size(args) > 4){
uint32_t index = 4; //first realted prefix
@@ -217,12 +235,13 @@ static CommandReturn _controlSetStrategy_Execute(CommandParser *parser,
uint32_t rel_len = UINT32_MAX;
_getAddressAndLen(str, rel_addr, &rel_len);
bool success = _checkAndSetIp(setStrategyCommand, addr_index,
- rel_addr, rel_len);
+ rel_addr, rel_len, output + output_offset, output_size - output_offset);
if(!success){
parcMemory_Deallocate(&setStrategyCommand);
free(rel_addr);
return CommandReturn_Failure;
}
+ output_offset = strlen(output);
setStrategyCommand->lens[addr_index] = rel_len;
free(rel_addr);
index++;
diff --git a/hicn-light/src/hicn/config/controlSetWldr.c b/hicn-light/src/hicn/config/controlSetWldr.c
index 6d990ac19..0d4a7eca2 100644
--- a/hicn-light/src/hicn/config/controlSetWldr.c
+++ b/hicn-light/src/hicn/config/controlSetWldr.c
@@ -32,10 +32,15 @@
#include <hicn/utils/utils.h>
static CommandReturn _controlSetWldr_Execute(CommandParser *parser,
- CommandOps *ops, PARCList *args);
+ CommandOps *ops,
+ PARCList *args,
+ char *output,
+ size_t output_size);
static CommandReturn _controlSetWldr_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static const char *_commandSetWldr = "set wldr";
static const char *_commandSetWldrHelp = "help set wldr";
@@ -56,24 +61,29 @@ CommandOps *controlSetWldr_HelpCreate(ControlState *state) {
static CommandReturn _controlSetWldr_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
- printf("set wldr <on|off> <connection_id>\n");
- printf("\n");
+ PARCList *args,
+ char *output,
+ size_t output_size) {
+ snprintf(output, output_size, "set wldr <on|off> <connection_id>\n\n");
+
return CommandReturn_Success;
}
static CommandReturn _controlSetWldr_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) != 4) {
- _controlSetWldr_HelpExecute(parser, ops, args);
+ _controlSetWldr_HelpExecute(parser, ops, args, output, output_size);
return CommandReturn_Failure;
}
if (((strcmp(parcList_GetAtIndex(args, 0), "set") != 0) ||
(strcmp(parcList_GetAtIndex(args, 1), "wldr") != 0))) {
- _controlSetWldr_HelpExecute(parser, ops, args);
+ _controlSetWldr_HelpExecute(parser, ops, args, output, output_size);
return CommandReturn_Failure;
}
@@ -83,7 +93,7 @@ static CommandReturn _controlSetWldr_Execute(CommandParser *parser,
} else if (strcmp(parcList_GetAtIndex(args, 2), "off") == 0) {
active = false;
} else {
- _controlSetWldr_HelpExecute(parser, ops, args);
+ _controlSetWldr_HelpExecute(parser, ops, args, output, output_size);
return CommandReturn_Failure;
}
@@ -92,7 +102,7 @@ static CommandReturn _controlSetWldr_Execute(CommandParser *parser,
if (!utils_ValidateSymbolicName(symbolicOrConnid) &&
!utils_IsNumber(symbolicOrConnid)) {
- printf(
+ 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;
diff --git a/hicn-light/src/hicn/config/controlState.c b/hicn-light/src/hicn/config/controlState.c
index 2df8805c6..acdae9e52 100644
--- a/hicn-light/src/hicn/config/controlState.c
+++ b/hicn-light/src/hicn/config/controlState.c
@@ -54,7 +54,7 @@ int controlState_connectToFwdDeamon(char *server_ip, uint16_t port) {
if ((sockfd = (int)socket(AF_INET, SOCK_STREAM, 0)) < 0) {
printf("\nSocket Creation Failed \n");
- exit(EXIT_FAILURE);
+ return EXIT_FAILURE;
}
memset(&servaddr, 0, sizeof(servaddr));
@@ -67,7 +67,7 @@ int controlState_connectToFwdDeamon(char *server_ip, uint16_t port) {
// Establish connection
if (connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) {
printf("\nConnection Failed: hicn-light Daemon is not running \n");
- exit(EXIT_FAILURE);
+ return -1;
}
return sockfd;
@@ -76,8 +76,8 @@ int controlState_connectToFwdDeamon(char *server_ip, uint16_t port) {
ControlState *controlState_Create(
void *userdata,
struct iovec *(*writeRead)(ControlState *state, struct iovec *msg),
- bool openControllerConnetion,
- char *server_ip, uint16_t port) {
+ bool openControllerConnetion,
+ char *server_ip, uint16_t port) {
ControlState *state = parcMemory_AllocateAndClear(sizeof(ControlState));
parcAssertNotNull(state, "parcMemory_AllocateAndClear(%zu) returned NULL",
sizeof(ControlState));
@@ -91,6 +91,9 @@ ControlState *controlState_Create(
if (openControllerConnetion) {
state->sockfd = controlState_connectToFwdDeamon(server_ip, port);
+ if (state->sockfd == -1) {
+ return NULL;
+ }
} else {
state->sockfd = 2; // stderr
}
@@ -161,9 +164,11 @@ static PARCList *_controlState_ParseStringIntoTokens(
}
CommandReturn controlState_DispatchCommand(ControlState *state,
- PARCList *args) {
+ PARCList *args,
+ char *output,
+ size_t output_size) {
parcAssertNotNull(state, "Parameter state must be non-null");
- return commandParser_DispatchCommand(state->parser, args);
+ return commandParser_DispatchCommand(state->parser, args, output, output_size);
}
int controlState_Interactive(ControlState *state) {
@@ -171,7 +176,7 @@ int controlState_Interactive(ControlState *state) {
char *line = NULL;
size_t linecap = 0;
CommandReturn controlReturn = CommandReturn_Success;
-
+ char output[8192];
while (controlReturn != CommandReturn_Exit && !feof(stdin)) {
fputs("> ", stdout);
fflush(stdout);
@@ -179,7 +184,9 @@ int controlState_Interactive(ControlState *state) {
parcAssertTrue(failure > -1, "Error getline");
PARCList *args = _controlState_ParseStringIntoTokens(line);
- controlReturn = controlState_DispatchCommand(state, args);
+
+ controlReturn = controlState_DispatchCommand(state, args, output, sizeof(output));
+ printf("%s", output);
// release and get command
parcList_Release(&args);
}
diff --git a/hicn-light/src/hicn/config/controlState.h b/hicn-light/src/hicn/config/controlState.h
index cc38cbe37..52b1f6655 100644
--- a/hicn-light/src/hicn/config/controlState.h
+++ b/hicn-light/src/hicn/config/controlState.h
@@ -143,6 +143,8 @@ void controlState_RegisterCommand(ControlState *state, CommandOps *command);
*
* @param [in] state The allocated ControlState
* @param [in] args Each command_line word parsed to the ordered list
+ * @param [in] output Output string
+ * @param [in] output_length output string max length
*
* @return CommandReturn_Success the command was successful
* @return CommandReturn_Failure the command failed or was not found
@@ -154,7 +156,10 @@ void controlState_RegisterCommand(ControlState *state, CommandOps *command);
* <#example#>
* @endcode
*/
-CommandReturn controlState_DispatchCommand(ControlState *state, PARCList *args);
+CommandReturn controlState_DispatchCommand(ControlState *state,
+ PARCList *args,
+ char *output,
+ size_t output_length);
/**
* Begin an interactive shell
diff --git a/hicn-light/src/hicn/config/controlUnset.c b/hicn-light/src/hicn/config/controlUnset.c
index 28507fbeb..e05ba2286 100644
--- a/hicn-light/src/hicn/config/controlUnset.c
+++ b/hicn-light/src/hicn/config/controlUnset.c
@@ -31,9 +31,15 @@
static void _controlUnset_Init(CommandParser *parser, CommandOps *ops);
static CommandReturn _controlUnset_Execute(CommandParser *parser,
- CommandOps *ops, PARCList *args);
+ CommandOps *ops,
+ PARCList *args,
+ char *output,
+ size_t output_size);
static CommandReturn _controlUnset_HelpExecute(CommandParser *parser,
- CommandOps *ops, PARCList *args);
+ CommandOps *ops,
+ PARCList *args,
+ char *output,
+ size_t output_size);
static const char *_commandUnset = "unset";
static const char *_commandUnsetHelp = "help unset";
@@ -60,18 +66,20 @@ static void _controlUnset_Init(CommandParser *parser, CommandOps *ops) {
static CommandReturn _controlUnset_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
+ PARCList *args,
+ char *output,
+ size_t output_size) {
CommandOps *ops_help_unset_debug = controlUnsetDebug_HelpCreate(NULL);
-
- printf("Available commands:\n");
- printf(" %s\n", ops_help_unset_debug->command);
- printf("\n");
+ snprintf(output, output_size, "Available commands:\n %s\n\n", ops_help_unset_debug->command);
commandOps_Destroy(&ops_help_unset_debug);
return CommandReturn_Success;
}
static CommandReturn _controlUnset_Execute(CommandParser *parser,
- CommandOps *ops, PARCList *args) {
- return _controlUnset_HelpExecute(parser, ops, args);
+ CommandOps *ops,
+ PARCList *args,
+ char *output,
+ size_t output_size) {
+ return _controlUnset_HelpExecute(parser, ops, args, output, output_size);
}
diff --git a/hicn-light/src/hicn/config/controlUnsetDebug.c b/hicn-light/src/hicn/config/controlUnsetDebug.c
index fa95c5127..ac2a4e028 100644
--- a/hicn-light/src/hicn/config/controlUnsetDebug.c
+++ b/hicn-light/src/hicn/config/controlUnsetDebug.c
@@ -30,10 +30,14 @@
static CommandReturn _controlUnsetDebug_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static CommandReturn _controlUnsetDebug_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static const char *_commandUnsetDebug = "unset debug";
static const char *_commandUnsetDebugHelp = "help unset debug";
@@ -54,23 +58,26 @@ CommandOps *controlUnsetDebug_HelpCreate(ControlState *state) {
static CommandReturn _controlUnsetDebug_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
- printf("unset debug: will disable the debug flag\n");
- printf("\n");
+ PARCList *args,
+ char *output,
+ size_t output_size) {
+ snprintf(output, output_size, "unset debug: will disable the debug flag\n\n");
return CommandReturn_Success;
}
static CommandReturn _controlUnsetDebug_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
+ PARCList *args,
+ char *output,
+ size_t output_size) {
if (parcList_Size(args) != 2) {
- _controlUnsetDebug_HelpExecute(parser, ops, args);
+ _controlUnsetDebug_HelpExecute(parser, ops, args, output, output_size);
return CommandReturn_Failure;
}
ControlState *state = ops->closure;
controlState_SetDebug(state, false);
- printf("Debug flag cleared\n\n");
+ snprintf(output, output_size, "Debug flag cleared\n\n");
return CommandReturn_Success;
}
diff --git a/hicn-light/src/hicn/config/controlUpdate.c b/hicn-light/src/hicn/config/controlUpdate.c
index 4c74660c2..095bbf01e 100644
--- a/hicn-light/src/hicn/config/controlUpdate.c
+++ b/hicn-light/src/hicn/config/controlUpdate.c
@@ -33,9 +33,15 @@
static void _controlUpdate_Init(CommandParser *parser, CommandOps *ops);
static CommandReturn _controlUpdate_Execute(CommandParser *parser,
- CommandOps *ops, PARCList *args);
+ CommandOps *ops,
+ PARCList *args,
+ char *output,
+ size_t output_size);
static CommandReturn _controlUpdate_HelpExecute(CommandParser *parser,
- CommandOps *ops, PARCList *args);
+ CommandOps *ops,
+ PARCList *args,
+ char *output,
+ size_t output_size);
static const char *_commandUpdate = "update";
static const char *_commandUpdateHelp = "help update";
@@ -53,18 +59,19 @@ CommandOps *controlUpdate_HelpCreate(ControlState *state) {
// =====================================================
static CommandReturn _controlUpdate_HelpExecute(CommandParser *parser,
- CommandOps *ops, PARCList *args) {
+ CommandOps *ops,
+ PARCList *args,
+ char *output,
+ size_t output_size) {
//CommandOps *ops_update_connections = controlUpdateConnections_HelpCreate(NULL);
// CommandOps *ops_update_interfaces = controlUpdateInterfaces_HelpCreate(NULL);
//CommandOps *ops_update_routes = controlUpdateRoutes_HelpCreate(NULL);
CommandOps *ops_update_listeners = controlUpdateConnection_HelpCreate(NULL);
+ snprintf(output, output_size,
+ "Available commands:\n %s\n\n",
+ ops_update_listeners->command);
- printf("Available commands:\n");
- //printf(" %s\n", ops_update_connections->command);
- // printf(" %s\n", ops_update_interfaces->command);
- //printf(" %s\n", ops_update_routes->command);
- printf(" %s\n", ops_update_listeners->command);
- printf("\n");
+
// commandOps_Destroy(&ops_update_connections);
// commandOps_Destroy(&ops_update_interfaces);
@@ -88,8 +95,11 @@ static void _controlUpdate_Init(CommandParser *parser, CommandOps *ops) {
}
static CommandReturn _controlUpdate_Execute(CommandParser *parser,
- CommandOps *ops, PARCList *args) {
- return _controlUpdate_HelpExecute(parser, ops, args);
+ CommandOps *ops,
+ PARCList *args,
+ char *output,
+ size_t output_size) {
+ return _controlUpdate_HelpExecute(parser, ops, args, output, output_size);
}
#endif /* WITH_POLICY */
diff --git a/hicn-light/src/hicn/config/controlUpdateConnection.c b/hicn-light/src/hicn/config/controlUpdateConnection.c
index ff834522e..70a017d4f 100644
--- a/hicn-light/src/hicn/config/controlUpdateConnection.c
+++ b/hicn-light/src/hicn/config/controlUpdateConnection.c
@@ -37,10 +37,14 @@
static CommandReturn _controlUpdateConnection_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static CommandReturn _controlUpdateConnection_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args);
+ PARCList *args,
+ char *output,
+ size_t output_size);
static const char *command_update_connection = "update connection";
static const char *command_help_update_connection = "help update connection";
@@ -62,24 +66,29 @@ static const int _indexTags = 3;
static CommandReturn _controlUpdateConnection_HelpExecute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
- printf("commands:\n");
- printf(" update connection <symbolic | id> <tags> \n");
- printf("\n");
- printf(
- " symbolic: User defined name for connection, must start with "
- "alpha and be alphanum\n");
- printf(" id: Identifier for the connection\n");
- printf(" tags: A string representing tags\n");
+ PARCList *args,
+ char *output,
+ size_t output_size) {
+
+ snprintf(output, output_size,
+ "commands:\n"
+ " update connection <symbolic | id> <tags> \n"
+ "\n"
+ " symbolic: User defined name for connection, must start with "
+ "alpha and be alphanum\n"
+ " id: Identifier for the connection\n"
+ " tags: A string representing tags\n");
return CommandReturn_Success;
}
static CommandReturn _controlUpdateConnection_Execute(CommandParser *parser,
CommandOps *ops,
- PARCList *args) {
+ PARCList *args,
+ char *output,
+ size_t output_size) {
if ((parcList_Size(args) != 3) && (parcList_Size(args) != 4)) {
- _controlUpdateConnection_HelpExecute(parser, ops, args);
+ _controlUpdateConnection_HelpExecute(parser, ops, args, output, output_size);
return CommandReturn_Failure;
}
@@ -87,7 +96,7 @@ static CommandReturn _controlUpdateConnection_Execute(CommandParser *parser,
if (!utils_ValidateSymbolicName(symbolicOrConnid) &&
!utils_IsNumber(symbolicOrConnid)) {
- printf(
+ 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;