diff --git a/daemon/src/iax/iaxaccount.cpp b/daemon/src/iax/iaxaccount.cpp index 59d89755c033c67b3ba7952258a23ce36bcb4354..d4a216848216f867ce018752773c28d2bc10ba4f 100644 --- a/daemon/src/iax/iaxaccount.cpp +++ b/daemon/src/iax/iaxaccount.cpp @@ -45,7 +45,6 @@ IAXAccount::IAXAccount (const std::string& accountID) IAXAccount::~IAXAccount() { delete _link; - _link = NULL; } void IAXAccount::serialize (Conf::YamlEmitter *emitter) @@ -172,7 +171,7 @@ int IAXAccount::registerVoIPLink() setHostname (_hostname); setUsername (_username); - _link->sendRegister (_accountID); + _link->sendRegister (this); } catch(VoipLinkException &e) { _error("IAXAccount: %s", e.what()); @@ -185,7 +184,7 @@ int IAXAccount::unregisterVoIPLink() { try { - _link->sendUnregister (_accountID); + _link->sendUnregister (this); _link->terminate(); return 0; diff --git a/daemon/src/iax/iaxvoiplink.cpp b/daemon/src/iax/iaxvoiplink.cpp index da362ab76595dcd5b4b52fdbb853be6de4d62f88..d639b8f16af131d6e18b2a5e7c21f664e9c10904 100644 --- a/daemon/src/iax/iaxvoiplink.cpp +++ b/daemon/src/iax/iaxvoiplink.cpp @@ -88,14 +88,12 @@ IAXVoIPLink::~IAXVoIPLink() delete converter; } -bool +void IAXVoIPLink::init() { // If it was done, don't do it again, until we call terminate() - if (initDone()) - return false; - - bool returnValue = false; + if (_initDone) + return; // _localAddress = "127.0.0.1"; // port 0 is default @@ -119,7 +117,6 @@ IAXVoIPLink::init() } else { _debug ("IAX Info: listening on port %d", last_port); _localPort = last_port; - returnValue = true; _evThread->start(); audiolayer = Manager::instance().getAudioDriver(); @@ -132,23 +129,21 @@ IAXVoIPLink::init() nbTry--; - initDone (true); + _initDone = true; } if (port == IAX_FAILURE || nbTry==0) { _debug ("Fail to initialize iax"); - initDone (false); + _initDone = false; } - - return returnValue; } void IAXVoIPLink::terminate() { // If it was done, don't do it again, until we call init() - if (!initDone()) + if (!_initDone) return; // iaxc_shutdown(); @@ -156,7 +151,7 @@ IAXVoIPLink::terminate() // Hangup all calls terminateIAXCall(); - initDone (false); + _initDone = false; } void @@ -222,16 +217,6 @@ IAXVoIPLink::getEvent() sendAudioFromMic(); - // Manager::instance().getAudioLayerMutex()->leave(); - - // Do the doodle-moodle to send audio from the microphone to the IAX channel. - // sendAudioFromMic(); - - // Refresh registration. - if (_nextRefreshStamp && _nextRefreshStamp - 2 < time (NULL)) { - sendRegister (""); - } - // thread wait 3 millisecond _evThread->sleep (3); @@ -314,15 +299,11 @@ IAXVoIPLink::getIAXCall (const std::string& id) void -IAXVoIPLink::sendRegister (std::string id UNUSED) throw(VoipLinkException) +IAXVoIPLink::sendRegister (Account *a) throw(VoipLinkException) { _debug ("IAX: Sending registration"); - IAXAccount *account = getAccountPtr(); - - if (!account) { - throw VoipLinkException("Account is NULL in send register"); - } + IAXAccount *account = (IAXAccount*)a; if (account->getHostname().empty()) { throw VoipLinkException("Account hostname is empty"); @@ -360,15 +341,11 @@ IAXVoIPLink::sendRegister (std::string id UNUSED) throw(VoipLinkException) } void -IAXVoIPLink::sendUnregister (std::string id UNUSED) throw(VoipLinkException) +IAXVoIPLink::sendUnregister (Account *a) { _debug ("IAXVoipLink: Send unregister"); - IAXAccount *account = getAccountPtr(); - - if (!account) { - throw VoipLinkException("Account is NULL in send unregister"); - } + IAXAccount *account = (IAXAccount*)a; _mutexIAX.enterMutex(); @@ -410,16 +387,14 @@ IAXVoIPLink::newOutgoingCall (const std::string& id, const std::string& toUrl) t } -bool -IAXVoIPLink::answer (const std::string& id) throw (VoipLinkException) +void +IAXVoIPLink::answer (Call *c) throw (VoipLinkException) { - IAXCall* call = getIAXCall (id); + IAXCall* call = (IAXCall*) c; call->setCodecMap (Manager::instance().getAudioCodecFactory()); Manager::instance().addStream (call->getCallId()); - CHK_VALID_CALL; - _mutexIAX.enterMutex(); iax_answer (call->getSession()); _mutexIAX.leaveMutex(); @@ -429,11 +404,9 @@ IAXVoIPLink::answer (const std::string& id) throw (VoipLinkException) // Flush main buffer audiolayer->flushMain(); - - return true; } -bool +void IAXVoIPLink::hangup (const std::string& id) throw (VoipLinkException) { _debug ("IAXVoIPLink: Hangup"); @@ -443,8 +416,6 @@ IAXVoIPLink::hangup (const std::string& id) throw (VoipLinkException) throw VoipLinkException("Could not find call"); } - CHK_VALID_CALL; - Manager::instance().getMainBuffer()->unBindAll (call->getCallId()); _mutexIAX.enterMutex(); @@ -454,11 +425,10 @@ IAXVoIPLink::hangup (const std::string& id) throw (VoipLinkException) call->setSession (NULL); removeCall (id); - return true; } -bool +void IAXVoIPLink::peerHungup (const std::string& id) throw (VoipLinkException) { _debug ("IAXVoIPLink: Peer hung up"); @@ -468,14 +438,11 @@ IAXVoIPLink::peerHungup (const std::string& id) throw (VoipLinkException) throw VoipLinkException("Could not find call"); } - CHK_VALID_CALL; - Manager::instance().getMainBuffer()->unBindAll (call->getCallId()); call->setSession (NULL); removeCall (id); - return true; } @@ -488,8 +455,6 @@ IAXVoIPLink::onhold (const std::string& id) throw (VoipLinkException) throw VoipLinkException("Call does not exist"); } - CHK_VALID_CALL; - Manager::instance().getMainBuffer()->unBindAll (call->getCallId()); //if (call->getState() == Call::Hold) { _debug("Call is already on hold"); return false; } @@ -506,7 +471,6 @@ bool IAXVoIPLink::offhold (const std::string& id) throw (VoipLinkException) { IAXCall* call = getIAXCall (id); - CHK_VALID_CALL; Manager::instance().addStream (call->getCallId()); @@ -524,7 +488,6 @@ bool IAXVoIPLink::transfer (const std::string& id, const std::string& to) throw (VoipLinkException) { IAXCall* call = getIAXCall (id); - CHK_VALID_CALL; char callto[to.length() +1]; @@ -551,7 +514,6 @@ bool IAXVoIPLink::refuse (const std::string& id) { IAXCall* call = getIAXCall (id); - CHK_VALID_CALL; _mutexIAX.enterMutex(); @@ -568,7 +530,6 @@ bool IAXVoIPLink::carryingDTMFdigits (const std::string& id, char code) { IAXCall* call = getIAXCall (id); - CHK_VALID_CALL; _mutexIAX.enterMutex(); @@ -584,7 +545,6 @@ IAXVoIPLink::sendTextMessage (sfl::InstantMessaging *module, const std::string& /*from*/) { IAXCall* call = getIAXCall (callID); - CHK_VALID_CALL; // Must active the mutex for this session diff --git a/daemon/src/iax/iaxvoiplink.h b/daemon/src/iax/iaxvoiplink.h index 9b1fd65a169ee4bca5806bfd1e2537071843f017..08cf8d124337543818ab2f31e9444af493261ba4 100644 --- a/daemon/src/iax/iaxvoiplink.h +++ b/daemon/src/iax/iaxvoiplink.h @@ -78,10 +78,8 @@ class IAXVoIPLink : public VoIPLink /** * Init the voip link - * @return true if successful - * false otherwise */ - virtual bool init (void); + virtual void init (void); /** * Terminate a voip link by clearing the call list @@ -90,18 +88,15 @@ class IAXVoIPLink : public VoIPLink /** * Send out registration - * @return bool The new registration state (are we registered ?) */ - virtual void sendRegister (std::string id) throw(VoipLinkException); + virtual void sendRegister (Account *a) throw(VoipLinkException); /** * Destroy registration session * @todo Send an IAX_COMMAND_REGREL to force unregistration upstream. * Urgency: low - * @return bool true if we're registered upstream - * false otherwise */ - virtual void sendUnregister (std::string id) throw(VoipLinkException); + virtual void sendUnregister (Account *a); /** * Create a new outgoing call @@ -113,37 +108,27 @@ class IAXVoIPLink : public VoIPLink /** * Answer a call - * @param id The ID of the call - * @return bool true on success - * false otherwise + * @param c The call */ - virtual bool answer (const std::string& id) throw (VoipLinkException); + virtual void answer (Call *c) throw (VoipLinkException); /** * Hangup a call * @param id The ID of the call - * @return bool true on success - * false otherwise */ - virtual bool hangup (const std::string& id) throw (VoipLinkException); + virtual void hangup (const std::string& id) throw (VoipLinkException); /** * Peer Hungup a call * @param id The ID of the call - * @return bool true on success - * false otherwise */ - virtual bool peerHungup (const std::string& id) throw (VoipLinkException); + virtual void peerHungup (const std::string& id) throw (VoipLinkException); /** * Cancel a call * @param id The ID of the call - * @return bool true on success - * false otherwise */ - virtual bool cancel (const std::string& id UNUSED) throw (VoipLinkException){ - return false; - } + virtual void cancel (const std::string& id UNUSED) throw (VoipLinkException){} /** * Put a call on hold diff --git a/daemon/src/im/InstantMessaging.cpp b/daemon/src/im/InstantMessaging.cpp index 8c45a8e2686e8d3521fe5a993774ac52592d81df..1284012ad39f7fa737933b1bea89457746adfe41 100644 --- a/daemon/src/im/InstantMessaging.cpp +++ b/daemon/src/im/InstantMessaging.cpp @@ -111,7 +111,7 @@ int InstantMessaging::closeArchive (std::string& id) return (int) imFiles.size (); } -bool InstantMessaging::saveMessage (const std::string& message, const std::string& author, std::string& id, int mode) +bool InstantMessaging::saveMessage (const std::string& message, const std::string& author, const std::string& id, int mode) { // We need here to write the text message in the right file. @@ -158,7 +158,7 @@ pj_status_t InstantMessaging::notify (const std::string& /*id*/) return PJ_SUCCESS; } -pj_status_t InstantMessaging::sip_send (pjsip_inv_session *session, std::string& id, const std::string& text) +pj_status_t InstantMessaging::sip_send (pjsip_inv_session *session, const std::string& id, const std::string& text) { pjsip_method msg_method; @@ -219,7 +219,7 @@ pj_status_t InstantMessaging::sip_send (pjsip_inv_session *session, std::string& return PJ_SUCCESS; } -pj_status_t InstantMessaging::send_sip_message (pjsip_inv_session *session, std::string& id, const std::string& message) +pj_status_t InstantMessaging::send_sip_message (pjsip_inv_session *session, const std::string& id, const std::string& message) { /* Check the length of the message */ diff --git a/daemon/src/im/InstantMessaging.h b/daemon/src/im/InstantMessaging.h index 565b5663a37022678380caa1a3ea8307cd2b4427..90a0ee8040bd0f63215311feaa1025b23a2c6032 100644 --- a/daemon/src/im/InstantMessaging.h +++ b/daemon/src/im/InstantMessaging.h @@ -133,7 +133,7 @@ class InstantMessaging * @param id The current call * @return True if the message could have been successfully saved, False otherwise */ - bool saveMessage (const std::string& message, const std::string& author, std::string& id, int mode = MODE_APPEND); + bool saveMessage (const std::string& message, const std::string& author, const std::string& id, int mode = MODE_APPEND); /* * Receive a string SIP message, for a specific call @@ -152,9 +152,9 @@ class InstantMessaging * @return pj_status_t 0 on success * 1 otherwise */ - pj_status_t sip_send (pjsip_inv_session*, std::string& id, const std::string&); + pj_status_t sip_send (pjsip_inv_session*, const std::string& id, const std::string&); - pj_status_t send_sip_message (pjsip_inv_session*, std::string& id, const std::string&); + pj_status_t send_sip_message (pjsip_inv_session*, const std::string& id, const std::string&); bool iax_send (iax_session* session, const std::string& id, const std::string& message); diff --git a/daemon/src/managerimpl.cpp b/daemon/src/managerimpl.cpp index c2faf9118732ece7e6a3fb2a4174f02f2aac158d..5810bb2f32c549bcd1d5b5d56a22dfa83343c057 100644 --- a/daemon/src/managerimpl.cpp +++ b/daemon/src/managerimpl.cpp @@ -313,10 +313,7 @@ bool ManagerImpl::answerCall (const std::string& call_id) } try { - if (!getAccountLink (account_id)->answer (call_id)) { - removeCallAccount (call_id); - return false; - } + getAccountLink (account_id)->answer (call); } catch (const VoipLinkException &e) { _error("Manager: Error: %s", e.what()); @@ -350,10 +347,8 @@ bool ManagerImpl::answerCall (const std::string& call_id) } //THREAD=Main -bool ManagerImpl::hangupCall (const std::string& callId) +void ManagerImpl::hangupCall (const std::string& callId) { - bool returnValue = true; - _info ("Manager: Hangup call %s", callId.c_str()); // First stop audio layer if there is no call anymore @@ -364,7 +359,7 @@ bool ManagerImpl::hangupCall (const std::string& callId) if(_audiodriver == NULL) { audioLayerMutexUnlock(); _error("Manager: Error: Audio layer was not instantiated"); - return returnValue; + return; } _debug ("Manager: stop audio stream, there is no call remaining"); @@ -383,7 +378,7 @@ bool ManagerImpl::hangupCall (const std::string& callId) if (not isValidCall(callId) and not getConfigFromCall(callId) == Call::IPtoIP) { _error("Manager: Error: Could not hang up call, call not valid"); - return false; + return; } // Disconnect streams @@ -405,23 +400,20 @@ bool ManagerImpl::hangupCall (const std::string& callId) if (getConfigFromCall (callId) == Call::IPtoIP) { /* Direct IP to IP call */ try { - returnValue = SIPVoIPLink::instance()->hangup (callId); + SIPVoIPLink::instance()->hangup (callId); } catch (const VoipLinkException &e) { _error("%s", e.what()); - returnValue = 1; } } else { std::string accountId (getAccountFromCall (callId)); - returnValue = getAccountLink (accountId)->hangup (callId); + getAccountLink (accountId)->hangup (callId); removeCallAccount (callId); } getMainBuffer()->stateInfo(); - - return returnValue; } bool ManagerImpl::hangupConference (const std::string& id) @@ -454,45 +446,6 @@ bool ManagerImpl::hangupConference (const std::string& id) return true; } -//THREAD=Main -bool ManagerImpl::cancelCall (const std::string& id) -{ - std::string accountid; - bool returnValue; - - _debug ("Manager: Cancel call"); - - stopTone(); - - /* Direct IP to IP call */ - - if (getConfigFromCall (id) == Call::IPtoIP) - returnValue = SIPVoIPLink::instance()->cancel (id); - else { - /* Classic call, attached to an account */ - accountid = getAccountFromCall (id); - - if (accountid.empty()) { - _debug ("! Manager Cancel Call: Call doesn't exists"); - return false; - } - - returnValue = getAccountLink (accountid)->cancel (id); - - removeCallAccount (id); - } - - // it could be a waiting call? - removeWaitingCall (id); - - removeStream (id); - - switchCall (""); - - getMainBuffer()->stateInfo(); - - return returnValue; -} //THREAD=Main bool ManagerImpl::onHoldCall (const std::string& callId) @@ -1772,15 +1725,7 @@ void ManagerImpl::incomingMessage (const std::string& callID, _debug ("Manager: Failed to get account while sending instant message"); return; } - - if (account->getType() == "SIP") - dynamic_cast<SIPVoIPLink *> (getAccountLink (accountId))->sendTextMessage (_imModule, callID, message, from); - else if (account->getType() == "IAX") - dynamic_cast<IAXVoIPLink *> (account->getVoIPLink())->sendTextMessage (_imModule, callID, message, from); - else { - _debug ("Manager: Failed to get voip link while sending instant message"); - return; - } + account->getVoIPLink()->sendTextMessage (_imModule, callID, message, from); } // in case of a conference we must notify client using conference id @@ -1822,16 +1767,7 @@ bool ManagerImpl::sendTextMessage (const std::string& callID, const std::string& return false; } - if (account->getType() == "SIP") - // link = dynamic_cast<SIPVoIPLink *> (getAccountLink (accountId)); - dynamic_cast<SIPVoIPLink *> (getAccountLink (accountId))->sendTextMessage (_imModule, *iter_participant, message, from); - else if (account->getType() == "IAX") - // link = dynamic_cast<IAXVoIPLink *> (account->getVoIPLink()); - dynamic_cast<IAXVoIPLink *> (account->getVoIPLink())->sendTextMessage (_imModule, *iter_participant, message, from); - else { - _debug ("Manager: Failed to get voip link while sending instant message"); - return false; - } + account->getVoIPLink()->sendTextMessage (_imModule, *iter_participant, message, from); } return true; @@ -1858,14 +1794,7 @@ bool ManagerImpl::sendTextMessage (const std::string& callID, const std::string& return false; } - if (account->getType() == "SIP") - dynamic_cast<SIPVoIPLink *> (getAccountLink (accountId))->sendTextMessage (_imModule, *iter_participant, message, from); - else if (account->getType() == "IAX") - dynamic_cast<IAXVoIPLink *> (account->getVoIPLink())->sendTextMessage (_imModule, *iter_participant, message, from); - else { - _debug ("Manager: Failed to get voip link while sending instant message"); - return false; - } + account->getVoIPLink()->sendTextMessage (_imModule, *iter_participant, message, from); } } else { @@ -1878,14 +1807,7 @@ bool ManagerImpl::sendTextMessage (const std::string& callID, const std::string& return false; } - if (account->getType() == "SIP") - dynamic_cast<SIPVoIPLink *> (getAccountLink (accountId))->sendTextMessage (_imModule, callID, message, from); - else if (account->getType() == "IAX") - dynamic_cast<IAXVoIPLink *> (account->getVoIPLink())->sendTextMessage (_imModule, callID, message, from); - else { - _debug ("Manager: Failed to get voip link while sending instant message"); - return false; - } + account->getVoIPLink()->sendTextMessage (_imModule, callID, message, from); } return true; diff --git a/daemon/src/managerimpl.h b/daemon/src/managerimpl.h index 2e1b3181d6636dd48a0fd0335676c992d6e3f703..14cb8984a611921dac026f3678e6d65d255c2593 100644 --- a/daemon/src/managerimpl.h +++ b/daemon/src/managerimpl.h @@ -204,9 +204,8 @@ class ManagerImpl * Functions which occur with a user's action * Hangup the call * @param id The call identifier - * @return true on success */ - bool hangupCall (const std::string& id); + void hangupCall (const std::string& id); /** @@ -216,13 +215,6 @@ class ManagerImpl */ bool hangupConference (const std::string& id); - /** - * Functions which occur with a user's action - * Cancel the call - * @param id The call identifier - */ - bool cancelCall (const std::string& id); - /** * Functions which occur with a user's action * Put the call on hold diff --git a/daemon/src/sip/sipaccount.cpp b/daemon/src/sip/sipaccount.cpp index b31c6b2e6ac68fbca342e13e781e4da7c1bdc921..372265398a10b1348c9bb8b1f1dd849aeae3e9ed 100644 --- a/daemon/src/sip/sipaccount.cpp +++ b/daemon/src/sip/sipaccount.cpp @@ -566,7 +566,7 @@ int SIPAccount::registerVoIPLink() // In our definition of the ip2ip profile (aka Direct IP Calls), // no registration should be performed if (_accountID != IP2IP_PROFILE) { - _link->sendRegister (_accountID); + _link->sendRegister (this); } } catch(VoipLinkException &e) { @@ -583,7 +583,7 @@ int SIPAccount::unregisterVoIPLink() } try { - _link->sendUnregister (_accountID); + _link->sendUnregister (this); setRegistrationInfo (NULL); } catch(VoipLinkException &e) { diff --git a/daemon/src/sip/sipvoiplink.cpp b/daemon/src/sip/sipvoiplink.cpp index b196e128d2c8b3e5dae3acd6c5298b258c0e29b7..2545f07b790c43be0249f46ef9ecf4d85bef7982 100644 --- a/daemon/src/sip/sipvoiplink.cpp +++ b/daemon/src/sip/sipvoiplink.cpp @@ -284,8 +284,6 @@ SIPVoIPLink::SIPVoIPLink () SIPVoIPLink::~SIPVoIPLink() { - _debug ("UserAgent: SIPVoIPLink destructor called"); - terminate(); } @@ -303,20 +301,16 @@ SIPVoIPLink* SIPVoIPLink::instance () void SIPVoIPLink::decrementClients (void) { - _clients--; - - if (_clients == 0) { - + if (--_clients == 0) { _debug ("UserAgent: No SIP account anymore, terminate SIPVoIPLink"); - // terminate(); delete SIPVoIPLink::_instance; } } -bool SIPVoIPLink::init() +void SIPVoIPLink::init() { - if (initDone()) - return false; + if (_initDone) + return; // TODO This port should be the one configured for the IP profile // and not the global one @@ -328,9 +322,7 @@ bool SIPVoIPLink::init() /* Initialize the pjsip library */ pjsipInit(); - initDone (true); - - return true; + _initDone = true; } void @@ -346,12 +338,12 @@ SIPVoIPLink::terminate() /* Clean shutdown of pjsip library */ - if (initDone()) { + if (_initDone) { _debug ("UserAgent: Shutting down PJSIP"); pjsipShutdown(); } - initDone (false); + _initDone = false; } @@ -369,24 +361,13 @@ SIPVoIPLink::getEvent() } -void SIPVoIPLink::sendRegister (std::string id) throw(VoipLinkException) +void SIPVoIPLink::sendRegister (Account *a) throw(VoipLinkException) { - - int expire_value = 0; - pj_status_t status; pjsip_tx_data *tdata; - pjsip_host_info destination; - - std::string tmp, hostname, username, password; - SIPAccount *account = NULL; - pjsip_regc *regc; pjsip_hdr hdr_list; - account = dynamic_cast<SIPAccount *> (Manager::instance().getAccount (id)); - if (account == NULL) { - throw VoipLinkException("Account pointer is NULL in send register"); - } + SIPAccount *account = (SIPAccount*)a; // Resolve hostname here and keep its // IP address for the whole time the @@ -395,6 +376,7 @@ void SIPVoIPLink::sendRegister (std::string id) throw(VoipLinkException) // #1852 that we hope should be fixed // soon. if (account->isResolveOnce()) { + pjsip_host_info destination; struct result result; destination.type = PJSIP_TRANSPORT_UNSPECIFIED; @@ -446,16 +428,15 @@ void SIPVoIPLink::sendRegister (std::string id) throw(VoipLinkException) _mutexSIP.enterMutex(); // Get the client registration information for this particular account - regc = account->getRegistrationInfo(); + pjsip_regc *regc = account->getRegistrationInfo(); account->setRegister (true); // Set the expire value of the message from the config file + int expire_value; std::istringstream stream (account->getRegistrationExpire()); stream >> expire_value; - - if (!expire_value) { + if (!expire_value) expire_value = PJSIP_REGC_EXPIRATION_NOT_SPECIFIED; - } // Update the state of the voip link account->setRegistrationState (Trying); @@ -580,14 +561,10 @@ void SIPVoIPLink::sendRegister (std::string id) throw(VoipLinkException) } } -void SIPVoIPLink::sendUnregister (std::string id) throw(VoipLinkException) +void SIPVoIPLink::sendUnregister (Account *a) throw(VoipLinkException) { - - pj_status_t status = 0; pjsip_tx_data *tdata = NULL; - SIPAccount *account; - - account = dynamic_cast<SIPAccount *> (Manager::instance().getAccount (id)); + SIPAccount *account = (SIPAccount *)a; // If an transport is attached to this account, detach it and decrease reference counter if (account->getAccountTransport()) { @@ -606,20 +583,14 @@ void SIPVoIPLink::sendUnregister (std::string id) throw(VoipLinkException) } pjsip_regc *regc = account->getRegistrationInfo(); - if(regc == NULL) { + if(!regc) throw VoipLinkException("Registration structure is NULL"); - } - status = pjsip_regc_unregister (regc, &tdata); - if (status != PJ_SUCCESS) { + if (pjsip_regc_unregister (regc, &tdata) != PJ_SUCCESS) throw VoipLinkException("Unable to unregister sip account"); - } - status = pjsip_regc_send (regc, tdata); - - if (status != PJ_SUCCESS) { + if (pjsip_regc_send (regc, tdata) != PJ_SUCCESS) throw VoipLinkException("Unable to send request to unregister sip account"); - } account->setRegister (false); } @@ -627,7 +598,6 @@ void SIPVoIPLink::sendUnregister (std::string id) throw(VoipLinkException) Call *SIPVoIPLink::newOutgoingCall (const std::string& id, const std::string& toUrl) throw (VoipLinkException) { SIPAccount * account = NULL; - pj_status_t status; std::string localAddr, addrSdp; // Create a new SIP call @@ -697,8 +667,7 @@ Call *SIPVoIPLink::newOutgoingCall (const std::string& id, const std::string& to // Building the local SDP offer call->getLocalSDP()->setLocalIP (addrSdp); - status = call->getLocalSDP()->createOffer (account->getActiveCodecs ()); - if (status != PJ_SUCCESS) { + if (call->getLocalSDP()->createOffer (account->getActiveCodecs ()) != PJ_SUCCESS) { delete call; throw VoipLinkException ("Could not create local sdp offer for new call"); } @@ -715,69 +684,32 @@ Call *SIPVoIPLink::newOutgoingCall (const std::string& id, const std::string& to return call; } -bool -SIPVoIPLink::answer (const std::string& id) throw (VoipLinkException) +void +SIPVoIPLink::answer (Call *c) throw (VoipLinkException) { - pj_status_t status = PJ_SUCCESS; pjsip_tx_data *tdata; - pjsip_inv_session *inv_session; - - _debug ("UserAgent: Answering call %s", id.c_str()); - - SIPCall *call = getSIPCall (id); - if (call==NULL) { - throw VoipLinkException("Call is NULL while answering"); - } - inv_session = call->getInvSession(); + _debug ("UserAgent: Answering call"); - if (status == PJ_SUCCESS) { + SIPCall *call = (SIPCall*)c; - _debug ("UserAgent: SDP negotiation success! : call %s ", call->getCallId().c_str()); - // Create and send a 200(OK) response - if((status = pjsip_inv_answer (inv_session, PJSIP_SC_OK, NULL, NULL, &tdata)) != PJ_SUCCESS) { - throw VoipLinkException("Could not init invite request answer (200 OK)"); - } - if((status = pjsip_inv_send_msg (inv_session, tdata)) != PJ_SUCCESS) { - throw VoipLinkException("Could not send invite request answer (200 OK)"); - } + pjsip_inv_session *inv_session = call->getInvSession(); - call->setConnectionState (Call::Connected); - call->setState (Call::Active); + _debug ("UserAgent: SDP negotiation success! : call %s ", call->getCallId().c_str()); + // Create and send a 200(OK) response + if (pjsip_inv_answer (inv_session, PJSIP_SC_OK, NULL, NULL, &tdata) != PJ_SUCCESS) + throw VoipLinkException("Could not init invite request answer (200 OK)"); - return true; - } else { - // Create and send a 488/Not acceptable because the SDP negotiation failed - if((status = pjsip_inv_answer (inv_session, PJSIP_SC_NOT_ACCEPTABLE_HERE, NULL, NULL, &tdata)) != PJ_SUCCESS) { - throw VoipLinkException("Could not init invite answer (488 not acceptable here)"); - } - if((status = pjsip_inv_send_msg (inv_session, tdata)) != PJ_SUCCESS) { - throw VoipLinkException("Could not init invite request answer (488 NOT ACCEPTABLE HERE)"); - } - // Terminate the call - _debug ("UserAgent: SDP negotiation failed, terminate call %s ", call->getCallId().c_str()); + if (pjsip_inv_send_msg (inv_session, tdata) != PJ_SUCCESS) + throw VoipLinkException("Could not send invite request answer (200 OK)"); - if(call->getAudioRtp()) { - throw VoipLinkException("No audio rtp session for this call"); - } - - try { - call->getAudioRtp()->stop (); - } - catch(...) { - throw VoipLinkException("Could not stop rtp session"); - } - - removeCall (call->getCallId()); - - return false; - } + call->setConnectionState (Call::Connected); + call->setState (Call::Active); } -bool +void SIPVoIPLink::hangup (const std::string& id) throw (VoipLinkException) { - pj_status_t status; pjsip_tx_data *tdata = NULL; SIPCall* call = getSIPCall (id); @@ -804,63 +736,43 @@ SIPVoIPLink::hangup (const std::string& id) throw (VoipLinkException) } // User hangup current call. Notify peer - status = pjsip_inv_end_session (inv, 404, NULL, &tdata); - if (status != PJ_SUCCESS) { - return false; - } - - if (tdata == NULL) { - return true; - } + if (pjsip_inv_end_session (inv, 404, NULL, &tdata) != PJ_SUCCESS || !tdata) + return; - status = pjsip_inv_send_msg (inv, tdata); - if (status != PJ_SUCCESS) - return false; + if (pjsip_inv_send_msg (inv, tdata) != PJ_SUCCESS) + return; // Make sure user data is NULL in callbacks inv->mod_data[getModId()] = NULL; // Release RTP thread try { - if (Manager::instance().isCurrentCall (id)) { + if (Manager::instance().isCurrentCall (id)) call->getAudioRtp()->stop(); - } } catch(...) { throw VoipLinkException("Could not stop audio rtp session"); } removeCall (id); - - return true; } -bool +void SIPVoIPLink::peerHungup (const std::string& id) throw (VoipLinkException) { - pj_status_t status; - pjsip_tx_data *tdata = NULL; - SIPCall* call; - _info ("UserAgent: Peer hungup"); - call = getSIPCall (id); - if (call == NULL) { + SIPCall* call = getSIPCall (id); + if (!call) throw VoipLinkException("Call does not exist"); - } // User hangup current call. Notify peer - status = pjsip_inv_end_session (call->getInvSession(), 404, NULL, &tdata); - if (status != PJ_SUCCESS) - return false; - - if (tdata == NULL) - return true; - - status = pjsip_inv_send_msg (call->getInvSession(), tdata); + pjsip_tx_data *tdata = NULL; + if (pjsip_inv_end_session (call->getInvSession(), 404, NULL, &tdata) != PJ_SUCCESS || !tdata) + return; - if (status != PJ_SUCCESS) - return false; + if (pjsip_inv_send_msg (call->getInvSession(), tdata) != PJ_SUCCESS) + return; // Make sure user data is NULL in callbacks call->getInvSession()->mod_data[getModId() ] = NULL; @@ -877,11 +789,9 @@ SIPVoIPLink::peerHungup (const std::string& id) throw (VoipLinkException) } removeCall (id); - - return true; } -bool +void SIPVoIPLink::cancel (const std::string& id) throw (VoipLinkException) { _info ("UserAgent: Cancel call %s", id.c_str()); @@ -892,23 +802,15 @@ SIPVoIPLink::cancel (const std::string& id) throw (VoipLinkException) } removeCall (id); - - return true; } bool SIPVoIPLink::onhold (const std::string& id) throw (VoipLinkException) { - Sdp *sdpSession; - pj_status_t status; - SIPCall* call; - - call = getSIPCall (id); - - if (call == NULL) { + SIPCall *call = getSIPCall (id); + if (!call) throw VoipLinkException("Could not find call"); - } // Stop sound call->setState (Call::Hold); @@ -922,10 +824,9 @@ SIPVoIPLink::onhold (const std::string& id) throw (VoipLinkException) _debug ("UserAgent: Stopping RTP session for on hold action"); - sdpSession = call->getLocalSDP(); - if (sdpSession == NULL) { + Sdp *sdpSession = call->getLocalSDP(); + if (!sdpSession) throw VoipLinkException("Could not find sdp session"); - } sdpSession->removeAttributeFromLocalAudioMedia("sendrecv"); sdpSession->removeAttributeFromLocalAudioMedia("sendonly"); @@ -933,31 +834,20 @@ SIPVoIPLink::onhold (const std::string& id) throw (VoipLinkException) sdpSession->addAttributeToLocalAudioMedia("sendonly"); // Create re-INVITE with new offer - status = SIPSessionReinvite (call); - - if (status != PJ_SUCCESS) { - return false; - } - - return true; + return SIPSessionReinvite (call) == PJ_SUCCESS; } bool SIPVoIPLink::offhold (const std::string& id) throw (VoipLinkException) { - Sdp *sdpSession; - pj_status_t status; - SIPCall *call; - _debug ("UserAgent: retrive call from hold status"); - call = getSIPCall (id); - + SIPCall *call = getSIPCall (id); if (call == NULL) { throw VoipLinkException("Could not find call"); } - sdpSession = call->getLocalSDP(); + Sdp *sdpSession = call->getLocalSDP(); if (sdpSession == NULL) { throw VoipLinkException("Could not find sdp session"); } @@ -1003,13 +893,10 @@ SIPVoIPLink::offhold (const std::string& id) throw (VoipLinkException) sdpSession->addAttributeToLocalAudioMedia("sendrecv"); /* Create re-INVITE with new offer */ - status = SIPSessionReinvite (call); - if (status != PJ_SUCCESS) { + if (SIPSessionReinvite (call) != PJ_SUCCESS) return false; - } call->setState (Call::Active); - return true; } @@ -1019,70 +906,45 @@ SIPVoIPLink::sendTextMessage (sfl::InstantMessaging *module, const std::string& _debug ("SipVoipLink: Send text message to %s, from %s", callID.c_str(), from.c_str()); SIPCall *call = getSIPCall (callID); - pj_status_t status = !PJ_SUCCESS; - - - if (call) { - std::string formatedFrom = from; - - // add double quotes for xml formating - formatedFrom.insert (0,"\""); - formatedFrom.append ("\""); - - /* Send IM message */ - sfl::InstantMessaging::UriList list; - - sfl::InstantMessaging::UriEntry entry; - entry[sfl::IM_XML_URI] = std::string (formatedFrom); - - list.push_front (entry); - - std::string formatedMessage = module->appendUriList (message, list); - - status = module->send_sip_message (call->getInvSession (), (std::string&) callID, formatedMessage); - - } else { + if (!call) { /* Notify the client of an error */ /*Manager::instance ().incomingMessage ( "", "sflphoned", "Unable to send a message outside a call.");*/ + return !PJ_SUCCESS; } - return status; + /* Send IM message */ + sfl::InstantMessaging::UriList list; + sfl::InstantMessaging::UriEntry entry; + entry[sfl::IM_XML_URI] = std::string ("\"" + from + "\""); // add double quotes for xml formating + + list.push_front (entry); + + std::string formatedMessage = module->appendUriList (message, list); + + return module->send_sip_message (call->getInvSession (), callID, formatedMessage); } int SIPSessionReinvite (SIPCall *call) { - - pj_status_t status; pjsip_tx_data *tdata; - pjmedia_sdp_session *local_sdp; _debug("UserAgent: Sending re-INVITE request"); - if (call == NULL) { - _error ("UserAgent: Error: Call is NULL in session reinvite"); - return !PJ_SUCCESS; - } - - if ( (local_sdp = call->getLocalSDP()->getLocalSdpSession()) == NULL) { + pjmedia_sdp_session *local_sdp = call->getLocalSDP()->getLocalSdpSession(); + if (!local_sdp) { _debug ("UserAgent: Error: Unable to find local sdp"); return !PJ_SUCCESS; } // Build the reinvite request - status = pjsip_inv_reinvite (call->getInvSession(), NULL, local_sdp, &tdata); - + pj_status_t status = pjsip_inv_reinvite (call->getInvSession(), NULL, local_sdp, &tdata); if (status != PJ_SUCCESS) - return 1; // !PJ_SUCCESS + return status; // Send it - status = pjsip_inv_send_msg (call->getInvSession(), tdata); - - if (status != PJ_SUCCESS) - return 1; // !PJ_SUCCESS - - return PJ_SUCCESS; + return pjsip_inv_send_msg (call->getInvSession(), tdata); } bool @@ -1159,28 +1021,17 @@ SIPVoIPLink::transfer (const std::string& id, const std::string& to) throw (Voip bool SIPVoIPLink::attendedTransfer(const std::string& transferId, const std::string& targetId) { char str_dest_buf[PJSIP_MAX_URL_SIZE*2]; - pj_str_t str_dest; - pjsip_dialog *target_dlg; - pjsip_uri *uri; - pjsip_evsub *sub; - pjsip_tx_data *tdata; - - struct pjsip_evsub_user xfer_cb; - pj_status_t status; _debug("UserAgent: Attended transfer"); - str_dest.ptr = NULL; - str_dest.slen = 0; - - SIPCall *targetCall = getSIPCall (targetId); - target_dlg = targetCall->getInvSession()->dlg; + pjsip_dialog *target_dlg = getSIPCall (targetId)->getInvSession()->dlg; /* Print URI */ + pj_str_t str_dest = { NULL, 0 }; str_dest_buf[0] = '<'; str_dest.slen = 1; - uri = (pjsip_uri*) pjsip_uri_get_uri(target_dlg->remote.info->uri); + pjsip_uri *uri = (pjsip_uri*) pjsip_uri_get_uri(target_dlg->remote.info->uri); int len = pjsip_uri_print(PJSIP_URI_IN_REQ_URI, uri, str_dest_buf+1, sizeof(str_dest_buf)-1); str_dest.slen += len; @@ -1204,13 +1055,13 @@ bool SIPVoIPLink::attendedTransfer(const std::string& transferId, const std::str SIPCall *transferCall = getSIPCall (transferId); /* Create xfer client subscription. */ + struct pjsip_evsub_user xfer_cb; pj_bzero (&xfer_cb, sizeof (xfer_cb)); xfer_cb.on_evsub_state = &transfer_client_cb; + pjsip_evsub *sub; - status = pjsip_xfer_create_uac (transferCall->getInvSession()->dlg, &xfer_cb, &sub); - - if (status != PJ_SUCCESS) { - _warn ("UserAgent: Unable to create xfer -- %d", status); + if (pjsip_xfer_create_uac (transferCall->getInvSession()->dlg, &xfer_cb, &sub) != PJ_SUCCESS) { + _warn ("UserAgent: Unable to create xfer"); return false; } @@ -1224,10 +1075,9 @@ bool SIPVoIPLink::attendedTransfer(const std::string& transferId, const std::str /* * Create REFER request. */ - status = pjsip_xfer_initiate (sub, &str_dest, &tdata); - - if (status != PJ_SUCCESS) { - _error ("UserAgent: Unable to create REFER request -- %d", status); + pjsip_tx_data *tdata; + if (pjsip_xfer_initiate (sub, &str_dest, &tdata) != PJ_SUCCESS) { + _error ("UserAgent: Unable to create REFER request"); return false; } @@ -1239,23 +1089,7 @@ bool SIPVoIPLink::attendedTransfer(const std::string& transferId, const std::str /* Send. */ - status = pjsip_xfer_send_request (sub, tdata); - - if (status != PJ_SUCCESS) { - _error ("UserAgent: Unable to send REFER request -- %d", status); - return false; - } - - return true; -} - -bool SIPVoIPLink::transferStep2 (SIPCall* call) -{ - - // TODO is this the best way to proceed? - Manager::instance().peerHungupCall (call->getCallId()); - - return true; + return pjsip_xfer_send_request (sub, tdata) == PJ_SUCCESS; } bool @@ -3849,4 +3683,3 @@ std::string SIPVoIPLink::getInterfaceAddrFromName (std::string ifaceName) return addr; } - diff --git a/daemon/src/sip/sipvoiplink.h b/daemon/src/sip/sipvoiplink.h index 8082a09f038b4efe1c12f24e0afeee662cfb87bc..657c4c860028d0af5f854f08f9c8d2a7971ae304 100644 --- a/daemon/src/sip/sipvoiplink.h +++ b/daemon/src/sip/sipvoiplink.h @@ -105,9 +105,8 @@ class SIPVoIPLink : public VoIPLink /** * Try to initiate the pjsip engine/thread and set config - * @return bool True if OK */ - virtual bool init (void); + virtual void init (void); /** * Shut the library and clean up @@ -121,17 +120,13 @@ class SIPVoIPLink : public VoIPLink /** * Build and send SIP registration request - * @return bool True on success - * false otherwise */ - virtual void sendRegister (std::string id) throw(VoipLinkException); + virtual void sendRegister (Account *a) throw(VoipLinkException); /** * Build and send SIP unregistration request - * @return bool True on success - * false otherwise */ - virtual void sendUnregister (std::string id) throw(VoipLinkException); + virtual void sendUnregister (Account *a) throw(VoipLinkException); /** * Place a new call @@ -143,31 +138,27 @@ class SIPVoIPLink : public VoIPLink /** * Answer the call - * @param id The call identifier - * @return True on success + * @param c The call */ - virtual bool answer (const std::string& id) throw (VoipLinkException); + virtual void answer (Call *c) throw (VoipLinkException); /** * Hang up the call * @param id The call identifier - * @return bool True on success */ - virtual bool hangup (const std::string& id) throw (VoipLinkException); + virtual void hangup (const std::string& id) throw (VoipLinkException); /** * Hang up the call * @param id The call identifier - * @return bool True on success */ - virtual bool peerHungup (const std::string& id) throw (VoipLinkException); + virtual void peerHungup (const std::string& id) throw (VoipLinkException); /** * Cancel the call * @param id The call identifier - * @return bool True on success */ - virtual bool cancel (const std::string& id) throw (VoipLinkException); + virtual void cancel (const std::string& id) throw (VoipLinkException); /** * Put the call on hold @@ -199,11 +190,6 @@ class SIPVoIPLink : public VoIPLink */ virtual bool attendedTransfer(const std::string&, const std::string&); - /** - * Handle the incoming refer msg, not finished yet - */ - bool transferStep2 (SIPCall* call); - /** * Refuse the call * @param id The call identifier diff --git a/daemon/src/voiplink.h b/daemon/src/voiplink.h index 5242cf4ba19b2726d89b0d3d12de8fdf4f827be5..2f0b6afdd5c1f6e8d94bfe64e2bd599ed38485ea 100644 --- a/daemon/src/voiplink.h +++ b/daemon/src/voiplink.h @@ -39,6 +39,9 @@ #include "call.h" class Account; +namespace sfl { +class InstantMessaging; +}; /** Define a map that associate a Call object to a call identifier */ typedef std::map<std::string, Call*> CallMap; @@ -77,9 +80,8 @@ class VoIPLink /** * Virtual method * Try to initiate the communication layer and set config - * @return bool True if OK */ - virtual bool init (void) = 0; + virtual void init (void) = 0; /** * Virtual method @@ -90,18 +92,14 @@ class VoIPLink /** * Virtual method * Build and send account registration request - * @return bool True on success - * false otherwise */ - virtual void sendRegister (std::string id) throw (VoipLinkException) = 0; + virtual void sendRegister (Account *a) throw (VoipLinkException) = 0; /** * Virtual method * Build and send account unregistration request - * @return bool True on success - * false otherwise */ - virtual void sendUnregister (std::string id) throw (VoipLinkException) = 0; + virtual void sendUnregister (Account *a) = 0; /** * Place a new call @@ -113,31 +111,27 @@ class VoIPLink /** * Answer the call - * @param id The call identifier - * @return bool True on success + * @param c The call */ - virtual bool answer (const std::string& id) throw (VoipLinkException) = 0; + virtual void answer (Call *c) throw (VoipLinkException) = 0; /** * Hang up a call * @param id The call identifier - * @return bool True on success */ - virtual bool hangup (const std::string& id) throw (VoipLinkException) = 0; + virtual void hangup (const std::string& id) throw (VoipLinkException) = 0; /** * Peer Hung up a call * @param id The call identifier - * @return bool True on success */ - virtual bool peerHungup (const std::string& id) throw (VoipLinkException) = 0; + virtual void peerHungup (const std::string& id) throw (VoipLinkException) = 0; /** * Cancel the call dialing * @param id The call identifier - * @return bool True on success */ - virtual bool cancel (const std::string& id) throw (VoipLinkException) = 0; + virtual void cancel (const std::string& id) throw (VoipLinkException) = 0; /** * Put a call on hold @@ -190,12 +184,17 @@ class VoIPLink */ virtual std::string getCurrentCodecName(Call *call) = 0; - bool initDone (void) { - return _initDone; - } - void initDone (bool state) { - _initDone = state; - } + /** + * Send a message to a call identified by its callid + * + * @param The InstantMessaging module which contains formating, parsing and sending method + * @param The Id of the call to send the message to + * @param The actual message to be transmitted + * @param The sender of this message (could be another participant of a conference) + * + * @return True if the message is sent without error, false elsewhere + */ + virtual bool sendTextMessage (sfl::InstantMessaging *module, const std::string& callID, const std::string& message, const std::string& from) = 0; /** Add a call to the call map (protected by mutex) * @param call A call pointer with a unique pointer