Commit e0a60bfd authored by Gabriel Margiani's avatar Gabriel Margiani

fixed copyright year, added some more hooks.

parent c205a4a4
/** /**
* This file is part of 3phone * This file is part of 3phone
* Copyright (C) 2015 Gabriel Margiani * Copyright (C) 2016 Gabriel Margiani
* *
* 3phone is free software: you can redistribute it and/or modify * 3phone is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -23,6 +23,7 @@ p3::account::account(sipphone& p) : phone(p) {}; ...@@ -23,6 +23,7 @@ p3::account::account(sipphone& p) : phone(p) {};
p3::account::~account() {}; p3::account::~account() {};
void p3::account::onRegState(pj::OnRegStateParam &prm) { void p3::account::onRegState(pj::OnRegStateParam &prm) {
phone.handle_registration_change(prm.code);
} }
void p3::account::onIncomingCall(pj::OnIncomingCallParam &iprm) { void p3::account::onIncomingCall(pj::OnIncomingCallParam &iprm) {
......
/** /**
* This file is part of 3phone * This file is part of 3phone
* Copyright (C) 2015 Gabriel Margiani * Copyright (C) 2016 Gabriel Margiani
* *
* 3phone is free software: you can redistribute it and/or modify * 3phone is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
......
/** /**
* This file is part of 3phone * This file is part of 3phone
* Copyright (C) 2015 Gabriel Margiani * Copyright (C) 2016 Gabriel Margiani
* *
* 3phone is free software: you can redistribute it and/or modify * 3phone is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -44,15 +44,16 @@ void p3::call::onCallState(pj::OnCallStateParam& prm) { ...@@ -44,15 +44,16 @@ void p3::call::onCallState(pj::OnCallStateParam& prm) {
pj::CallInfo ci = getInfo(); pj::CallInfo ci = getInfo();
switch (ci.state) { switch (ci.state) {
case PJSIP_INV_STATE_DISCONNECTED: case PJSIP_INV_STATE_DISCONNECTED:
phone.get_event_hook().run_hook("disconnected", p3id, get_nr()); phone.get_event_hook().run_call_hook("disconnected", p3id, get_nr());
state = p3::callState::NONE; state = p3::callState::NONE;
phone.delete_call(p3id); phone.delete_call(p3id);
break; break;
case PJSIP_INV_STATE_CALLING: case PJSIP_INV_STATE_CALLING:
phone.get_event_hook().run_call_hook("calling", p3id, get_nr());
state = p3::callState::CALLING; state = p3::callState::CALLING;
phone.get_event_hook().run_hook("calling", p3id, get_nr());
break; break;
case PJSIP_INV_STATE_CONFIRMED: case PJSIP_INV_STATE_CONFIRMED:
phone.get_event_hook().run_call_hook("confirmed", p3id, get_nr());
state = p3::callState::RUNNING; state = p3::callState::RUNNING;
if (ringing) { if (ringing) {
phone.stop_ringing(); phone.stop_ringing();
...@@ -61,12 +62,12 @@ void p3::call::onCallState(pj::OnCallStateParam& prm) { ...@@ -61,12 +62,12 @@ void p3::call::onCallState(pj::OnCallStateParam& prm) {
break; break;
case PJSIP_INV_STATE_EARLY: case PJSIP_INV_STATE_EARLY:
if (ci.role == PJSIP_ROLE_UAS) { if (ci.role == PJSIP_ROLE_UAS) {
phone.get_event_hook().run_call_hook("incoming", p3id, get_nr());
if (!ringing) { if (!ringing) {
phone.start_ringing(); phone.start_ringing();
ringing = true; ringing = true;
} }
state = p3::callState::INCOMING; state = p3::callState::INCOMING;
phone.get_event_hook().run_hook("incoming", p3id, get_nr());
} }
break; break;
case PJSIP_INV_STATE_NULL: case PJSIP_INV_STATE_NULL:
...@@ -166,3 +167,7 @@ void p3::call::mute_toggle() { ...@@ -166,3 +167,7 @@ void p3::call::mute_toggle() {
pj::AudioMedia* p3::call::get_audio_media() { pj::AudioMedia* p3::call::get_audio_media() {
return aud_med; return aud_med;
} }
void p3::call::onDtmfDigit(pj::OnDtmfDigitParam &prm) {
phone.get_event_hook().run_call_hook("dtmf", p3id, get_nr(), prm.digit);
}
/** /**
* This file is part of 3phone * This file is part of 3phone
* Copyright (C) 2015 Gabriel Margiani * Copyright (C) 2016 Gabriel Margiani
* *
* 3phone is free software: you can redistribute it and/or modify * 3phone is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -60,6 +60,8 @@ namespace p3 { ...@@ -60,6 +60,8 @@ namespace p3 {
void onCallMediaState(pj::OnCallMediaStateParam &prm); void onCallMediaState(pj::OnCallMediaStateParam &prm);
void onDtmfDigit(pj::OnDtmfDigitParam &prm);
pj::AudioMedia* get_audio_media(); pj::AudioMedia* get_audio_media();
int get_id(); int get_id();
......
/** /**
* This file is part of 3phone * This file is part of 3phone
* Copyright (C) 2015 Gabriel Margiani * Copyright (C) 2016 Gabriel Margiani
* *
* 3phone is free software: you can redistribute it and/or modify * 3phone is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -73,7 +73,7 @@ p3::client::client(int ac, char *av[]) : argv(av, av+ac), interactive(false), ve ...@@ -73,7 +73,7 @@ p3::client::client(int ac, char *av[]) : argv(av, av+ac), interactive(false), ve
connection = new mQueue(id, true, (verbose >= 4)); connection = new mQueue(id, true, (verbose >= 4));
ma.send(p3::protocol::HELLO, id); ma.send(p3::protocol::HELLO, id);
p3::mQueueMessage m = connection->receive(30); p3::mQueueMessage m = connection->receive(3);
if (m.get_command() != p3::protocol::OK) { if (m.get_command() != p3::protocol::OK) {
throw new p3::perror("client.connection", "cannot connect to server " + m.get_value()); throw new p3::perror("client.connection", "cannot connect to server " + m.get_value());
......
/** /**
* This file is part of 3phone * This file is part of 3phone
* Copyright (C) 2015 Gabriel Margiani * Copyright (C) 2016 Gabriel Margiani
* *
* 3phone is free software: you can redistribute it and/or modify * 3phone is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
......
/** /**
* This file is part of 3phone * This file is part of 3phone
* Copyright (C) 2015 Gabriel Margiani * Copyright (C) 2016 Gabriel Margiani
* *
* 3phone is free software: you can redistribute it and/or modify * 3phone is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
......
/** /**
* This file is part of 3phone * This file is part of 3phone
* Copyright (C) 2015 Gabriel Margiani * Copyright (C) 2016 Gabriel Margiani
* *
* 3phone is free software: you can redistribute it and/or modify * 3phone is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
......
/** /**
* This file is part of 3phone * This file is part of 3phone
* Copyright (C) 2015 Gabriel Margiani * Copyright (C) 2016 Gabriel Margiani
* *
* 3phone is free software: you can redistribute it and/or modify * 3phone is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
......
/** /**
* This file is part of 3phone * This file is part of 3phone
* Copyright (C) 2015 Gabriel Margiani * Copyright (C) 2016 Gabriel Margiani
* *
* 3phone is free software: you can redistribute it and/or modify * 3phone is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -22,20 +22,30 @@ ...@@ -22,20 +22,30 @@
#include "eventhook.h" #include "eventhook.h"
p3::eventHook::eventHook(config& c, phonebook& p) : conf(c), book(p), command(conf.get_string("hook:command")) { p3::eventHook::eventHook(config& c, phonebook& p) :
conf(c),
book(p),
command(conf.get_string("hook:command"))
{
signal(SIGCHLD, SIG_IGN); signal(SIGCHLD, SIG_IGN);
} }
void p3::eventHook::run_hook(std::string event, int cid, std::string nr) { void p3::eventHook::run_call_hook(std::string event, int cid, std::string nr, std::string data) {
run_hook(event, std::to_string(cid), nr, data);
}
void p3::eventHook::run_hook(std::string event, const std::string& a2, const std::string& a3, const std::string& a4) {
int pid = fork(); int pid = fork();
if (pid == 0) { if (pid == 0) {
execl( execl(
command.c_str(), command.c_str(),
command.c_str(), command.c_str(),
event.c_str(), event.c_str(),
std::to_string(cid).c_str(), a2.c_str(),
book.address_by_nr(nr).c_str(), a3.c_str(),
a4.c_str(),
(char *)0 (char *)0
); );
} }
} }
/** /**
* This file is part of 3phone * This file is part of 3phone
* Copyright (C) 2015 Gabriel Margiani * Copyright (C) 2016 Gabriel Margiani
* *
* 3phone is free software: you can redistribute it and/or modify * 3phone is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -32,9 +32,12 @@ namespace p3 { ...@@ -32,9 +32,12 @@ namespace p3 {
* script (eventHook::command, loaded from config during server init) * script (eventHook::command, loaded from config during server init)
* with the following arguments: * with the following arguments:
* 1: Event description given by the caller, see call/phone implementation * 1: Event description given by the caller, see call/phone implementation
* 2: The id of the call associated to the even. * 2,3,4: depending on the event.
* 3: The "Address" (as formatted by the phonebook) of the other party on *
* the call. * If the event is associated with call, they will be:
* 2: The id of the call associated to the event.
* 3: The "Address" (as formatted by the phonebook) of the other party on the call
* 4: event data
*/ */
class eventHook { class eventHook {
...@@ -48,7 +51,8 @@ namespace p3 { ...@@ -48,7 +51,8 @@ namespace p3 {
explicit eventHook(config& c, phonebook& p); explicit eventHook(config& c, phonebook& p);
void run_hook(std::string event, int call_id, std::string nr); void run_hook(std::string event, const std::string& a2 = "", const std::string& a3 = "", const std::string& a4 = "");
void run_call_hook(std::string event, int call_id = 0, std::string nr = "", std::string data = "");
}; };
} }
......
/** /**
* This file is part of 3phone * This file is part of 3phone
* Copyright (C) 2015 Gabriel Margiani * Copyright (C) 2016 Gabriel Margiani
* *
* 3phone is free software: you can redistribute it and/or modify * 3phone is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
......
/** /**
* This file is part of 3phone * This file is part of 3phone
* Copyright (C) 2015 Gabriel Margiani * Copyright (C) 2016 Gabriel Margiani
* *
* 3phone is free software: you can redistribute it and/or modify * 3phone is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
......
/** /**
* This file is part of 3phone * This file is part of 3phone
* Copyright (C) 2015 Gabriel Margiani * Copyright (C) 2016 Gabriel Margiani
* *
* 3phone is free software: you can redistribute it and/or modify * 3phone is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
......
/** /**
* This file is part of 3phone * This file is part of 3phone
* Copyright (C) 2015 Gabriel Margiani * Copyright (C) 2016 Gabriel Margiani
* *
* 3phone is free software: you can redistribute it and/or modify * 3phone is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
......
/** /**
* This file is part of 3phone * This file is part of 3phone
* Copyright (C) 2015 Gabriel Margiani * Copyright (C) 2016 Gabriel Margiani
* *
* 3phone is free software: you can redistribute it and/or modify * 3phone is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
......
/** /**
* This file is part of 3phone * This file is part of 3phone
* Copyright (C) 2015 Gabriel Margiani * Copyright (C) 2016 Gabriel Margiani
* *
* 3phone is free software: you can redistribute it and/or modify * 3phone is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
......
/** /**
* This file is part of 3phone * This file is part of 3phone
* Copyright (C) 2015 Gabriel Margiani * Copyright (C) 2016 Gabriel Margiani
* *
* 3phone is free software: you can redistribute it and/or modify * 3phone is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -65,9 +65,11 @@ p3::server::~server() { ...@@ -65,9 +65,11 @@ p3::server::~server() {
std::this_thread::sleep_for(std::chrono::milliseconds(200)); std::this_thread::sleep_for(std::chrono::milliseconds(200));
} }
finish_threads(); finish_threads();
hook.run_hook("shutdown");
} }
void p3::server::run() { void p3::server::run() {
hook.run_hook("running");
try { try {
bool r = true; bool r = true;
while (r) { while (r) {
......
/** /**
* This file is part of 3phone * This file is part of 3phone
* Copyright (C) 2015 Gabriel Margiani * Copyright (C) 2016 Gabriel Margiani
* *
* 3phone is free software: you can redistribute it and/or modify * 3phone is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
......
/** /**
* This file is part of 3phone * This file is part of 3phone
* Copyright (C) 2015 Gabriel Margiani * Copyright (C) 2016 Gabriel Margiani
* *
* 3phone is free software: you can redistribute it and/or modify * 3phone is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -44,7 +44,7 @@ p3::sipphone::sipphone(p3::config& c, p3::eventHook& e, p3::phonebook& b) : ...@@ -44,7 +44,7 @@ p3::sipphone::sipphone(p3::config& c, p3::eventHook& e, p3::phonebook& b) :
pj::EpConfig ep_cfg; pj::EpConfig ep_cfg;
ep_cfg.logConfig.level = conf.get_int("pj:log_level"); ep_cfg.logConfig.level = conf.get_int("pj:log_level");
ep_cfg.uaConfig.maxCalls = conf.get_int("pj:max_calls"); ep_cfg.uaConfig.maxCalls = conf.get_int("pj:max_calls");
ep_cfg.uaConfig.userAgent = "3phone, (c) 2015 Gabriel Margiani"; ep_cfg.uaConfig.userAgent = "3phone, (c) 2016 Gabriel Margiani";
ep_cfg.medConfig.sndClockRate = 16000; ep_cfg.medConfig.sndClockRate = 16000;
endpoint->libInit(ep_cfg); endpoint->libInit(ep_cfg);
} catch(pj::Error& error) { } catch(pj::Error& error) {
...@@ -271,6 +271,7 @@ void p3::sipphone::busy(int id) { ...@@ -271,6 +271,7 @@ void p3::sipphone::busy(int id) {
void p3::sipphone::busyall_toggle() { void p3::sipphone::busyall_toggle() {
always_busy = !always_busy; always_busy = !always_busy;
eventhook.run_hook("busyall_toggle", std::to_string(always_busy));
} }
void p3::sipphone::hold_toggle(int id) { void p3::sipphone::hold_toggle(int id) {
...@@ -305,6 +306,7 @@ void p3::sipphone::global_mute_toggle() { ...@@ -305,6 +306,7 @@ void p3::sipphone::global_mute_toggle() {
mgr.getCaptureDevMedia().adjustTxLevel(0); mgr.getCaptureDevMedia().adjustTxLevel(0);
mute = true; mute = true;
} }
eventhook.run_hook("muteall_toggle", std::to_string(mute));
} catch (pj::Error& e) { } catch (pj::Error& e) {
throw p3::perror("sipphone:gmutetoggle", e.info()); throw p3::perror("sipphone:gmutetoggle", e.info());
} }
...@@ -428,7 +430,6 @@ std::map<std::string, std::string> p3::sipphone::get_status_dump() { ...@@ -428,7 +430,6 @@ std::map<std::string, std::string> p3::sipphone::get_status_dump() {
l["regURI"] = ri.uri; l["regURI"] = ri.uri;
l["regStatus"] = std::to_string(ri.regStatus); l["regStatus"] = std::to_string(ri.regStatus);
l["regStatusText"] = ri.regStatusText; l["regStatusText"] = ri.regStatusText;
l["regError"] = ri.regLastErr;
// calls // calls
l["callCount"] = std::to_string(get_call_count()); l["callCount"] = std::to_string(get_call_count());
...@@ -442,6 +443,10 @@ std::map<std::string, std::string> p3::sipphone::get_status_dump() { ...@@ -442,6 +443,10 @@ std::map<std::string, std::string> p3::sipphone::get_status_dump() {
return l; return l;
} }
void p3::sipphone::handle_registration_change(int s) {
pj::AccountInfo ri = acc->getInfo();
eventhook.run_hook("registration_change", std::to_string(ri.regStatus), ri.regStatusText);
}
p3::eventHook& p3::sipphone::get_event_hook() { p3::eventHook& p3::sipphone::get_event_hook() {
......
/** /**
* This file is part of 3phone * This file is part of 3phone
* Copyright (C) 2015 Gabriel Margiani * Copyright (C) 2016 Gabriel Margiani
* *
* 3phone is free software: you can redistribute it and/or modify * 3phone is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -81,6 +81,7 @@ namespace p3 { ...@@ -81,6 +81,7 @@ namespace p3 {
void unregister_number(std::string nr); void unregister_number(std::string nr);
void handle_incoming_call (int pjid = PJSUA_INVALID_ID); void handle_incoming_call (int pjid = PJSUA_INVALID_ID);
void handle_registration_change (int status);
public: public:
......
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