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) { UrlHook::runAction (Manager::instance().getConfigString (HOOKS, URLHOOK_COMMAND), (char*) event->data);
_debug ("> IAX_EVENT_URL received: %s", event->data);
UrlHook::runAction (Manager::instance().getConfigString (HOOKS, URLHOOK_COMMAND), (char*) event->data);
}
}
break; break;
case IAX_EVENT_TIMEOUT:
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
......
This diff is collapsed.
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
#include <pjnath/stun_config.h> #include <pjnath/stun_config.h>
/////////////////////////////// ///////////////////////////////
#include "sipaccount.h"
#include "voiplink.h" #include "voiplink.h"
namespace sfl { namespace sfl {
...@@ -56,9 +57,6 @@ class EventThread; ...@@ -56,9 +57,6 @@ class EventThread;
class SIPCall; class SIPCall;
class SIPAccount; class SIPAccount;
// To set the verbosity. From 0 (min) to 6 (max)
#define PJ_LOG_LEVEL 0
/** /**
* @file sipvoiplink.h * @file sipvoiplink.h
* @brief Specific VoIPLink for SIP (SIP core for incoming and outgoing events). * @brief Specific VoIPLink for SIP (SIP core for incoming and outgoing events).
...@@ -132,12 +130,6 @@ class SIPVoIPLink : public VoIPLink ...@@ -132,12 +130,6 @@ class SIPVoIPLink : public VoIPLink
*/ */
virtual void peerHungup (const std::string& id); virtual void peerHungup (const std::string& id);
/**
* Cancel the call
* @param id The call identifier
*/
virtual void cancel (const std::string& id);
/** /**
* Put the call on hold * Put the call on hold
* @param id The call identifier * @param id The call identifier
...@@ -179,9 +171,8 @@ class SIPVoIPLink : public VoIPLink ...@@ -179,9 +171,8 @@ class SIPVoIPLink : public VoIPLink
* Send DTMF refering to account configuration * Send DTMF refering to account configuration
* @param id The call identifier * @param id The call identifier
* @param code The char code * @param code The char code
* @return bool True on success
*/ */
virtual bool carryingDTMFdigits (const std::string& id, char code); virtual void carryingDTMFdigits (const std::string& id, char code);
/** /**
* Start a new SIP call using the IP2IP profile * Start a new SIP call using the IP2IP profile
...@@ -287,10 +278,8 @@ class SIPVoIPLink : public VoIPLink ...@@ -287,10 +278,8 @@ class SIPVoIPLink : public VoIPLink
* @param The Id of the call to send the message to * @param The Id of the call to send the message to
* @param The actual message to be transmitted * @param The actual message to be transmitted
* @param The sender of this message (could be another participant of a conference) * @param The sender of this message (could be another participant of a conference)
*
* @return True if the message is sent without error, false elsewhere
*/ */
bool sendTextMessage (sfl::InstantMessaging *module, const std::string& callID, const std::string& message, const std::string& from); void sendTextMessage (sfl::InstantMessaging *module, const std::string& callID, const std::string& message, const std::string& from);
/** /**
* Create the default UDP transport according ot Ip2Ip profile settings * Create the default UDP transport according ot Ip2Ip profile settings
...@@ -309,11 +298,8 @@ class SIPVoIPLink : public VoIPLink ...@@ -309,11 +298,8 @@ class SIPVoIPLink : public VoIPLink
* @return true if all is correct * @return true if all is correct
*/ */
bool SIPStartCall (SIPCall* call); bool SIPStartCall (SIPCall* call);
/**
* Send Dtmf using SIP INFO message void dtmfSend (SIPCall *call, char code, DtmfType type);
*/
void dtmfSipInfo (SIPCall *call, char code);
void dtmfOverRtp (SIPCall *call, char code);
/* Assignment Operator */ /* Assignment Operator */
SIPVoIPLink& operator= (const SIPVoIPLink& rh); SIPVoIPLink& operator= (const SIPVoIPLink& rh);
......
...@@ -116,12 +116,6 @@ class VoIPLink ...@@ -116,12 +116,6 @@ class VoIPLink
*/ */
virtual void peerHungup (const std::string& id) = 0; virtual void peerHungup (const std::string& id) = 0;
/**
* Cancel the call dialing
* @param id The call identifier
*/
virtual void cancel (const std::string& id) = 0;
/** /**
* Put a call on hold * Put a call on hold
* @param id The call identifier * @param id The call identifier
...@@ -163,9 +157,8 @@ class VoIPLink ...@@ -163,9 +157,8 @@ class VoIPLink
* Send DTMF * Send DTMF
* @param id The call identifier * @param id The call identifier
* @param code The char code * @param code The char code
* @return bool True on success
*/ */
virtual bool carryingDTMFdigits (const std::string& id, char code) = 0; virtual void carryingDTMFdigits (const std::string& id, char code) = 0;
/** /**
* Return the codec protocol used for this call * Return the codec protocol used for this call
...@@ -180,10 +173,8 @@ class VoIPLink ...@@ -180,10 +173,8 @@ class VoIPLink
* @param The Id of the call to send the message to * @param The Id of the call to send the message to
* @param The actual message to be transmitted * @param The actual message to be transmitted
* @param The sender of this message (could be another participant of a conference) * @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; virtual void 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) /** Add a call to the call map (protected by mutex)
* @param call A call pointer with a unique pointer * @param call A call pointer with a unique pointer
......
...@@ -101,47 +101,6 @@ void InstantMessagingTest::testSaveMultipleMessage () ...@@ -101,47 +101,6 @@ void InstantMessagingTest::testSaveMultipleMessage ()
CPPUNIT_ASSERT (input == "[Manu] Bonjour, c'est un test d'archivage de message[Alex] Cool"); CPPUNIT_ASSERT (input == "[Manu] Bonjour, c'est un test d'archivage de message[Alex] Cool");
} }
void InstantMessagingTest::testSplitMessage ()
{
_im->setMessageMaximumSize(10);
unsigned int maxSize = _im->getMessageMaximumSize();
/* A message that does not need to be split */
std::string short_message = "Salut";
std::vector<std::string> messages = _im->split_message (short_message);
CPPUNIT_ASSERT (messages.size() == short_message.length() / maxSize + 1);
CPPUNIT_ASSERT (messages[0] == short_message);
/* A message that needs to be split into two messages */
std::string long_message = "A message too long";
messages = _im->split_message (long_message);
int size = messages.size ();
int i = 0;
CPPUNIT_ASSERT (size == (int) (long_message.length() / maxSize + 1));
/* If only one element, do not enter the loop */
for (i = 0; i < size - 1; i++) {
CPPUNIT_ASSERT (messages[i] == long_message.substr ( (maxSize * i), maxSize) + DELIMITER_CHAR);
}
/* Works for the last element, or for the only element */
CPPUNIT_ASSERT (messages[size- 1] == long_message.substr (maxSize * (size-1)));