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

SIP: simplify

parent d81435fa
......@@ -60,7 +60,6 @@ AudioRtpSession::AudioRtpSession (SIPCall * sipcall, RtpMethod type, ost::RTPDat
AudioRtpSession::~AudioRtpSession()
{
_info ("AudioRtpSession: Delete AudioRtpSession instance");
_queue->disableStack();
}
......
......@@ -33,6 +33,8 @@
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
std::string cmd = command + "\"" + args + "\" &";
system(cmd.c_str());
......
......@@ -474,36 +474,29 @@ IAXVoIPLink::refuse (const std::string& id)
}
bool
void
IAXVoIPLink::carryingDTMFdigits (const std::string& id, char code)
{
IAXCall* call = getIAXCall (id);
CHK_VALID_CALL;
mutexIAX_.enterMutex();
iax_send_dtmf (call->getSession(), code);
mutexIAX_.leaveMutex();
return true;
if (call) {
mutexIAX_.enterMutex();
iax_send_dtmf (call->getSession(), code);
mutexIAX_.leaveMutex();
}
}
bool
void
IAXVoIPLink::sendTextMessage (sfl::InstantMessaging *module,
const std::string& callID, const std::string& message,
const std::string& /*from*/)
{
IAXCall* call = getIAXCall (callID);
CHK_VALID_CALL;
if (!call)
return;
// Must active the mutex for this session
mutexIAX_.enterMutex();
module->send_iax_message (call->getSession(), callID, message.c_str());
// iax_send_text (call->getSession(), message.c_str());
mutexIAX_.leaveMutex();
return true;
}
......@@ -649,28 +642,17 @@ IAXVoIPLink::iaxHandleCallEvent (iax_event* event, IAXCall* call)
break;
case IAX_IE_MSGCOUNT:
break;
case IAX_EVENT_TIMEOUT:
case IAX_EVENT_PONG:
default:
break;
case IAX_EVENT_URL:
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);
}
}
if (Manager::instance().getConfigString (HOOKS, URLHOOK_IAX2_ENABLED) == "1")
UrlHook::runAction (Manager::instance().getConfigString (HOOKS, URLHOOK_COMMAND), (char*) event->data);
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
* Send DTMF
* @param id The ID of the call
* @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
......
......@@ -54,9 +54,7 @@ static void XMLCALL endElementCallback (void * /*userData*/, const char * /*name
}
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::
}
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)
{
std::vector<std::string> msgs = split_message (message);
std::vector<std::string>::const_iterator 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
*/
~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.
* Longer messages should be splitted in several smaller messages using split_message
*/
unsigned int getMessageMaximumSize (void) {
return messageMaxSize;
size_t getMessageMaximumSize (void) {
return MAXIMUM_MESSAGE_LENGTH;
}
/*
......@@ -120,9 +113,6 @@ class InstantMessaging
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 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&);
std::vector<std::string> split_message(std::string);
......@@ -177,24 +167,8 @@ class InstantMessaging
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& operator= (const InstantMessaging&); //No Assignment Operator
/**
* Maximum size in char of an instant message
*/
unsigned int messageMaxSize;
};
}
#endif // _INSTANT_MESSAGING_H
......@@ -128,7 +128,6 @@ void ManagerImpl::init (std::string config_file)
audioLayerMutexUnlock();
_history->load_history (preferences.getHistoryLimit());
_imModule->init();
registerAccounts();
}
......@@ -591,21 +590,15 @@ void ManagerImpl::transferSucceded ()
bool ManagerImpl::attendedTransfer(const std::string& transferID, const std::string& targetID)
{
bool returnValue = false;
_debug("Manager: Attended transfer");
bool returnValue;;
// Direct IP to IP call
if (getConfigFromCall (transferID) == Call::IPtoIP)
returnValue = SIPVoIPLink::instance ()-> attendedTransfer(transferID, targetID);
else { // Classic call, attached to an account
std::string accountid = getAccountFromCall (transferID);
if (accountid.empty()) {
_warn ("Manager: Call doesn't exists");
if (accountid.empty())
return false;
}
returnValue = getAccountLink (accountid)->attendedTransfer (transferID, targetID);
}
......@@ -618,20 +611,11 @@ bool ManagerImpl::attendedTransfer(const std::string& transferID, const std::str
//THREAD=Main : Call:Incoming
bool ManagerImpl::refuseCall (const std::string& id)
{
std::string accountid;
bool returnValue;
_debug ("Manager: Refuse call %s", id.c_str());
std::string current_call_id = getCurrentCallId();
stopTone();
int nbCalls = getCallList().size();
if (nbCalls <= 1) {
_debug (" refuseCall: stop audio stream, there is only %d call(s) remaining", nbCalls);
if (getCallList().size() <= 1) {
audioLayerMutexLock();
_audiodriver->stopStream();
audioLayerMutexUnlock();
......@@ -643,12 +627,9 @@ bool ManagerImpl::refuseCall (const std::string& id)
returnValue = SIPVoIPLink::instance ()-> refuse (id);
else {
/* Classic call, attached to an account */
accountid = getAccountFromCall (id);
if (accountid.empty()) {
_warn ("Manager: Call doesn't exists");
std::string accountid = getAccountFromCall (id);
if (accountid.empty())
return false;
}
returnValue = getAccountLink (accountid)->refuse (id);
......@@ -659,7 +640,6 @@ bool ManagerImpl::refuseCall (const std::string& id)
// so the method did nothing
if (returnValue) {
removeWaitingCall (id);
_dbus.getCallManager()->callStateChanged (id, "HUNGUP");
}
......@@ -1329,11 +1309,11 @@ void ManagerImpl::saveConfig (void)
}
//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));
playDtmf (code);
return getAccountLink (accountid)->carryingDTMFdigits (id, code);
getAccountLink (accountid)->carryingDTMFdigits (id, code);
}
//THREAD=Main | VoIPLink
......@@ -2866,7 +2846,7 @@ ManagerImpl::getAccount (const std::string& accountID) const
if (iter != _accountMap.end())
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);
}
......
......@@ -339,7 +339,7 @@ class ManagerImpl
* @param id: callid of the line.
* @param code: pressed key.
*/
bool sendDtmf (const std::string& id, char code);
void sendDtmf (const std::string& id, char code);
/**
* Play a ringtone
......
This diff is collapsed.
......@@ -46,6 +46,7 @@
#include <pjnath/stun_config.h>
///////////////////////////////
#include "sipaccount.h"
#include "voiplink.h"
namespace sfl {
......@@ -56,9 +57,6 @@ class EventThread;
class SIPCall;
class SIPAccount;
// To set the verbosity. From 0 (min) to 6 (max)
#define PJ_LOG_LEVEL 0
/**
* @file sipvoiplink.h
* @brief Specific VoIPLink for SIP (SIP core for incoming and outgoing events).
......@@ -132,12 +130,6 @@ class SIPVoIPLink : public VoIPLink
*/
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
* @param id The call identifier
......@@ -179,9 +171,8 @@ class SIPVoIPLink : public VoIPLink
* Send DTMF refering to account configuration
* @param id The call identifier
* @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
......@@ -287,10 +278,8 @@ class SIPVoIPLink : public VoIPLink
* @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
*/
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
......@@ -309,11 +298,8 @@ class SIPVoIPLink : public VoIPLink
* @return true if all is correct
*/
bool SIPStartCall (SIPCall* call);
/**
* Send Dtmf using SIP INFO message
*/
void dtmfSipInfo (SIPCall *call, char code);
void dtmfOverRtp (SIPCall *call, char code);
void dtmfSend (SIPCall *call, char code, DtmfType type);
/* Assignment Operator */
SIPVoIPLink& operator= (const SIPVoIPLink& rh);
......
......@@ -116,12 +116,6 @@ class VoIPLink
*/
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
* @param id The call identifier
......@@ -163,9 +157,8 @@ class VoIPLink
* Send DTMF
* @param id The call identifier
* @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
......@@ -180,10 +173,8 @@ class VoIPLink
* @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;
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)
* @param call A call pointer with a unique pointer
......
......@@ -101,47 +101,6 @@ void InstantMessagingTest::testSaveMultipleMessage ()
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)));
/* A message that needs to be split into four messages */
std::string very_long_message = "A message that needs to be split into many messages";
messages = _im->split_message (very_long_message);
size = messages.size ();
/* If only one element, do not enter the loop */
for (i = 0; i < size - 1; i++) {
CPPUNIT_ASSERT (messages[i] ==very_long_message.substr ( (maxSize * i), maxSize) + DELIMITER_CHAR);
}
/* Works for the last element, or for the only element */
CPPUNIT_ASSERT (messages[size- 1] == very_long_message.substr (maxSize * (size-1)));
}
static inline char* duplicateString(char dst[], const char src[], size_t len)
{
memcpy(dst, src, len);
......
......@@ -55,7 +55,6 @@ class InstantMessagingTest : public CppUnit::TestCase {
CPPUNIT_TEST_SUITE( InstantMessagingTest );
CPPUNIT_TEST (testSaveSingleMessage);
CPPUNIT_TEST (testSaveMultipleMessage);
CPPUNIT_TEST (testSplitMessage);
CPPUNIT_TEST (testGenerateXmlUriList);
CPPUNIT_TEST (testXmlUriListParsing);
CPPUNIT_TEST (testGetTextArea);
......@@ -82,8 +81,6 @@ class InstantMessagingTest : public CppUnit::TestCase {
void testSaveMultipleMessage ();
void testSplitMessage ();
void testGenerateXmlUriList ();
void testXmlUriListParsing ();
......
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