Commit 1c4fd526 authored by Gabriel Margiani's avatar Gabriel Margiani
Browse files

add allways to phonebook if needed.

parent dab806af
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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:
+1 −1
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ namespace p3 {
	enum class callState: char {
		NONE = 'X',
		CALLING = 'c',
		INCOMMING = '*',
		INCOMING = '*',
		RUNNING = ' ',
		HOLDING = '&'
	};
+7 −1
Original line number Diff line number Diff line
@@ -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(
+5 −3
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@
#include <string>

#include "phonebook.h"
#include "config.h"

namespace p3 {

@@ -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);
	};
+5 −3
Original line number Diff line number Diff line
@@ -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("");
@@ -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;
@@ -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;
	}
}

@@ -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