Commit 564aeb4d authored by Alexandre Savard's avatar Alexandre Savard
Browse files

[#4071] Move src/sip/im to src/im since common to both SIP and IAX

parent cd95ae69
......@@ -52,7 +52,7 @@ AC_CONFIG_FILES([Makefile])
AC_CONFIG_FILES([src/Makefile \
src/sip/Makefile \
src/sip/im/Makefile \
src/im/Makefile \
src/iax/Makefile \
src/audio/Makefile \
src/audio/audiortp/Makefile \
......
......@@ -3,7 +3,7 @@ include ../globals.mak
libexecdir=$(libdir)/sflphone
libexec_PROGRAMS = sflphoned
SUBDIRS = dbus audio config plug-in hooks history sip iax
SUBDIRS = dbus audio config plug-in hooks history sip iax im
# Add here the cpp files to be build with sflphone
sflphoned_SOURCES = \
......@@ -66,6 +66,7 @@ libsflphone_la_LIBADD = \
$(src)/libs/iax2/libiax2.la \
$(src)/libs/dbus-c++/src/libdbus-c++-1.la \
$(IAX_LIB) \
./im/libim.la \
./sip/libsiplink.la \
./audio/libaudio.la \
./dbus/libdbus.la \
......
......@@ -702,13 +702,17 @@ IAXVoIPLink::carryingDTMFdigits (const CallID& id, char code)
}
bool
IAXVoIPLink::sendTextMessage (const std::string& callID, const std::string& message, const std::string& from)
IAXVoIPLink::sendTextMessage (sfl::InstantMessaging *module, const std::string& callID, const std::string& message, const std::string& from)
{
IAXCall* call = getIAXCall (callID);
CHK_VALID_CALL;
// Must active the mutex for this session
_mutexIAX.enterMutex();
// module->send_iax_message(call->getSession(), message.c_str());
iax_send_text (call->getSession(), message.c_str());
_mutexIAX.leaveMutex();
......
......@@ -40,6 +40,8 @@
#include "audio/samplerateconverter.h"
#include "hooks/urlhook.h"
#include "im/InstantMessaging.h"
class EventThread;
class IAXCall;
......@@ -189,7 +191,7 @@ class IAXVoIPLink : public VoIPLink
bool carryingDTMFdigits (const CallID& id, char code);
bool sendTextMessage (const std::string& callID, const std::string& message, const std::string& from);
bool sendTextMessage (sfl::InstantMessaging *module, const std::string& callID, const std::string& message, const std::string& from);
bool isContactPresenceSupported() {
return false;
......
......@@ -189,7 +189,7 @@ pj_status_t InstantMessaging::send (pjsip_inv_session *session, CallID& id, cons
return PJ_SUCCESS;
}
pj_status_t InstantMessaging::send_message (pjsip_inv_session *session, CallID& id, const std::string& message)
pj_status_t InstantMessaging::send_sip_message (pjsip_inv_session *session, CallID& id, const std::string& message)
{
/* Check the length of the message */
......
......@@ -131,7 +131,7 @@ class InstantMessaging
*/
pj_status_t send (pjsip_inv_session*, CallID& id, const std::string&);
pj_status_t send_message (pjsip_inv_session*, CallID& id, const std::string&);
pj_status_t send_sip_message (pjsip_inv_session*, CallID& id, const std::string&);
std::vector<std::string> split_message (const std::string&);
......
......@@ -93,6 +93,7 @@ ManagerImpl::ManagerImpl (void) :
_cleaner = new NumberCleaner();
_history = new HistoryManager();
_imModule = new sfl::InstantMessaging();
#ifdef TEST
testAccountMap();
......@@ -118,6 +119,8 @@ ManagerImpl::~ManagerImpl (void)
_cleaner = NULL;
delete _history;
_history = NULL;
delete _imModule;
_imModule = NULL;
_debug ("Manager: %s stop correctly.", PROGNAME);
}
......@@ -160,6 +163,9 @@ void ManagerImpl::init ()
// Load the history
_history->load_history (preferences.getHistoryLimit());
// Init the instant messaging module
_imModule->init();
}
void ManagerImpl::terminate ()
......@@ -1733,8 +1739,8 @@ void ManagerImpl::incomingMessage (const CallID& callID,
link = SIPVoIPLink::instance (""); // dynamic_cast<SIPVoIPLink *> (getAccountLink (*iter_participant));
if (link)
link->sendTextMessage (*iter_participant, message, from);
if (link && _imModule)
link->sendTextMessage (_imModule, *iter_participant, message, from);
}
iter_participant++;
......@@ -1776,8 +1782,8 @@ bool ManagerImpl::sendTextMessage (const CallID& callID, const std::string& mess
link = SIPVoIPLink::instance (""); // dynamic_cast<SIPVoIPLink *> (getAccountLink (*iter_participant));
if (link)
link->sendTextMessage (*iter_participant, message, from);
if (link && _imModule)
link->sendTextMessage (_imModule, *iter_participant, message, from);
iter_participant++;
}
......@@ -1801,8 +1807,8 @@ bool ManagerImpl::sendTextMessage (const CallID& callID, const std::string& mess
link = SIPVoIPLink::instance (""); // dynamic_cast<SIPVoIPLink *> (getAccountLink (*iter_participant));
if (link)
link->sendTextMessage (*iter_participant, message, from);
if (link && _imModule)
link->sendTextMessage (_imModule, *iter_participant, message, from);
iter_participant++;
}
......@@ -1820,10 +1826,10 @@ bool ManagerImpl::sendTextMessage (const CallID& callID, const std::string& mess
if (account->getType() == "SIP")
// link = dynamic_cast<SIPVoIPLink *> (getAccountLink (accountId));
dynamic_cast<SIPVoIPLink *> (getAccountLink (accountId))->sendTextMessage (callID, message, from);
dynamic_cast<SIPVoIPLink *> (getAccountLink (accountId))->sendTextMessage (_imModule, callID, message, from);
else if (account->getType() == "IAX")
// link = dynamic_cast<IAXVoIPLink *> (account->getVoIPLink());
dynamic_cast<IAXVoIPLink *> (account->getVoIPLink())->sendTextMessage (callID, message, from);
dynamic_cast<IAXVoIPLink *> (account->getVoIPLink())->sendTextMessage (_imModule, callID, message, from);
else {
//link = NULL;
......
......@@ -59,6 +59,8 @@
#include "yamlparser.h"
#include "preferences.h"
#include "im/InstantMessaging.h"
class AudioLayer;
class GuiFramework;
class TelephoneTone;
......@@ -1309,6 +1311,13 @@ class ManagerImpl
MainBuffer _mainBuffer;
/**
* Instant messaging module, resposible to initiate, format, parse,
* send, and receive instant messages.
*/
sfl::InstantMessaging *_imModule;
public:
/**
......@@ -1318,6 +1327,13 @@ class ManagerImpl
return &_mainBuffer;
}
/**
* Return a pointer to the instance of InstantMessaging
*/
sfl::InstantMessaging *getInstantMessageModule (void) {
return _imModule;
}
/**
* Tell if there is a current call processed
......
SUBDIRS=im
include $(top_srcdir)/globals.mak
noinst_LTLIBRARIES = libsiplink.la
......@@ -13,8 +11,6 @@ libsiplink_la_SOURCES = \
sipcall.cpp \
sipvoiplink.cpp
libsiplink_la_LIBADD = im/libim.la
noinst_HEADERS = \
Pattern.h \
SdesNegotiator.h \
......
......@@ -45,6 +45,8 @@
#include "dbus/dbusmanager.h"
#include "dbus/callmanager.h"
#include "im/InstantMessaging.h"
#include "pjsip/sip_endpoint.h"
#include "pjsip/sip_transport_tls.h"
#include "pjsip/sip_transport_tls.h"
......@@ -165,11 +167,6 @@ pj_thread_desc desc;
*/
UrlHook *urlhook;
/*
* Instant Messaging module
*/
InstantMessaging *imModule;
/**
* Get the number of voicemail waiting in a SIP message
*/
......@@ -280,9 +277,6 @@ SIPVoIPLink::SIPVoIPLink (const AccountID& accountID)
urlhook = new UrlHook ();
// Load the chat module
imModule = new InstantMessaging ();
/* Start pjsip initialization step */
init();
}
......@@ -1062,7 +1056,7 @@ SIPVoIPLink::onhold (const CallID& id)
}
bool
SIPVoIPLink::sendTextMessage (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)
{
_debug ("SipVoipLink: Send text message to %s, from %s", callID.c_str(), from.c_str());
......@@ -1085,9 +1079,10 @@ SIPVoIPLink::sendTextMessage (const std::string& callID, const std::string& mess
list.push_front (&entry);
std::string formatedMessage = imModule->appendUriList (message, list);
std::string formatedMessage = module->appendUriList (message, list);
status = module->send_sip_message (call->getInvSession (), (CallID&) callID, formatedMessage);
status = imModule->send_message (call->getInvSession (), (CallID&) callID, formatedMessage);
} else {
/* Notify the client of an error */
/*Manager::instance ().incomingMessage ( "",
......@@ -2096,9 +2091,6 @@ bool SIPVoIPLink::pjsip_init()
const pj_str_t STR_MIME_TEXT_PLAIN = { (char*) "text/plain", 10 };
pjsip_endpt_add_capability (_endpt, &_mod_ua, PJSIP_H_ACCEPT, NULL, 1, &STR_MIME_TEXT_PLAIN);
// Registering and initializing IM module
imModule->init ();
// Register "application/sdp" in ACCEPT header
pjsip_endpt_add_capability (_endpt, &_mod_ua, PJSIP_H_ACCEPT, NULL, 1, &accepted);
......@@ -3496,24 +3488,26 @@ void call_on_tsx_changed (pjsip_inv_session *inv UNUSED, pjsip_transaction *tsx,
std::string message;
std::string urilist;
InstantMessaging::UriList list;
sfl::InstantMessaging::UriList list;
sfl::InstantMessaging *module = Manager::instance().getInstantMessageModule();
try {
// retrive message from formated text
message = imModule->findTextMessage (formatedMessage);
message = module->findTextMessage (formatedMessage);
// retreive the recipient-list of this message
urilist = imModule->findTextUriList (formatedMessage);
urilist = module->findTextUriList (formatedMessage);
// parse the recipient list xml
list = imModule->parseXmlUriList (urilist);
list = module->parseXmlUriList (urilist);
// If no item present in the list, peer is considered as the sender
if (list.empty()) {
from = call->getPeerNumber ();
} else {
InstantMessaging::UriEntry *entry = list.front();
InstantMessaging::UriEntry::iterator iterAttr = entry->find (IM_XML_URI);
sfl::InstantMessaging::UriEntry *entry = list.front();
sfl::InstantMessaging::UriEntry::iterator iterAttr = entry->find (IM_XML_URI);
if (iterAttr->second != "Me")
from = iterAttr->second;
......@@ -3539,7 +3533,8 @@ void call_on_tsx_changed (pjsip_inv_session *inv UNUSED, pjsip_transaction *tsx,
// Pass through the instant messaging module if needed
// Right now, it does do anything.
// And notify the clients
Manager::instance ().incomingMessage (call->getCallId (), stripped, imModule->receive (message, stripped, call->getCallId ()));
Manager::instance ().incomingMessage (call->getCallId (), stripped, module->receive (message, stripped, call->getCallId ()));
}
......
......@@ -37,7 +37,7 @@
#include "voiplink.h"
#include "hooks/urlhook.h"
#include "im/InstantMessaging.h"
#include "../im/InstantMessaging.h"
//////////////////////////////
/* PJSIP imports */
......@@ -366,15 +366,16 @@ class SIPVoIPLink : public VoIPLink
/**
* Send a SIP message to a call identified by its callid
*
* Send a SIP 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
*/
bool sendTextMessage (const std::string& callID, const std::string& message, const std::string& from);
bool sendTextMessage (sfl::InstantMessaging *module, const std::string& callID, const std::string& message, const std::string& from);
private:
/**
......
......@@ -37,7 +37,7 @@
#include <assert.h>
// Application import
#include "sip/im/InstantMessaging.h"
#include "im/InstantMessaging.h"
/*
* @file instantmessagingtest.h
......
Supports Markdown
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