From 813826d91348e766a193b01f2046f903d19fc403 Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Tue, 28 Aug 2012 16:06:47 +0200 Subject: [PATCH] Extend the unregister command to be able to unregister all proxies with one command. --- daemon/commands/unregister.cc | 41 +++++++++++++++++++++++++---------- daemon/daemon.h | 1 + 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/daemon/commands/unregister.cc b/daemon/commands/unregister.cc index 56d0b7c69..91093e916 100644 --- a/daemon/commands/unregister.cc +++ b/daemon/commands/unregister.cc @@ -3,22 +3,41 @@ using namespace std; UnregisterCommand::UnregisterCommand() : - DaemonCommand("unregister", "unregister ", "Unregister the daemon from proxy.") { + DaemonCommand("unregister", "unregister ", "Unregister the daemon from the specified proxy or from all proxies.") { } + void UnregisterCommand::exec(Daemon *app, const char *args) { - LinphoneCore *lc = app->getCore(); LinphoneProxyConfig *cfg = NULL; + string param; int pid; - if (sscanf(args, "%i", &pid) == 1) { - cfg = app->findProxy(pid); - if (cfg == NULL) { - app->sendResponse(Response("No register with such id.")); - return; - } - } else { - app->sendResponse(Response("Missing/Incorrect parameter(s).")); + + istringstream ist(args); + ist >> param; + if (ist.fail()) { + app->sendResponse(Response("Missing parameter.", Response::Error)); return; } - linphone_core_remove_proxy_config(lc, cfg); + if (param.compare("ALL") == 0) { + for (int i = 1; i <= app->maxProxyId(); i++) { + cfg = app->findProxy(i); + if (cfg != NULL) { + linphone_core_remove_proxy_config(app->getCore(), cfg); + } + } + } else { + ist.str(param); + ist.seekg(0); + ist >> pid; + if (ist.fail()) { + app->sendResponse(Response("Incorrect parameter.", Response::Error)); + return; + } + cfg = app->findProxy(pid); + if (cfg == NULL) { + app->sendResponse(Response("No register with such id.", Response::Error)); + return; + } + linphone_core_remove_proxy_config(app->getCore(), cfg); + } app->sendResponse(Response()); } diff --git a/daemon/daemon.h b/daemon/daemon.h index 51cb46580..02913ee13 100644 --- a/daemon/daemon.h +++ b/daemon/daemon.h @@ -155,6 +155,7 @@ public: bool pullEvent(); int updateCallId(LinphoneCall *call); int updateProxyId(LinphoneProxyConfig *proxy); + inline int maxProxyId() { return mProxyIds; }; int updateAudioStreamId(AudioStream *audio_stream); private: static void* iterateThread(void *arg);