Commit a2a896e3 authored by Simon Morlat's avatar Simon Morlat
Browse files

add new command to set/get config items

parent fd685faa
No related merge requests found
Showing 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 \
......
#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()));
}
}
#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() {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment