mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-25 23:28:09 +00:00
Add media-encryption command.
Fixes bug 0000186.
This commit is contained in:
parent
566071b2ea
commit
ab122cc3b3
4 changed files with 84 additions and 0 deletions
|
|
@ -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 \
|
||||
|
|
|
|||
63
daemon/commands/media-encryption.cc
Normal file
63
daemon/commands/media-encryption.cc
Normal 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));
|
||||
}
|
||||
}
|
||||
17
daemon/commands/media-encryption.h
Normal file
17
daemon/commands/media-encryption.h
Normal 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_
|
||||
|
|
@ -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());
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue