diff --git a/daemon/Makefile.am b/daemon/Makefile.am index 573d29cad481e245183debf2170719cc430f5029..4c39ff8e03b49a53eb5b8cf7bfb6dc8e96136232 100644 --- a/daemon/Makefile.am +++ b/daemon/Makefile.am @@ -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 \ diff --git a/daemon/commands/config.cc b/daemon/commands/config.cc new file mode 100644 index 0000000000000000000000000000000000000000..fa89bc8c3b226b940fa48e86e241a9965fcbaff7 --- /dev/null +++ b/daemon/commands/config.cc @@ -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())); + } +} + diff --git a/daemon/commands/configcommand.h b/daemon/commands/configcommand.h new file mode 100644 index 0000000000000000000000000000000000000000..70327dbfcea419bb8f1f234db728d9e40b1e1860 --- /dev/null +++ b/daemon/commands/configcommand.h @@ -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_ diff --git a/daemon/daemon.cc b/daemon/daemon.cc index 32048cf9a69db8bfc9e8576d85ff38597ed55eba..a46892f3a078e1a66b6692c310249e4b684effa6 100644 --- a/daemon/daemon.cc +++ b/daemon/daemon.cc @@ -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() {