diff --git a/daemon/src/call.h b/daemon/src/call.h index da702a7e312490d001820a0cf80011255912a1a7..b6d4ce59c63b48fde228cbd226f7200889eba30a 100644 --- a/daemon/src/call.h +++ b/daemon/src/call.h @@ -174,6 +174,8 @@ class Call : public Recordable { isIPToIP_ = IPToIP; } + virtual void answer() = 0; + /** * Set my IP [not protected] * @param ip The local IP address diff --git a/daemon/src/iax/iaxcall.cpp b/daemon/src/iax/iaxcall.cpp index a1eb21ec93ac7f467f43094922af9eb1d4301402..2b09b4944fbbeb18685d916e072fb464f4c8b870 100644 --- a/daemon/src/iax/iaxcall.cpp +++ b/daemon/src/iax/iaxcall.cpp @@ -29,6 +29,9 @@ * as that of the covered work. */ +#include <cstring> +#include <sys/socket.h> +#include <iax-client.h> #include "iaxcall.h" #include "iax2/frame.h" #include "account.h" @@ -115,3 +118,8 @@ int IAXCall::getAudioCodec() const return -1; } } + +void IAXCall::answer() +{ + iax_answer(session); +} diff --git a/daemon/src/iax/iaxcall.h b/daemon/src/iax/iaxcall.h index b2822520398726543001c18ad02f581f2462f43e..d97b838d35cabb04b377ae3183b7262c5932303e 100644 --- a/daemon/src/iax/iaxcall.h +++ b/daemon/src/iax/iaxcall.h @@ -74,6 +74,7 @@ class IAXCall : public Call { int format; iax_session* session; private: + virtual void answer(); NON_COPYABLE(IAXCall); }; diff --git a/daemon/src/iax/iaxvoiplink.cpp b/daemon/src/iax/iaxvoiplink.cpp index 1b4cf25c763e137dadb57c4832c2ad661cff0014..17b11d52a86a28fb03ed7f07cfcbb3e338cb57f3 100644 --- a/daemon/src/iax/iaxvoiplink.cpp +++ b/daemon/src/iax/iaxvoiplink.cpp @@ -255,14 +255,12 @@ IAXVoIPLink::newOutgoingCall(const std::string& id, const std::string& toUrl) void -IAXVoIPLink::answer(Call *c) +IAXVoIPLink::answer(Call *call) { - IAXCall* call = dynamic_cast<IAXCall*>(c); - Manager::instance().addStream(call->getCallId()); mutexIAX_.enter(); - iax_answer(call->session); + call->answer(); mutexIAX_.leave(); call->setState(Call::ACTIVE); diff --git a/daemon/src/managerimpl.cpp b/daemon/src/managerimpl.cpp index 7ace5bc58a99570487808262383fbc8b15f95aee..4c1e8cbc4f07e259d2073af9acfdfeb8df0e08b9 100644 --- a/daemon/src/managerimpl.cpp +++ b/daemon/src/managerimpl.cpp @@ -292,7 +292,7 @@ bool ManagerImpl::answerCall(const std::string& call_id) try { getAccountLink(account_id)->answer(call); - } catch (const VoipLinkException &e) { + } catch (const std::runtime_error &e) { ERROR("Manager: Error: %s", e.what()); } diff --git a/daemon/src/sip/sipcall.cpp b/daemon/src/sip/sipcall.cpp index dd31f3bdc387e2db9490d1602a5fc0defc73a56e..9c5c9d584027dbcb22ee0b7f427b5b2426ac23e6 100644 --- a/daemon/src/sip/sipcall.cpp +++ b/daemon/src/sip/sipcall.cpp @@ -53,3 +53,16 @@ SIPCall::~SIPCall() delete local_sdp_; pj_pool_release(pool_); } + +void SIPCall::answer() +{ + pjsip_tx_data *tdata; + if (pjsip_inv_answer(inv, PJSIP_SC_OK, NULL, NULL, &tdata) != PJ_SUCCESS) + throw std::runtime_error("Could not init invite request answer (200 OK)"); + + if (pjsip_inv_send_msg(inv, tdata) != PJ_SUCCESS) + throw std::runtime_error("Could not send invite request answer (200 OK)"); + + setConnectionState(CONNECTED); + setState(ACTIVE); +} diff --git a/daemon/src/sip/sipcall.h b/daemon/src/sip/sipcall.h index dab99795a77a66809277723be08e990e28b25248..249d3b7976bafd949dc465cf5a480c87581b78b9 100644 --- a/daemon/src/sip/sipcall.h +++ b/daemon/src/sip/sipcall.h @@ -89,6 +89,7 @@ class SIPCall : public Call { pjsip_inv_session *inv; private: + virtual void answer(); NON_COPYABLE(SIPCall); diff --git a/daemon/src/sip/sipvoiplink.cpp b/daemon/src/sip/sipvoiplink.cpp index 9415cbe46f57a024377ecee7f001621c4c55a053..dfd8f6a5032ec2f29f31a22491a0d124ee3ce1df 100644 --- a/daemon/src/sip/sipvoiplink.cpp +++ b/daemon/src/sip/sipvoiplink.cpp @@ -651,29 +651,24 @@ void SIPVoIPLink::sendUnregister(Account *a) account->setRegister(false); } -void SIPVoIPLink::registerKeepAliveTimer(pj_timer_entry& timer, pj_time_val& delay) +void SIPVoIPLink::registerKeepAliveTimer(pj_timer_entry &timer, pj_time_val &delay) { - pj_status_t status; - - DEBUG("UserAgent: Registering keep alive timer"); - - if(timer.id == -1) { + if (timer.id == -1) WARN("UserAgent: Timer already scheduled"); - } - - status = pjsip_endpt_schedule_timer(endpt_, &timer, &delay); - if (status != PJ_SUCCESS) { - ERROR("UserAgent: Could not schedule new timer in pjsip endpoint"); - } - if(status == PJ_EINVAL) { - ERROR("UserAgent: Invalid timer or delay entry"); - } - - if(status == PJ_EINVALIDOP) { - ERROR("Invalid timer entry, maybe already scheduled"); + switch (pjsip_endpt_schedule_timer(endpt_, &timer, &delay)) { + case PJ_SUCCESS: + break; + default: + ERROR("UserAgent: Could not schedule new timer in pjsip endpoint"); + /* fallthrough */ + case PJ_EINVAL: + ERROR("UserAgent: Invalid timer or delay entry"); + break; + case PJ_EINVALIDOP: + ERROR("Invalid timer entry, maybe already scheduled"); + break; } - } void SIPVoIPLink::cancelKeepAliveTimer(pj_timer_entry& timer) @@ -749,23 +744,11 @@ Call *SIPVoIPLink::newOutgoingCall(const std::string& id, const std::string& toU } void -SIPVoIPLink::answer(Call *c) +SIPVoIPLink::answer(Call *call) { - SIPCall *call = dynamic_cast<SIPCall*>(c); - if (!call) return; - - pjsip_tx_data *tdata; - - if (pjsip_inv_answer(call->inv, PJSIP_SC_OK, NULL, NULL, &tdata) != PJ_SUCCESS) - throw VoipLinkException("Could not init invite request answer (200 OK)"); - - if (pjsip_inv_send_msg(call->inv, tdata) != PJ_SUCCESS) - throw VoipLinkException("Could not send invite request answer (200 OK)"); - - call->setConnectionState(Call::CONNECTED); - call->setState(Call::ACTIVE); + call->answer(); } void