diff --git a/daemon/CMakeLists.txt b/daemon/CMakeLists.txt index 2137c230f80e33b554663c7978f0fc66d70efabe..4fde370dc9b7b5057d2c330841217ff6a60ff62f 100644 --- a/daemon/CMakeLists.txt +++ b/daemon/CMakeLists.txt @@ -91,6 +91,7 @@ set(DAEMON_SOURCE_FILES commands/quit.h commands/register.cc commands/register.h + commands/register-info.cc commands/register-status.cc commands/register-status.h commands/terminate.cc diff --git a/daemon/Makefile.am b/daemon/Makefile.am index e68d32fb9fcebefac7b0797fe08e15f5b5a9ac46..27a1e13034c764d7a3c0d1ee489ec2be3b7b7e4c 100644 --- a/daemon/Makefile.am +++ b/daemon/Makefile.am @@ -34,6 +34,7 @@ linphone_daemon_SOURCES=daemon.cc \ commands/port.cc \ commands/ptime.cc \ commands/register.cc \ + commands/register-info.cc \ commands/register-status.cc \ commands/terminate.cc \ commands/unregister.cc \ @@ -73,6 +74,7 @@ linphone_daemon_SOURCES=daemon.cc \ commands/port.h \ commands/ptime.h \ commands/register.h \ + commands/register-info.h \ commands/register-status.h \ commands/terminate.h \ commands/unregister.h \ diff --git a/daemon/commands/register-info.cc b/daemon/commands/register-info.cc new file mode 100644 index 0000000000000000000000000000000000000000..f9750e58764c82cbfc747e80444692f5ad82c912 --- /dev/null +++ b/daemon/commands/register-info.cc @@ -0,0 +1,108 @@ +/* +register-info.cc +Copyright (C) 2016 Belledonne Communications, Grenoble, France + +This library is free software; you can redistribute it and/or modify it +under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at +your option) any later version. + +This library is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with this library; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "register-info.h" + +class RegisterInfoResponse: public Response { +public: + RegisterInfoResponse(): Response() {} + RegisterInfoResponse(int id, const ::LinphoneProxyConfig *cfg): Response() { + append(id, cfg); + } + void append(int id, const ::LinphoneProxyConfig *cfg) { + std::ostringstream ost; + ost << getBody(); + if (ost.tellp() > 0) ost << std::endl; + ost << "Id: " << id << std::endl; + ost << "Identity: " << linphone_proxy_config_get_identity(cfg) << std::endl; + ost << "Proxy: " << linphone_proxy_config_get_server_addr(cfg) << std::endl; + + const char *route = linphone_proxy_config_get_route(cfg); + if (route != NULL) { + ost << "Route: " << route << std::endl; + } + + ost << "State: " << linphone_registration_state_to_string(linphone_proxy_config_get_state(cfg)) << std::endl; + setBody(ost.str()); + } +}; + +RegisterInfoCommand::RegisterInfoCommand(): + DaemonCommand("register-info", "register-info <register_id>|ALL", + "Get informations about one or more registrations.") +{ + addExample(new DaemonCommandExample("register-info 1", + "Status: Ok\n\n" + "Id: 1\n" + "Identity: sip:toto@sip.linphone.org\n" + "Proxy: <sip:sip.linphone.org;transport=tls>\n" + "Route: <sip:sip.linphone.org;transport=tls>\n" + "State: LinphoneRegistrationOk")); + addExample(new DaemonCommandExample("register-info ALL", + "Status: Ok\n\n" + "Id: 1\n" + "Identity: sip:toto@sip.linphone.org\n" + "Proxy: <sip:sip.linphone.org;transport=tls>\n" + "Route: <sip:sip.linphone.org;transport=tls>\n" + "State: LinphoneRegistrationOk\n\n" + "Id: 2\n" + "Identity: sip:toto2@sip.linphone.org\n" + "Proxy: <sip:sip.linphone.org;transport=udp>\n" + "State: LinphoneRegistrationFailed")); + addExample(new DaemonCommandExample("register-info 3", + "Status: Error\n" + "Reason: No register with such id.")); +} + +void RegisterInfoCommand::exec(Daemon *app, const std::string& args) { + std::string param; + std::istringstream ist(args); + ist >> param; + if (ist.fail()) { + app->sendResponse(Response("Missing parameter.", Response::Error)); + return; + } + if (param == "ALL") { + RegisterInfoResponse response; + for (int i=1; i<=app->maxProxyId(); i++) { + ::LinphoneProxyConfig *cfg = app->findProxy(i); + if (cfg != NULL) { + response.append(i, cfg); + } + } + app->sendResponse(response); + } else { + int id; + try { + id = std::stoi(param); + } catch (std::invalid_argument) { + app->sendResponse(Response("Invalid ID.", Response::Error)); + return; + } catch (std::out_of_range) { + app->sendResponse(Response("Out of range ID.", Response::Error)); + return; + } + ::LinphoneProxyConfig *cfg = app->findProxy(id); + if (cfg == NULL) { + app->sendResponse(Response("No register with such id.", Response::Error)); + return; + } + app->sendResponse(RegisterInfoResponse(id, cfg)); + } +} diff --git a/daemon/commands/register-info.h b/daemon/commands/register-info.h new file mode 100644 index 0000000000000000000000000000000000000000..25228b836c2c710886783bd1dd63efa57f773388 --- /dev/null +++ b/daemon/commands/register-info.h @@ -0,0 +1,31 @@ +/* +register-info.h +Copyright (C) 2017 Belledonne Communications, Grenoble, France + +This library is free software; you can redistribute it and/or modify it +under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at +your option) any later version. + +This library is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with this library; if not, write to the Free Software Foundation, +Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef LINPHONE_DAEMON_COMMAND_REGISTER_INFO_H_ +#define LINPHONE_DAEMON_COMMAND_REGISTER_INFO_H_ + +#include "daemon.h" + +class RegisterInfoCommand: public DaemonCommand { +public: + RegisterInfoCommand(); + virtual void exec(Daemon *app, const std::string& args); +}; + +#endif // LINPHONE_DAEMON_COMMAND_REGISTER_INFO_H_ diff --git a/daemon/daemon.cc b/daemon/daemon.cc index 1b996f29bf84a2a9bac4186fc0db087382360ca4..bcda18ef51868551ab0b369f0b9593636d752c0f 100644 --- a/daemon/daemon.cc +++ b/daemon/daemon.cc @@ -70,6 +70,7 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include "commands/port.h" #include "commands/ptime.h" #include "commands/register.h" +#include "commands/register-info.h" #include "commands/register-status.h" #include "commands/terminate.h" #include "commands/unregister.h" @@ -471,6 +472,7 @@ void Daemon::initCommands() { mCommands.push_back(new RegisterCommand()); mCommands.push_back(new ContactCommand()); mCommands.push_back(new RegisterStatusCommand()); + mCommands.push_back(new RegisterInfoCommand()); mCommands.push_back(new UnregisterCommand()); mCommands.push_back(new AuthInfosClearCommand()); mCommands.push_back(new CallCommand());