Add media-encryption command.

Fixes bug 0000186.
This commit is contained in:
Ghislain MARY 2012-08-27 09:30:48 +02:00
parent 566071b2ea
commit ab122cc3b3
4 changed files with 84 additions and 0 deletions

View file

@ -17,6 +17,7 @@ linphone_daemon_SOURCES=daemon.cc \
commands/firewall-policy.cc \
commands/help.cc \
commands/ipv6.cc \
commands/media-encryption.cc \
commands/msfilter-add-fmtp.cc \
commands/pop-event.cc \
commands/ptime.cc \
@ -40,6 +41,7 @@ linphone_daemon_SOURCES=daemon.cc \
commands/firewall-policy.h \
commands/help.h \
commands/ipv6.h \
commands/media-encryption.h \
commands/msfilter-add-fmtp.h \
commands/pop-event.h \
commands/ptime.h \

View file

@ -0,0 +1,63 @@
#include "media-encryption.h"
using namespace std;
class MediaEncryptionCommandPrivate {
public:
void outputMediaEncryption(Daemon *app, ostringstream &ost);
};
void MediaEncryptionCommandPrivate::outputMediaEncryption(Daemon* app, ostringstream& ost) {
LinphoneMediaEncryption encryption = linphone_core_get_media_encryption(app->getCore());
ost << "Encryption: ";
switch (encryption) {
case LinphoneMediaEncryptionNone:
ost << "none\n";
break;
case LinphoneMediaEncryptionSRTP:
ost << "srtp\n";
break;
case LinphoneMediaEncryptionZRTP:
ost << "zrtp\n";
break;
}
}
MediaEncryptionCommand::MediaEncryptionCommand() :
DaemonCommand("media-encryption", "media-encryption [none|srtp|zrtp]",
"Set the media encryption policy if a parameter is given, otherwise return the media encrytion in use."),
d(new MediaEncryptionCommandPrivate()) {
}
MediaEncryptionCommand::~MediaEncryptionCommand() {
delete d;
}
void MediaEncryptionCommand::exec(Daemon *app, const char *args) {
string encryption_str;
istringstream ist(args);
ist >> encryption_str;
if (ist.eof() && (encryption_str.length() == 0)) {
ostringstream ost;
d->outputMediaEncryption(app, ost);
app->sendResponse(Response(ost.str().c_str(), Response::Ok));
} else if (ist.fail()) {
app->sendResponse(Response("Incorrect parameter.", Response::Error));
} else {
LinphoneMediaEncryption encryption;
if (encryption_str.compare("none") == 0) {
encryption = LinphoneMediaEncryptionNone;
} else if (encryption_str.compare("srtp") == 0) {
encryption = LinphoneMediaEncryptionSRTP;
} else if (encryption_str.compare("zrtp") == 0) {
encryption = LinphoneMediaEncryptionZRTP;
} else {
app->sendResponse(Response("Incorrect parameter.", Response::Error));
return;
}
linphone_core_set_media_encryption(app->getCore(), encryption);
ostringstream ost;
d->outputMediaEncryption(app, ost);
app->sendResponse(Response(ost.str().c_str(), Response::Ok));
}
}

View file

@ -0,0 +1,17 @@
#ifndef COMMAND_MEDIA_ENCRYPTION_H_
#define COMMAND_MEDIA_ENCRYPTION_H_
#include "../daemon.h"
class MediaEncryptionCommandPrivate;
class MediaEncryptionCommand: public DaemonCommand {
public:
MediaEncryptionCommand();
~MediaEncryptionCommand();
virtual void exec(Daemon *app, const char *args);
private:
MediaEncryptionCommandPrivate *d;
};
#endif //COMMAND_MEDIA_ENCRYPTION_H_

View file

@ -24,6 +24,7 @@
#include "commands/firewall-policy.h"
#include "commands/help.h"
#include "commands/ipv6.h"
#include "commands/media-encryption.h"
#include "commands/msfilter-add-fmtp.h"
#include "commands/pop-event.h"
#include "commands/ptime.h"
@ -304,6 +305,7 @@ void Daemon::initCommands() {
mCommands.push_back(new PtimeCommand());
mCommands.push_back(new IPv6Command());
mCommands.push_back(new FirewallPolicyCommand());
mCommands.push_back(new MediaEncryptionCommand());
mCommands.push_back(new QuitCommand());
mCommands.push_back(new HelpCommand());