Add ipv6 command.

Fixes bug 0000183.
This commit is contained in:
Ghislain MARY 2012-08-24 16:30:22 +02:00
parent bad9235398
commit 40f1bcf6d4
4 changed files with 72 additions and 0 deletions

View file

@ -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 \

51
daemon/commands/ipv6.cc Normal file
View file

@ -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));
}
}

17
daemon/commands/ipv6.h Normal file
View file

@ -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_

View file

@ -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());