Loading src/call.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -65,8 +65,8 @@ void p3::call::onCallState(pj::OnCallStateParam& prm) { phone.start_ringing(); ringing = true; } state = p3::callState::INCOMMING; phone.get_event_hook().run_hook("incomming", p3id, get_nr()); state = p3::callState::INCOMING; phone.get_event_hook().run_hook("incoming", p3id, get_nr()); } break; case PJSIP_INV_STATE_NULL: Loading src/call.h +1 −1 Original line number Diff line number Diff line Loading @@ -31,7 +31,7 @@ namespace p3 { enum class callState: char { NONE = 'X', CALLING = 'c', INCOMMING = '*', INCOMING = '*', RUNNING = ' ', HOLDING = '&' }; Loading src/eventhook.cpp +7 −1 Original line number Diff line number Diff line Loading @@ -22,11 +22,17 @@ #include "eventhook.h" p3::eventHook::eventHook(std::string c, phonebook& p) : command(c), book(p) { p3::eventHook::eventHook(config& c, phonebook& p) : conf(c), book(p), command(conf.get_string("hook:command")) { signal(SIGCHLD, SIG_IGN); } void p3::eventHook::run_hook(std::string event, int cid, std::string nr) { // TODO: Think of a better place for this if (conf.get_bool("phonebook:auto_add_unanswered")) { book.add(nr); } int pid = fork(); if (pid == 0) { execl( Loading src/eventhook.h +5 −3 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ #include <string> #include "phonebook.h" #include "config.h" namespace p3 { Loading @@ -38,13 +39,14 @@ namespace p3 { class eventHook { std::string command; config& conf; phonebook& book; std::string command; public: explicit eventHook(std::string c, phonebook& p); explicit eventHook(config& c, phonebook& p); void run_hook(std::string event, int call_id, std::string nr); }; Loading src/phonebook.cpp +5 −3 Original line number Diff line number Diff line Loading @@ -70,7 +70,7 @@ void p3::phonebook::add(const std::string& nr) { if (nr.empty() || index.count(nr)) return; std::regex rnm("\"(.*)\""); std::regex rnr("sip:(.*)@(.*)>?"); std::regex rnr("<sip:(.*)@(.*)>"); std::smatch match; std::string name(""); Loading @@ -87,6 +87,8 @@ void p3::phonebook::add(const std::string& nr) { } } if (index.count(num)) return; // number already there data[id_count] = {num, name, ""}; index[num] = id_count; if (!name.empty()) index[name] = id_count; Loading @@ -98,7 +100,7 @@ void p3::phonebook::add(const std::string& nr) { ); if (f) { f << name << "\t< " << num << "\t<" << std::endl; f << name << "\t> " << num << "\t>" << std::endl; } } Loading Loading @@ -133,7 +135,7 @@ std::string p3::phonebook::uri_by_nr(const std::string& nr) { int id = index.at(nr); return "\"" + data[id][1] + "\" <sip:" + nr + "@" + conf->get_string("phnebook:default_uri") + conf->get_string("phonebook:default_uri") + ">"; } catch (std::out_of_range& e) { return "<sip:" + nr + "@" + Loading Loading
src/call.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -65,8 +65,8 @@ void p3::call::onCallState(pj::OnCallStateParam& prm) { phone.start_ringing(); ringing = true; } state = p3::callState::INCOMMING; phone.get_event_hook().run_hook("incomming", p3id, get_nr()); state = p3::callState::INCOMING; phone.get_event_hook().run_hook("incoming", p3id, get_nr()); } break; case PJSIP_INV_STATE_NULL: Loading
src/call.h +1 −1 Original line number Diff line number Diff line Loading @@ -31,7 +31,7 @@ namespace p3 { enum class callState: char { NONE = 'X', CALLING = 'c', INCOMMING = '*', INCOMING = '*', RUNNING = ' ', HOLDING = '&' }; Loading
src/eventhook.cpp +7 −1 Original line number Diff line number Diff line Loading @@ -22,11 +22,17 @@ #include "eventhook.h" p3::eventHook::eventHook(std::string c, phonebook& p) : command(c), book(p) { p3::eventHook::eventHook(config& c, phonebook& p) : conf(c), book(p), command(conf.get_string("hook:command")) { signal(SIGCHLD, SIG_IGN); } void p3::eventHook::run_hook(std::string event, int cid, std::string nr) { // TODO: Think of a better place for this if (conf.get_bool("phonebook:auto_add_unanswered")) { book.add(nr); } int pid = fork(); if (pid == 0) { execl( Loading
src/eventhook.h +5 −3 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ #include <string> #include "phonebook.h" #include "config.h" namespace p3 { Loading @@ -38,13 +39,14 @@ namespace p3 { class eventHook { std::string command; config& conf; phonebook& book; std::string command; public: explicit eventHook(std::string c, phonebook& p); explicit eventHook(config& c, phonebook& p); void run_hook(std::string event, int call_id, std::string nr); }; Loading
src/phonebook.cpp +5 −3 Original line number Diff line number Diff line Loading @@ -70,7 +70,7 @@ void p3::phonebook::add(const std::string& nr) { if (nr.empty() || index.count(nr)) return; std::regex rnm("\"(.*)\""); std::regex rnr("sip:(.*)@(.*)>?"); std::regex rnr("<sip:(.*)@(.*)>"); std::smatch match; std::string name(""); Loading @@ -87,6 +87,8 @@ void p3::phonebook::add(const std::string& nr) { } } if (index.count(num)) return; // number already there data[id_count] = {num, name, ""}; index[num] = id_count; if (!name.empty()) index[name] = id_count; Loading @@ -98,7 +100,7 @@ void p3::phonebook::add(const std::string& nr) { ); if (f) { f << name << "\t< " << num << "\t<" << std::endl; f << name << "\t> " << num << "\t>" << std::endl; } } Loading Loading @@ -133,7 +135,7 @@ std::string p3::phonebook::uri_by_nr(const std::string& nr) { int id = index.at(nr); return "\"" + data[id][1] + "\" <sip:" + nr + "@" + conf->get_string("phnebook:default_uri") + conf->get_string("phonebook:default_uri") + ">"; } catch (std::out_of_range& e) { return "<sip:" + nr + "@" + Loading