diff options
author | San Mehat <san@google.com> | 2009-05-14 15:00:06 -0700 |
---|---|---|
committer | San Mehat <san@google.com> | 2009-05-15 10:40:29 -0700 |
commit | 5d6d417972f8d946c223c4efb9636b1ba4280543 (patch) | |
tree | bbe4637de91895dd9a0283b8dcc3a3d2cf9378b0 /nexus/CommandListener.cpp | |
parent | c41d1c8074ed02acc9d1e749d81e0aafb5efbbfa (diff) | |
download | system_core-5d6d417972f8d946c223c4efb9636b1ba4280543.zip system_core-5d6d417972f8d946c223c4efb9636b1ba4280543.tar.gz system_core-5d6d417972f8d946c223c4efb9636b1ba4280543.tar.bz2 |
nexus: Flesh out VPN support a bit more, cleanup service handling
Signed-off-by: San Mehat <san@google.com>
Diffstat (limited to 'nexus/CommandListener.cpp')
-rw-r--r-- | nexus/CommandListener.cpp | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/nexus/CommandListener.cpp b/nexus/CommandListener.cpp index d9ee971..fdf3fed 100644 --- a/nexus/CommandListener.cpp +++ b/nexus/CommandListener.cpp @@ -14,6 +14,9 @@ * limitations under the License. */ #include <stdlib.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <arpa/inet.h> #include <errno.h> #define LOG_TAG "CommandListener" @@ -25,6 +28,7 @@ #include "Controller.h" #include "NetworkManager.h" #include "WifiController.h" +#include "VpnController.h" #include "ErrorCode.h" CommandListener::CommandListener() : @@ -40,6 +44,8 @@ CommandListener::CommandListener() : registerCmd(new WifiGetVarCmd()); registerCmd(new VpnEnableCmd()); + registerCmd(new VpnSetVarCmd()); + registerCmd(new VpnGetVarCmd()); registerCmd(new VpnDisableCmd()); } @@ -261,6 +267,79 @@ int CommandListener::VpnEnableCmd::runCommand(SocketClient *cli, char *data) { return 0; } +CommandListener::VpnSetVarCmd::VpnSetVarCmd() : + NexusCommand("vpn_setvar") { +} + +int CommandListener::VpnSetVarCmd::runCommand(SocketClient *cli, char *data) { + VpnController *vc = (VpnController *) NetworkManager::Instance()->findController("VPN"); + + char *bword; + char *last; + char varname[32]; + char val[250]; + + if (!(bword = strtok_r(data, ":", &last))) + goto out_inval; + + strncpy(varname, bword, sizeof(varname)); + + if (!(bword = strtok_r(NULL, ":", &last))) + goto out_inval; + + strncpy(val, bword, sizeof(val)); + + if (!strcasecmp(varname, "vpn_gateway")) { + if (vc->setVpnGateway(val)) + goto out_inval; + } else { + cli->sendMsg(ErrorCode::CommandParameterError, "Variable not found.", true); + return 0; + } + + cli->sendMsg(ErrorCode::CommandOkay, "Variable written.", false); + return 0; + +out_inval: + errno = EINVAL; + cli->sendMsg(ErrorCode::CommandParameterError, "Failed to set variable.", true); + return 0; +} + +CommandListener::VpnGetVarCmd::VpnGetVarCmd() : + NexusCommand("vpn_getvar") { +} + +int CommandListener::VpnGetVarCmd::runCommand(SocketClient *cli, char *data) { + VpnController *vc = (VpnController *) NetworkManager::Instance()->findController("VPN"); + + char *bword; + char *last; + char varname[32]; + + if (!(bword = strtok_r(data, ":", &last))) + goto out_inval; + + strncpy(varname, bword, sizeof(varname)); + + if (!strcasecmp(varname, "vpn_gateway")) { + char buffer[255]; + + sprintf(buffer, "%s:%s", varname, inet_ntoa(vc->getVpnGateway())); + cli->sendMsg(ErrorCode::VariableRead, buffer, false); + } else { + cli->sendMsg(ErrorCode::CommandParameterError, "Variable not found.", true); + return 0; + } + + cli->sendMsg(ErrorCode::CommandOkay, "Variable read.", false); + return 0; +out_inval: + errno = EINVAL; + cli->sendMsg(ErrorCode::CommandParameterError, "Failed to get variable.", true); + return 0; +} + CommandListener::VpnDisableCmd::VpnDisableCmd() : NexusCommand("vpn_disable") { } |