Commit d054a328 authored by Rafaël Carré's avatar Rafaël Carré
Browse files

SIP: simplify

parent d81435fa
...@@ -60,7 +60,6 @@ AudioRtpSession::AudioRtpSession (SIPCall * sipcall, RtpMethod type, ost::RTPDat ...@@ -60,7 +60,6 @@ AudioRtpSession::AudioRtpSession (SIPCall * sipcall, RtpMethod type, ost::RTPDat
AudioRtpSession::~AudioRtpSession() AudioRtpSession::~AudioRtpSession()
{ {
_info ("AudioRtpSession: Delete AudioRtpSession instance");
_queue->disableStack(); _queue->disableStack();
} }
......
...@@ -33,6 +33,8 @@ ...@@ -33,6 +33,8 @@
void UrlHook::runAction (std::string command, std::string args) void UrlHook::runAction (std::string command, std::string args)
{ {
if (args.empty())
return;
//FIXME : use fork and execve, so no need to escape shell arguments //FIXME : use fork and execve, so no need to escape shell arguments
std::string cmd = command + "\"" + args + "\" &"; std::string cmd = command + "\"" + args + "\" &";
system(cmd.c_str()); system(cmd.c_str());
......
...@@ -474,36 +474,29 @@ IAXVoIPLink::refuse (const std::string& id) ...@@ -474,36 +474,29 @@ IAXVoIPLink::refuse (const std::string& id)
} }
bool void
IAXVoIPLink::carryingDTMFdigits (const std::string& id, char code) IAXVoIPLink::carryingDTMFdigits (const std::string& id, char code)
{ {
IAXCall* call = getIAXCall (id); IAXCall* call = getIAXCall (id);
CHK_VALID_CALL; if (call) {
mutexIAX_.enterMutex(); mutexIAX_.enterMutex();
iax_send_dtmf (call->getSession(), code); iax_send_dtmf (call->getSession(), code);
mutexIAX_.leaveMutex(); mutexIAX_.leaveMutex();
}
return true;
} }
bool void
IAXVoIPLink::sendTextMessage (sfl::InstantMessaging *module, IAXVoIPLink::sendTextMessage (sfl::InstantMessaging *module,
const std::string& callID, const std::string& message, const std::string& callID, const std::string& message,
const std::string& /*from*/) const std::string& /*from*/)
{ {
IAXCall* call = getIAXCall (callID); IAXCall* call = getIAXCall (callID);
CHK_VALID_CALL; if (!call)
return;
// Must active the mutex for this session
mutexIAX_.enterMutex(); mutexIAX_.enterMutex();
module->send_iax_message (call->getSession(), callID, message.c_str()); module->send_iax_message (call->getSession(), callID, message.c_str());
// iax_send_text (call->getSession(), message.c_str());
mutexIAX_.leaveMutex(); mutexIAX_.leaveMutex();
return true;
} }
...@@ -649,28 +642,17 @@ IAXVoIPLink::iaxHandleCallEvent (iax_event* event, IAXCall* call) ...@@ -649,28 +642,17 @@ IAXVoIPLink::iaxHandleCallEvent (iax_event* event, IAXCall* call)
break; break;
case IAX_IE_MSGCOUNT: case IAX_IE_MSGCOUNT:
break; case IAX_EVENT_TIMEOUT:
case IAX_EVENT_PONG: case IAX_EVENT_PONG:
default:
break; break;
case IAX_EVENT_URL: case IAX_EVENT_URL:
if (Manager::instance().getConfigString (HOOKS, URLHOOK_IAX2_ENABLED) == "1") { if (Manager::instance().getConfigString (HOOKS, URLHOOK_IAX2_ENABLED) == "1")
if (*event->data) {
_debug ("> IAX_EVENT_URL received: %s", event->data);
UrlHook::runAction (Manager::instance().getConfigString (HOOKS, URLHOOK_COMMAND), (char*) event->data); UrlHook::runAction (Manager::instance().getConfigString (HOOKS, URLHOOK_COMMAND), (char*) event->data);
}
}
break;
case IAX_EVENT_TIMEOUT:
break; break;
default:
_debug ("iaxHandleCallEvent: Unknown event type (in call event): %d", event->etype);
} }
} }
......
...@@ -175,13 +175,11 @@ class IAXVoIPLink : public VoIPLink ...@@ -175,13 +175,11 @@ class IAXVoIPLink : public VoIPLink
* Send DTMF * Send DTMF
* @param id The ID of the call * @param id The ID of the call
* @param code The code of the DTMF * @param code The code of the DTMF
* @return bool true on success
* false otherwise
*/ */
virtual bool carryingDTMFdigits (const std::string& id, char code); virtual void carryingDTMFdigits (const std::string& id, char code);
virtual bool sendTextMessage (sfl::InstantMessaging *module, const std::string& callID, const std::string& message, const std::string& from); virtual void sendTextMessage (sfl::InstantMessaging *module, const std::string& callID, const std::string& message, const std::string& from);
/** /**
* Return the codec protocol used for this call * Return the codec protocol used for this call
......
...@@ -54,9 +54,7 @@ static void XMLCALL endElementCallback (void * /*userData*/, const char * /*name ...@@ -54,9 +54,7 @@ static void XMLCALL endElementCallback (void * /*userData*/, const char * /*name
} }
InstantMessaging::InstantMessaging() InstantMessaging::InstantMessaging() {}
: imFiles ()
, messageMaxSize (MAXIMUM_MESSAGE_LENGTH) {}
InstantMessaging::~InstantMessaging() {} InstantMessaging::~InstantMessaging() {}
...@@ -110,17 +108,12 @@ void InstantMessaging::send_sip_message (pjsip_inv_session *session, const std:: ...@@ -110,17 +108,12 @@ void InstantMessaging::send_sip_message (pjsip_inv_session *session, const std::
} }
void InstantMessaging::iax_send (iax_session* session, const std::string& /*id*/, const std::string& message)
{
iax_send_text(session, message.c_str()) != -1;
}
void InstantMessaging::send_iax_message (iax_session* session, const std::string& id, const std::string& message) void InstantMessaging::send_iax_message (iax_session* session, const std::string& id, const std::string& message)
{ {
std::vector<std::string> msgs = split_message (message); std::vector<std::string> msgs = split_message (message);
std::vector<std::string>::const_iterator iter; std::vector<std::string>::const_iterator iter;
for (iter = msgs.begin(); iter != msgs.end(); ++iter) for (iter = msgs.begin(); iter != msgs.end(); ++iter)
iax_send(session, id, *iter); iax_send_text(session, (*iter).c_str());
} }
......
...@@ -86,19 +86,12 @@ class InstantMessaging ...@@ -86,19 +86,12 @@ class InstantMessaging
*/ */
~InstantMessaging(); ~InstantMessaging();
/**
* Set maximum size fo this module.
*/
void setMessageMaximumSize (unsigned int max) {
messageMaxSize = max;
}
/** /**
* Return the maximum number if character for a single SIP MESSAGE. * Return the maximum number if character for a single SIP MESSAGE.
* Longer messages should be splitted in several smaller messages using split_message * Longer messages should be splitted in several smaller messages using split_message
*/ */
unsigned int getMessageMaximumSize (void) { size_t getMessageMaximumSize (void) {
return messageMaxSize; return MAXIMUM_MESSAGE_LENGTH;
} }
/* /*
...@@ -120,9 +113,6 @@ class InstantMessaging ...@@ -120,9 +113,6 @@ class InstantMessaging
void sip_send (pjsip_inv_session*, const std::string& id, const std::string&); void sip_send (pjsip_inv_session*, const std::string& id, const std::string&);
void send_sip_message (pjsip_inv_session*, const std::string& id, const std::string&); void send_sip_message (pjsip_inv_session*, const std::string& id, const std::string&);
void iax_send (iax_session* session, const std::string& id, const std::string& message);
void send_iax_message (iax_session *session, const std::string& id, const std::string&); void send_iax_message (iax_session *session, const std::string& id, const std::string&);
std::vector<std::string> split_message(std::string); std::vector<std::string> split_message(std::string);
...@@ -177,24 +167,8 @@ class InstantMessaging ...@@ -177,24 +167,8 @@ class InstantMessaging
private: private:
/**
* A queue to handle messages
*/
// std::queue<std::string> queuedMessages;
/**
* A map to handle opened file descriptors
* A file descriptor is associated to a call ID
*/
std::map<std::string, std::ofstream*> imFiles;
InstantMessaging (const InstantMessaging&); //No Copy Constructor InstantMessaging (const InstantMessaging&); //No Copy Constructor
InstantMessaging& operator= (const InstantMessaging&); //No Assignment Operator InstantMessaging& operator= (const InstantMessaging&); //No Assignment Operator
/**
* Maximum size in char of an instant message
*/
unsigned int messageMaxSize;
}; };
} }
#endif // _INSTANT_MESSAGING_H #endif // _INSTANT_MESSAGING_H
...@@ -128,7 +128,6 @@ void ManagerImpl::init (std::string config_file) ...@@ -128,7 +128,6 @@ void ManagerImpl::init (std::string config_file)
audioLayerMutexUnlock(); audioLayerMutexUnlock();
_history->load_history (preferences.getHistoryLimit()); _history->load_history (preferences.getHistoryLimit());
_imModule->init();
registerAccounts(); registerAccounts();
} }
...@@ -591,21 +590,15 @@ void ManagerImpl::transferSucceded () ...@@ -591,21 +590,15 @@ void ManagerImpl::transferSucceded ()
bool ManagerImpl::attendedTransfer(const std::string& transferID, const std::string& targetID) bool ManagerImpl::attendedTransfer(const std::string& transferID, const std::string& targetID)
{ {
bool returnValue = false; bool returnValue;;
_debug("Manager: Attended transfer");
// Direct IP to IP call // Direct IP to IP call
if (getConfigFromCall (transferID) == Call::IPtoIP) if (getConfigFromCall (transferID) == Call::IPtoIP)
returnValue = SIPVoIPLink::instance ()-> attendedTransfer(transferID, targetID); returnValue = SIPVoIPLink::instance ()-> attendedTransfer(transferID, targetID);
else { // Classic call, attached to an account else { // Classic call, attached to an account
std::string accountid = getAccountFromCall (transferID); std::string accountid = getAccountFromCall (transferID);
if (accountid.empty())
if (accountid.empty()) {
_warn ("Manager: Call doesn't exists");
return false; return false;
}
returnValue = getAccountLink (accountid)->attendedTransfer (transferID, targetID); returnValue = getAccountLink (accountid)->attendedTransfer (transferID, targetID);
} }
...@@ -618,20 +611,11 @@ bool ManagerImpl::attendedTransfer(const std::string& transferID, const std::str ...@@ -618,20 +611,11 @@ bool ManagerImpl::attendedTransfer(const std::string& transferID, const std::str
//THREAD=Main : Call:Incoming //THREAD=Main : Call:Incoming
bool ManagerImpl::refuseCall (const std::string& id) bool ManagerImpl::refuseCall (const std::string& id)
{ {
std::string accountid;
bool returnValue; bool returnValue;
_debug ("Manager: Refuse call %s", id.c_str());
std::string current_call_id = getCurrentCallId();
stopTone(); stopTone();
int nbCalls = getCallList().size(); if (getCallList().size() <= 1) {
if (nbCalls <= 1) {
_debug (" refuseCall: stop audio stream, there is only %d call(s) remaining", nbCalls);
audioLayerMutexLock(); audioLayerMutexLock();
_audiodriver->stopStream(); _audiodriver->stopStream();
audioLayerMutexUnlock(); audioLayerMutexUnlock();
...@@ -643,12 +627,9 @@ bool ManagerImpl::refuseCall (const std::string& id) ...@@ -643,12 +627,9 @@ bool ManagerImpl::refuseCall (const std::string& id)
returnValue = SIPVoIPLink::instance ()-> refuse (id); returnValue = SIPVoIPLink::instance ()-> refuse (id);
else { else {
/* Classic call, attached to an account */ /* Classic call, attached to an account */
accountid = getAccountFromCall (id); std::string accountid = getAccountFromCall (id);
if (accountid.empty())
if (accountid.empty()) {
_warn ("Manager: Call doesn't exists");
return false; return false;
}
returnValue = getAccountLink (accountid)->refuse (id); returnValue = getAccountLink (accountid)->refuse (id);
...@@ -659,7 +640,6 @@ bool ManagerImpl::refuseCall (const std::string& id) ...@@ -659,7 +640,6 @@ bool ManagerImpl::refuseCall (const std::string& id)
// so the method did nothing // so the method did nothing
if (returnValue) { if (returnValue) {
removeWaitingCall (id); removeWaitingCall (id);
_dbus.getCallManager()->callStateChanged (id, "HUNGUP"); _dbus.getCallManager()->callStateChanged (id, "HUNGUP");
} }
...@@ -1329,11 +1309,11 @@ void ManagerImpl::saveConfig (void) ...@@ -1329,11 +1309,11 @@ void ManagerImpl::saveConfig (void)
} }
//THREAD=Main //THREAD=Main
bool ManagerImpl::sendDtmf (const std::string& id, char code) void ManagerImpl::sendDtmf (const std::string& id, char code)
{ {
std::string accountid(getAccountFromCall(id)); std::string accountid(getAccountFromCall(id));
playDtmf (code); playDtmf (code);
return getAccountLink (accountid)->carryingDTMFdigits (id, code); getAccountLink (accountid)->carryingDTMFdigits (id, code);
} }
//THREAD=Main | VoIPLink //THREAD=Main | VoIPLink
...@@ -2866,7 +2846,7 @@ ManagerImpl::getAccount (const std::string& accountID) const ...@@ -2866,7 +2846,7 @@ ManagerImpl::getAccount (const std::string& accountID) const
if (iter != _accountMap.end()) if (iter != _accountMap.end())
return iter->second; return iter->second;
_debug ("Manager: Did not found account %s, returning IP2IP account", accountID.c_str()); _debug ("Manager: Did not found account \"%s\", returning IP2IP account", accountID.c_str());
return getAccount(IP2IP_PROFILE); return getAccount(IP2IP_PROFILE);
} }
......
...@@ -339,7 +339,7 @@ class ManagerImpl ...@@ -339,7 +339,7 @@ class ManagerImpl
* @param id: callid of the line. * @param id: callid of the line.
* @param code: pressed key. * @param code: pressed key.
*/ */
bool sendDtmf (const std::string& id, char code); void sendDtmf (const std::string& id, char code);
/** /**
* Play a ringtone * Play a ringtone
......
...@@ -99,11 +99,6 @@ static const char * const transactionStateMap[] = { ...@@ -99,11 +99,6 @@ static const char * const transactionStateMap[] = {
"PJSIP_TSX_STATE_MAX" "PJSIP_TSX_STATE_MAX"
}; };
struct result {
pj_status_t status;
pjsip_server_addresses servers;
};
/** The default transport (5060) */ /** The default transport (5060) */
pjsip_transport *_localUDPTransport = NULL; pjsip_transport *_localUDPTransport = NULL;
...@@ -164,11 +159,6 @@ pjsip_module _mod_ua; ...@@ -164,11 +159,6 @@ pjsip_module _mod_ua;
pj_thread_t *thread; pj_thread_t *thread;
pj_thread_desc desc; pj_thread_desc desc;
/**
* Get the number of voicemail waiting in a SIP message
*/
void setVoicemailInfo (const std::string &account, pjsip_msg_body *body);
/* /*
* Session callback * Session callback
* Called after SDP offer/answer session has completed. * Called after SDP offer/answer session has completed.
...@@ -547,11 +537,7 @@ Call *SIPVoIPLink::newOutgoingCall (const std::string& id, const std::string& to ...@@ -547,11 +537,7 @@ Call *SIPVoIPLink::newOutgoingCall (const std::string& id, const std::string& to
call->getLocalSDP()->setLocalIP (addrSdp); call->getLocalSDP()->setLocalIP (addrSdp);
call->getLocalSDP()->createOffer(account->getActiveCodecs()); call->getLocalSDP()->createOffer(account->getActiveCodecs());
if (SIPStartCall(call)) { if (!SIPStartCall(call)) {
call->setConnectionState (Call::Progressing);
call->setState (Call::Active);
addCall (call);
} else {
delete call; delete call;
throw VoipLinkException("Could not send outgoing INVITE request for new call"); throw VoipLinkException("Could not send outgoing INVITE request for new call");
} }
...@@ -614,14 +600,8 @@ SIPVoIPLink::hangup (const std::string& id) ...@@ -614,14 +600,8 @@ SIPVoIPLink::hangup (const std::string& id)
// Make sure user data is NULL in callbacks // Make sure user data is NULL in callbacks
inv->mod_data[getModId()] = NULL; inv->mod_data[getModId()] = NULL;
// Release RTP thread
try {
if (Manager::instance().isCurrentCall (id)) if (Manager::instance().isCurrentCall (id))
call->getAudioRtp()->stop(); call->getAudioRtp()->stop();
}
catch (...) {
throw VoipLinkException("Could not stop audio rtp session");
}
removeCall (id); removeCall (id);
} }
...@@ -629,8 +609,6 @@ SIPVoIPLink::hangup (const std::string& id) ...@@ -629,8 +609,6 @@ SIPVoIPLink::hangup (const std::string& id)
void void
SIPVoIPLink::peerHungup (const std::string& id) SIPVoIPLink::peerHungup (const std::string& id)
{ {
_info ("UserAgent: Peer hungup");
SIPCall* call = getSIPCall(id); SIPCall* call = getSIPCall(id);
// User hangup current call. Notify peer // User hangup current call. Notify peer
...@@ -644,44 +622,18 @@ SIPVoIPLink::peerHungup (const std::string& id) ...@@ -644,44 +622,18 @@ SIPVoIPLink::peerHungup (const std::string& id)
// Make sure user data is NULL in callbacks // Make sure user data is NULL in callbacks
call->inv->mod_data[getModId() ] = NULL; call->inv->mod_data[getModId() ] = NULL;
// Release RTP thread if (Manager::instance().isCurrentCall (id))
try {
if (Manager::instance().isCurrentCall (id)) {
_debug ("UserAgent: Stopping AudioRTP for hangup");
call->getAudioRtp()->stop(); call->getAudioRtp()->stop();
}
}
catch (...) {
throw VoipLinkException("Could not stop audio rtp session");
}
removeCall (id); removeCall (id);
} }
void
SIPVoIPLink::cancel (const std::string& id)
{
_info ("UserAgent: Cancel call %s", id.c_str());
removeCall (id);
}
void void
SIPVoIPLink::onhold (const std::string& id) SIPVoIPLink::onhold (const std::string& id)
{ {
SIPCall *call = getSIPCall(id); SIPCall *call = getSIPCall(id);
// Stop sound
call->setState (Call::Hold); call->setState (Call::Hold);
try {
call->getAudioRtp()->stop(); call->getAudioRtp()->stop();
}
catch (...) {
throw VoipLinkException("Could not stop audio rtp session");
}
_debug ("UserAgent: Stopping RTP session for on hold action");
Sdp *sdpSession = call->getLocalSDP(); Sdp *sdpSession = call->getLocalSDP();
if (!sdpSession) if (!sdpSession)
...@@ -689,18 +641,14 @@ SIPVoIPLink::onhold (const std::string& id) ...@@ -689,18 +641,14 @@ SIPVoIPLink::onhold (const std::string& id)
sdpSession->removeAttributeFromLocalAudioMedia("sendrecv"); sdpSession->removeAttributeFromLocalAudioMedia("sendrecv");
sdpSession->removeAttributeFromLocalAudioMedia("sendonly"); sdpSession->removeAttributeFromLocalAudioMedia("sendonly");
sdpSession->addAttributeToLocalAudioMedia("sendonly"); sdpSession->addAttributeToLocalAudioMedia("sendonly");
// Create re-INVITE with new offer
SIPSessionReinvite (call); SIPSessionReinvite (call);
} }
void void
SIPVoIPLink::offhold (const std::string& id) SIPVoIPLink::offhold (const std::string& id)
{ {
_debug ("UserAgent: retrive call from hold status");
SIPCall *call = getSIPCall (id); SIPCall *call = getSIPCall (id);
Sdp *sdpSession = call->getLocalSDP(); Sdp *sdpSession = call->getLocalSDP();
...@@ -750,16 +698,15 @@ SIPVoIPLink::offhold (const std::string& id) ...@@ -750,16 +698,15 @@ SIPVoIPLink::offhold (const std::string& id)
call->setState (Call::Active); call->setState (Call::Active);
} }
bool void
SIPVoIPLink::sendTextMessage (sfl::InstantMessaging *module, const std::string& callID, const std::string& message, const std::string& from) SIPVoIPLink::sendTextMessage (sfl::InstantMessaging *module, const std::string& callID, const std::string& message, const std::string& from)
{ {