Add 'auth-infos-clear' daemon command to flush auth infos

parent 17524f08
......@@ -12,6 +12,7 @@ linphone_daemon_SOURCES=daemon.cc \
commands/audio-stream-start.cc \
commands/audio-stream-stop.cc \
commands/audio-stream-stats.cc \
commands/auth-infos-clear.cc \
commands/call.cc \
commands/call-stats.cc \
commands/call-status.cc \
......@@ -86,7 +87,7 @@ linphone_daemon_LDADD=$(top_builddir)/coreapi/liblinphone.la $(READLINE_LIBS) \
$(MEDIASTREAMER_LIBS) \
$(ORTP_LIBS) \
$(SPEEX_LIBS) \
$(LIBXML2_LIBS)
$(LIBXML2_LIBS)
AM_CFLAGS=$(READLINE_CFLAGS) -DIN_LINPHONE $(STRICT_OPTIONS)
AM_CXXFLAGS=$(READLINE_CXXFLAGS) -DIN_LINPHONE $(STRICT_OPTIONS)
......
#include "auth-infos-clear.h"
using namespace std;
AuthInfosClearCommand::AuthInfosClearCommand() :
DaemonCommand("auth-infos-clear", "auth-infos-clear <auth_infos_id|ALL> ", "Remove auth infos context for the given id, or all.") {
addExample(new DaemonCommandExample("auth-infos-clear 1",
"Status: Ok\n"
"Reason: Successfully cleared auth info 1."));
addExample(new DaemonCommandExample("auth-infos-clear ALL",
"Status: Ok\n"
"Reason: Successfully cleared 5 auth infos."));
addExample(new DaemonCommandExample("auth-infos-clear 3",
"Status: Error\n"
"Reason: No auth info with such id."));
}
void AuthInfosClearCommand::exec(Daemon *app, const char *args) {
string param;
int pid;
ostringstream ostr;
istringstream ist(args);
ist >> param;
if (ist.fail()) {
app->sendResponse(Response("Missing parameter.", Response::Error));
return;
}
if (param.compare("ALL") == 0) {
int previous_size = app->maxAuthInfoId();
linphone_core_clear_all_auth_info(app->getCore());
ostr << "Successfully cleared " << previous_size - app->maxAuthInfoId() << " auth infos." << endl;
app->sendResponse(Response(ostr.str().c_str(), Response::Ok));
} else {
LinphoneAuthInfo *auth_info = NULL;
ist.clear();
ist.str(param);
ist >> pid;
if (ist.fail()) {
app->sendResponse(Response("Incorrect parameter.", Response::Error));
return;
}
auth_info = app->findAuthInfo(pid);
if (auth_info == NULL) {
app->sendResponse(Response("No auth info with such id.", Response::Error));
return;
}
linphone_core_remove_auth_info(app->getCore(), auth_info);
ostr << "Successfully cleared auth info " << pid << "." << endl;
app->sendResponse(Response(ostr.str().c_str(), Response::Ok));
}
}
#ifndef COMMAND_AUTH_INFOS_CLEAR_H_
#define COMMAND_AUTH_INFOS_CLEAR_H_
#include "../daemon.h"
class AuthInfosClearCommand: public DaemonCommand {
public:
AuthInfosClearCommand();
virtual void exec(Daemon *app, const char *args);
};
#endif //COMMAND_AUTH_INFOS_CLEAR_H_
......@@ -23,6 +23,7 @@
#include "commands/audio-stream-start.h"
#include "commands/audio-stream-stop.h"
#include "commands/audio-stream-stats.h"
#include "commands/auth-infos-clear.h"
#include "commands/call.h"
#include "commands/call-stats.h"
#include "commands/call-status.h"
......@@ -374,6 +375,18 @@ LinphoneProxyConfig *Daemon::findProxy(int id) {
return NULL;
}
LinphoneAuthInfo *Daemon::findAuthInfo(int id) {
const MSList *elem = linphone_core_get_auth_info_list(mLc);
if (elem == NULL || id < 1 || id > ms_list_size(elem)) {
return NULL;
}
while (id > 1) {
elem = elem->next;
--id;
}
return (LinphoneAuthInfo *) elem->data;
}
int Daemon::updateAudioStreamId(AudioStream *audio_stream) {
for (std::map<int, AudioStreamAndOther*>::iterator it = mAudioStreams.begin(); it != mAudioStreams.end(); ++it) {
if (it->second->stream == audio_stream)
......@@ -412,6 +425,7 @@ void Daemon::initCommands() {
mCommands.push_back(new ContactCommand());
mCommands.push_back(new RegisterStatusCommand());
mCommands.push_back(new UnregisterCommand());
mCommands.push_back(new AuthInfosClearCommand());
mCommands.push_back(new CallCommand());
mCommands.push_back(new TerminateCommand());
mCommands.push_back(new DtmfCommand());
......
......@@ -198,6 +198,7 @@ public:
const std::list<DaemonCommand*> &getCommandList() const;
LinphoneCall *findCall(int id);
LinphoneProxyConfig *findProxy(int id);
LinphoneAuthInfo *findAuthInfo(int id);
AudioStream *findAudioStream(int id);
AudioStreamAndOther *findAudioStreamAndOther(int id);
void removeAudioStream(int id);
......@@ -205,6 +206,7 @@ public:
int updateCallId(LinphoneCall *call);
int updateProxyId(LinphoneProxyConfig *proxy);
inline int maxProxyId() { return mProxyIds; }
inline int maxAuthInfoId() { return ms_list_size(linphone_core_get_auth_info_list(mLc)); }
int updateAudioStreamId(AudioStream *audio_stream);
void dumpCommandsHelp();
void dumpCommandsHelpHtml();
......
Markdown is supported
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