diff --git a/daemon/Makefile.am b/daemon/Makefile.am index 1fe661506..b824ccaed 100644 --- a/daemon/Makefile.am +++ b/daemon/Makefile.am @@ -16,6 +16,7 @@ linphone_daemon_SOURCES=daemon.cc \ commands/call-status.cc \ commands/firewall-policy.cc \ commands/help.cc \ + commands/ipv6.cc \ commands/msfilter-add-fmtp.cc \ commands/pop-event.cc \ commands/ptime.cc \ @@ -38,6 +39,7 @@ linphone_daemon_SOURCES=daemon.cc \ commands/call-status.h \ commands/firewall-policy.h \ commands/help.h \ + commands/ipv6.h \ commands/msfilter-add-fmtp.h \ commands/pop-event.h \ commands/ptime.h \ diff --git a/daemon/commands/ipv6.cc b/daemon/commands/ipv6.cc new file mode 100644 index 000000000..1edb744b4 --- /dev/null +++ b/daemon/commands/ipv6.cc @@ -0,0 +1,51 @@ +#include "ipv6.h" + +using namespace std; + +class IPv6CommandPrivate { +public: + void outputIPv6(Daemon *app, ostringstream &ost); +}; + +void IPv6CommandPrivate::outputIPv6(Daemon* app, ostringstream& ost) { + bool ipv6_enabled = linphone_core_ipv6_enabled(app->getCore()) == TRUE ? true : false; + ost << "Status: "; + if (ipv6_enabled) { + ost << "enabled\n"; + } else { + ost << "disabled\n"; + } +} + +IPv6Command::IPv6Command() : + DaemonCommand("ipv6", "ipv6 [enable|disable]", + "Enable or disable IPv6 respectively with the 'enable' and 'disable' parameters, return the status of the use of IPv6 without parameter."), + d(new IPv6CommandPrivate()) { +} + +IPv6Command::~IPv6Command() { + delete d; +} + +void IPv6Command::exec(Daemon *app, const char *args) { + string status; + istringstream ist(args); + ist >> status; + if (ist.fail()) { + ostringstream ost; + d->outputIPv6(app, ost); + app->sendResponse(Response(ost.str().c_str(), Response::Ok)); + } else { + if (status.compare("enable") == 0) { + linphone_core_enable_ipv6(app->getCore(), TRUE); + } else if (status.compare("disable") == 0) { + linphone_core_enable_ipv6(app->getCore(), FALSE); + } else { + app->sendResponse(Response("Incorrect parameter.", Response::Error)); + return; + } + ostringstream ost; + d->outputIPv6(app, ost); + app->sendResponse(Response(ost.str().c_str(), Response::Ok)); + } +} diff --git a/daemon/commands/ipv6.h b/daemon/commands/ipv6.h new file mode 100644 index 000000000..c744bf765 --- /dev/null +++ b/daemon/commands/ipv6.h @@ -0,0 +1,17 @@ +#ifndef COMMAND_IPV6_H_ +#define COMMAND_IPV6_H_ + +#include "../daemon.h" + +class IPv6CommandPrivate; + +class IPv6Command: public DaemonCommand { +public: + IPv6Command(); + ~IPv6Command(); + virtual void exec(Daemon *app, const char *args); +private: + IPv6CommandPrivate *d; +}; + +#endif //COMMAND_IPV6_H_ diff --git a/daemon/daemon.cc b/daemon/daemon.cc index a6ebf8971..f5230bf48 100644 --- a/daemon/daemon.cc +++ b/daemon/daemon.cc @@ -23,6 +23,7 @@ #include "commands/call-status.h" #include "commands/firewall-policy.h" #include "commands/help.h" +#include "commands/ipv6.h" #include "commands/msfilter-add-fmtp.h" #include "commands/pop-event.h" #include "commands/ptime.h" @@ -301,6 +302,7 @@ void Daemon::initCommands() { mCommands.push_back(new AudioStreamStopCommand()); mCommands.push_back(new MSFilterAddFmtpCommand()); mCommands.push_back(new PtimeCommand()); + mCommands.push_back(new IPv6Command()); mCommands.push_back(new FirewallPolicyCommand()); mCommands.push_back(new QuitCommand()); mCommands.push_back(new HelpCommand());