forked from mirrors/linphone-iphone
add new command to set/get config items
This commit is contained in:
parent
fd685faaf1
commit
a2a896e362
4 changed files with 82 additions and 0 deletions
|
|
@ -39,6 +39,7 @@ linphone_daemon_SOURCES=daemon.cc \
|
|||
commands/quit.cc \
|
||||
commands/version.cc \
|
||||
commands/contact.cc \
|
||||
commands/config.cc commands/configcommand.h \
|
||||
daemon.h \
|
||||
commands/adaptive-jitter-compensation.h \
|
||||
commands/answer.h \
|
||||
|
|
|
|||
60
daemon/commands/config.cc
Normal file
60
daemon/commands/config.cc
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
#include "configcommand.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
class ConfigResponse : public Response {
|
||||
public:
|
||||
ConfigResponse(const char *value);
|
||||
};
|
||||
|
||||
ConfigResponse::ConfigResponse(const char *value) : Response() {
|
||||
ostringstream ost;
|
||||
ost << "Value: "<<(value ? value : "<unset>");
|
||||
setBody(ost.str().c_str());
|
||||
}
|
||||
|
||||
ConfigGetCommand::ConfigGetCommand() :
|
||||
DaemonCommand("config-get", "config section key",
|
||||
"Reads a configuration value from linphone's configuration database.") {
|
||||
addExample(new DaemonCommandExample("config rtp symmetric",
|
||||
"Status: Ok\n\n"
|
||||
"Value: <unset>"));
|
||||
}
|
||||
|
||||
void ConfigGetCommand::exec(Daemon *app, const char *args) {
|
||||
string section,key;
|
||||
istringstream ist(args);
|
||||
ist >> section >> key;
|
||||
if (ist.fail()) {
|
||||
app->sendResponse(Response("Missing section and/or key names."));
|
||||
} else {
|
||||
const char *read_value=lp_config_get_string(linphone_core_get_config(app->getCore()),section.c_str(),key.c_str(),NULL);
|
||||
app->sendResponse(ConfigResponse(read_value));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ConfigSetCommand::ConfigSetCommand() :
|
||||
DaemonCommand("config-set", "config section key value",
|
||||
"Sets a configuration value into linphone's configuration database.") {
|
||||
addExample(new DaemonCommandExample("config-set rtp symmetric 1",
|
||||
"Status: Ok\n\n"
|
||||
"Value: 2"));
|
||||
addExample(new DaemonCommandExample("config-set rtp symmetric",
|
||||
"Status: Ok\n\n"
|
||||
"Value: <unset>"));
|
||||
}
|
||||
|
||||
void ConfigSetCommand::exec(Daemon *app, const char *args) {
|
||||
string section,key,value;
|
||||
istringstream ist(args);
|
||||
ist >> section >> key;
|
||||
if (ist.fail()) {
|
||||
app->sendResponse(Response("Missing section and/or key names."));
|
||||
} else {
|
||||
ist>>value;
|
||||
lp_config_set_string(linphone_core_get_config(app->getCore()), section.c_str(), key.c_str(), value.size()>0 ? value.c_str() : NULL);
|
||||
app->sendResponse(ConfigResponse(value.c_str()));
|
||||
}
|
||||
}
|
||||
|
||||
18
daemon/commands/configcommand.h
Normal file
18
daemon/commands/configcommand.h
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#ifndef COMMAND_CONFIG_H_
|
||||
#define COMMAND_CONFIG_H_
|
||||
|
||||
#include "../daemon.h"
|
||||
|
||||
class ConfigGetCommand: public DaemonCommand {
|
||||
public:
|
||||
ConfigGetCommand();
|
||||
virtual void exec(Daemon *app, const char *args);
|
||||
};
|
||||
|
||||
class ConfigSetCommand: public DaemonCommand {
|
||||
public:
|
||||
ConfigSetCommand();
|
||||
virtual void exec(Daemon *app, const char *args);
|
||||
};
|
||||
|
||||
#endif //COMMAND_IPV6_H_
|
||||
|
|
@ -48,6 +48,7 @@
|
|||
#include "commands/terminate.h"
|
||||
#include "commands/unregister.h"
|
||||
#include "commands/quit.h"
|
||||
#include "commands/configcommand.h"
|
||||
#include "commands/version.h"
|
||||
|
||||
#include "private.h"
|
||||
|
|
@ -447,6 +448,8 @@ void Daemon::initCommands() {
|
|||
mCommands.push_back(new VersionCommand());
|
||||
mCommands.push_back(new QuitCommand());
|
||||
mCommands.push_back(new HelpCommand());
|
||||
mCommands.push_back(new ConfigGetCommand());
|
||||
mCommands.push_back(new ConfigSetCommand());
|
||||
}
|
||||
|
||||
void Daemon::uninitCommands() {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue