Commit 26be4d8d authored by Tristan Matthews's avatar Tristan Matthews Committed by Tristan Matthews

daemon: hookpreference: cleanup

parent 8d2ccf70
...@@ -389,13 +389,13 @@ void ConfigurationManager::setAddressbookList( ...@@ -389,13 +389,13 @@ void ConfigurationManager::setAddressbookList(
std::map<std::string, std::string> ConfigurationManager::getHookSettings() std::map<std::string, std::string> ConfigurationManager::getHookSettings()
{ {
return Manager::instance().getHookSettings(); return Manager::instance().hookPreference.toMap();
} }
void ConfigurationManager::setHookSettings(const std::map<std::string, void ConfigurationManager::setHookSettings(const std::map<std::string,
std::string>& settings) std::string>& settings)
{ {
Manager::instance().setHookSettings(settings); Manager::instance().hookPreference = HookPreference(settings);
} }
void ConfigurationManager::setAccountsOrder(const std::string& order) void ConfigurationManager::setAccountsOrder(const std::string& order)
......
...@@ -191,9 +191,7 @@ bool ManagerImpl::outgoingCall(const std::string& account_id, ...@@ -191,9 +191,7 @@ bool ManagerImpl::outgoingCall(const std::string& account_id,
std::string current_call_id(getCurrentCallId()); std::string current_call_id(getCurrentCallId());
std::string prefix; std::string prefix(hookPreference.getNumberAddPrefix());
if (hookPreference.getNumberEnabled())
prefix = hookPreference.getNumberAddPrefix();
std::string to_cleaned(NumberCleaner::clean(to, prefix)); std::string to_cleaned(NumberCleaner::clean(to, prefix));
...@@ -2748,30 +2746,6 @@ std::vector<std::string> ManagerImpl::getAddressbookList() const ...@@ -2748,30 +2746,6 @@ std::vector<std::string> ManagerImpl::getAddressbookList() const
return unserialize(addressbookPreference.getList()); return unserialize(addressbookPreference.getList());
} }
std::map<std::string, std::string> ManagerImpl::getHookSettings() const
{
std::map<std::string, std::string> settings;
settings["URLHOOK_IAX2_ENABLED"] = hookPreference.getIax2Enabled() ? "true" : "false";
settings["PHONE_NUMBER_HOOK_ADD_PREFIX"] = hookPreference.getNumberAddPrefix();
settings["PHONE_NUMBER_HOOK_ENABLED"] = hookPreference.getNumberEnabled() ? "true" : "false";
settings["URLHOOK_SIP_ENABLED"] = hookPreference.getSipEnabled() ? "true" : "false";
settings["URLHOOK_COMMAND"] = hookPreference.getUrlCommand();
settings["URLHOOK_SIP_FIELD"] = hookPreference.getUrlSipField();
return settings;
}
void ManagerImpl::setHookSettings(const std::map<std::string, std::string>& settings)
{
hookPreference.setIax2Enabled(settings.find("URLHOOK_IAX2_ENABLED")->second == "true");
hookPreference.setNumberAddPrefix(settings.find("PHONE_NUMBER_HOOK_ADD_PREFIX")->second);
hookPreference.setNumberEnabled(settings.find("PHONE_NUMBER_HOOK_ENABLED")->second == "true");
hookPreference.setSipEnabled(settings.find("URLHOOK_SIP_ENABLED")->second == "true");
hookPreference.setUrlCommand(settings.find("URLHOOK_COMMAND")->second);
hookPreference.setUrlSipField(settings.find("URLHOOK_SIP_FIELD")->second);
}
void ManagerImpl::setIPToIPForCall(const std::string& callID, bool IPToIP) void ManagerImpl::setIPToIPForCall(const std::string& callID, bool IPToIP)
{ {
if (not isIPToIP(callID)) // no IPToIP calls with the same ID if (not isIPToIP(callID)) // no IPToIP calls with the same ID
......
...@@ -691,17 +691,6 @@ class ManagerImpl { ...@@ -691,17 +691,6 @@ class ManagerImpl {
*/ */
std::vector <std::string> getAddressbookList() const; std::vector <std::string> getAddressbookList() const;
/**
* Hook configuration
*/
std::map<std::string, std::string> getHookSettings() const;
/**
* Hook configuration
*/
void setHookSettings(const std::map<std::string, std::string>& settings);
/** /**
* Get the audio manager * Get the audio manager
* @return int The audio manager * @return int The audio manager
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "audio/pulseaudio/pulselayer.h" #include "audio/pulseaudio/pulselayer.h"
#include "config/yamlemitter.h" #include "config/yamlemitter.h"
#include "config/yamlnode.h" #include "config/yamlnode.h"
#include "hooks/urlhook.h"
#include <sstream> #include <sstream>
#include "global.h" #include "global.h"
#include <cassert> #include <cassert>
...@@ -216,6 +217,28 @@ HookPreference::HookPreference() : iax2Enabled_(false) ...@@ -216,6 +217,28 @@ HookPreference::HookPreference() : iax2Enabled_(false)
, urlSipField_("X-sflphone-url") , urlSipField_("X-sflphone-url")
{} {}
HookPreference::HookPreference(const std::map<std::string, std::string> &settings) :
iax2Enabled_(settings.find("URLHOOK_IAX2_ENABLED")->second == "true")
, numberAddPrefix_(settings.find("PHONE_NUMBER_HOOK_ADD_PREFIX")->second)
, numberEnabled_(settings.find("PHONE_NUMBER_HOOK_ENABLED")->second == "true")
, sipEnabled_(settings.find("URLHOOK_SIP_ENABLED")->second == "true")
, urlCommand_(settings.find("URLHOOK_COMMAND")->second)
, urlSipField_(settings.find("URLHOOK_SIP_FIELD")->second)
{}
std::map<std::string, std::string> HookPreference::toMap() const
{
std::map<std::string, std::string> settings;
settings["URLHOOK_IAX2_ENABLED"] = iax2Enabled_ ? "true" : "false";
settings["PHONE_NUMBER_HOOK_ADD_PREFIX"] = numberAddPrefix_;
settings["PHONE_NUMBER_HOOK_ENABLED"] = numberEnabled_ ? "true" : "false";
settings["URLHOOK_SIP_ENABLED"] = sipEnabled_ ? "true" : "false";
settings["URLHOOK_COMMAND"] = urlCommand_;
settings["URLHOOK_SIP_FIELD"] = urlSipField_;
return settings;
}
void HookPreference::serialize(Conf::YamlEmitter *emitter) void HookPreference::serialize(Conf::YamlEmitter *emitter)
{ {
Conf::MappingNode preferencemap(NULL); Conf::MappingNode preferencemap(NULL);
...@@ -252,6 +275,11 @@ void HookPreference::unserialize(const Conf::MappingNode *map) ...@@ -252,6 +275,11 @@ void HookPreference::unserialize(const Conf::MappingNode *map)
map->getValue(urlSipFieldKey, &urlSipField_); map->getValue(urlSipFieldKey, &urlSipField_);
} }
void HookPreference::run(const std::string &header)
{
UrlHook::runAction(urlCommand_, header);
}
AudioPreference::AudioPreference() : AudioPreference::AudioPreference() :
audioApi_(PULSEAUDIO_API_STR) audioApi_(PULSEAUDIO_API_STR)
, cardin_(atoi(ALSA_DFT_CARD)) // ALSA_DFT_CARD , cardin_(atoi(ALSA_DFT_CARD)) // ALSA_DFT_CARD
......
...@@ -335,56 +335,23 @@ class AddressbookPreference : public Serializable { ...@@ -335,56 +335,23 @@ class AddressbookPreference : public Serializable {
class HookPreference : public Serializable { class HookPreference : public Serializable {
public: public:
HookPreference(); HookPreference();
HookPreference(const std::map<std::string, std::string> &settings);
virtual void serialize(Conf::YamlEmitter *emitter); virtual void serialize(Conf::YamlEmitter *emitter);
virtual void unserialize(const Conf::MappingNode *map); virtual void unserialize(const Conf::MappingNode *map);
bool getIax2Enabled() const {
return iax2Enabled_;
}
void setIax2Enabled(bool i) {
iax2Enabled_ = i;
}
std::string getNumberAddPrefix() const { std::string getNumberAddPrefix() const {
return numberAddPrefix_; if (numberEnabled_)
} return numberAddPrefix_;
else
void setNumberAddPrefix(const std::string &n) { return "";
numberAddPrefix_ = n;
}
bool getNumberEnabled() const {
return numberEnabled_;
}
void setNumberEnabled(bool n) {
numberEnabled_ = n;
} }
bool getSipEnabled() const { std::map<std::string, std::string> toMap() const;
return sipEnabled_; bool getSipEnabled() const { return sipEnabled_; }
} std::string getUrlSipField() const { return urlSipField_; }
void run(const std::string &header);
void setSipEnabled(bool s) {
sipEnabled_ = s;
}
std::string getUrlCommand() const {
return urlCommand_;
}
void setUrlCommand(const std::string &u) {
urlCommand_ = u;
}
std::string getUrlSipField() const {
return urlSipField_;
}
void setUrlSipField(const std::string &u) {
urlSipField_ = u;
}
private: private:
bool iax2Enabled_; bool iax2Enabled_;
...@@ -393,7 +360,6 @@ class HookPreference : public Serializable { ...@@ -393,7 +360,6 @@ class HookPreference : public Serializable {
bool sipEnabled_; bool sipEnabled_;
std::string urlCommand_; std::string urlCommand_;
std::string urlSipField_; std::string urlSipField_;
}; };
class AudioPreference : public Serializable { class AudioPreference : public Serializable {
......
...@@ -48,7 +48,6 @@ ...@@ -48,7 +48,6 @@
#include "dbus/dbusmanager.h" #include "dbus/dbusmanager.h"
#include "dbus/callmanager.h" #include "dbus/callmanager.h"
#include "hooks/urlhook.h"
#include "im/instant_messaging.h" #include "im/instant_messaging.h"
#include "audio/audiolayer.h" #include "audio/audiolayer.h"
...@@ -309,7 +308,7 @@ pj_bool_t transaction_request_cb(pjsip_rx_data *rdata) ...@@ -309,7 +308,7 @@ pj_bool_t transaction_request_cb(pjsip_rx_data *rdata)
if (Manager::instance().hookPreference.getSipEnabled()) { if (Manager::instance().hookPreference.getSipEnabled()) {
std::string header_value(fetchHeaderValue(rdata->msg_info.msg, Manager::instance().hookPreference.getUrlSipField())); std::string header_value(fetchHeaderValue(rdata->msg_info.msg, Manager::instance().hookPreference.getUrlSipField()));
UrlHook::runAction(Manager::instance().hookPreference.getUrlCommand(), header_value); Manager::instance().hookPreference.run(header_value);
} }
SIPCall* call = new SIPCall(Manager::instance().getNewCallID(), Call::INCOMING, cp_); SIPCall* call = new SIPCall(Manager::instance().getNewCallID(), Call::INCOMING, cp_);
...@@ -2126,14 +2125,14 @@ std::string fetchHeaderValue(pjsip_msg *msg, const std::string &field) ...@@ -2126,14 +2125,14 @@ std::string fetchHeaderValue(pjsip_msg *msg, const std::string &field)
if (!hdr) if (!hdr)
return ""; return "";
std::string value(std::string(hdr->hvalue.ptr, hdr->hvalue.slen)); std::string value(hdr->hvalue.ptr, hdr->hvalue.slen);
size_t pos = value.find("\n"); size_t pos = value.find("\n");
if (pos == std::string::npos) if (pos != std::string::npos)
return value.substr(0, pos);
else
return ""; return "";
return value.substr(0, pos);
} }
} // end anonymous namespace } // end anonymous namespace
......
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