Commit b5ceece8 authored by Alexandre Savard's avatar Alexandre Savard
Browse files

[#4071] Send IAX text message using InstantMessaging Module

parent 564aeb4d
......@@ -711,9 +711,9 @@ IAXVoIPLink::sendTextMessage (sfl::InstantMessaging *module, const std::string&
// Must active the mutex for this session
_mutexIAX.enterMutex();
// module->send_iax_message(call->getSession(), message.c_str());
module->send_iax_message (call->getSession(), callID, message.c_str());
iax_send_text (call->getSession(), message.c_str());
// iax_send_text (call->getSession(), message.c_str());
_mutexIAX.leaveMutex();
return true;
......@@ -908,7 +908,7 @@ IAXVoIPLink::iaxHandleCallEvent (iax_event* event, IAXCall* call)
break;
case IAX_EVENT_TEXT:
Manager::instance ().incomingMessage (call->getCallId (), std::string ("ME"), std::string ( (const char*) event->data));
Manager::instance ().incomingMessage (call->getCallId (), call->getPeerNumber(), std::string ( (const char*) event->data));
break;
case IAX_EVENT_RINGA:
......
......@@ -127,7 +127,7 @@ pj_status_t InstantMessaging::notify (CallID& id)
return PJ_SUCCESS;
}
pj_status_t InstantMessaging::send (pjsip_inv_session *session, CallID& id, const std::string& text)
pj_status_t InstantMessaging::sip_send (pjsip_inv_session *session, CallID& id, const std::string& text)
{
pjsip_method msg_method;
......@@ -195,7 +195,7 @@ pj_status_t InstantMessaging::send_sip_message (pjsip_inv_session *session, Call
/* Check the length of the message */
if (message.length() < getMessageMaximumSize()) {
/* No problem here */
send (session, id, message);
sip_send (session, id, message);
}
else {
......@@ -207,13 +207,48 @@ pj_status_t InstantMessaging::send_sip_message (pjsip_inv_session *session, Call
// Maximum is above 1500 character
// TODO: Send every messages
send (session, id, multiple_messages[i]);
sip_send (session, id, multiple_messages[i]);
}
return PJ_SUCCESS;
}
bool InstantMessaging::iax_send (iax_session* session, const CallID& id, const std::string& message)
{
if (iax_send_text (session, message.c_str()) != -1)
return true;
else
return false;
}
bool InstantMessaging::send_iax_message (iax_session* session, const CallID& id, const std::string& message)
{
bool ret;
/* Check the length of the message */
if (message.length() < getMessageMaximumSize()) {
/* No problem here */
ret = iax_send (session, id, message);
}
else {
/* It exceeds the size limit of a SIP MESSAGE (1300 bytes), o plit it and send multiple messages */
std::vector<std::string> multiple_messages = split_message (message);
/* Send multiple messages */
// int size = multiple_messages.size();
int i = 0;
// Maximum is above 1500 character
// TODO: Send every messages
ret = iax_send (session, id, multiple_messages[i]);
}
}
std::vector<std::string> InstantMessaging::split_message (const std::string& text)
{
......
......@@ -16,6 +16,8 @@
#include <list>
#include <exception>
#include <iax-client.h>
#define EMPTY_MESSAGE pj_str((char*)"")
#define STR_TEXT pj_str((char*)"text")
#define STR_PLAIN pj_str((char*)"plain")
......@@ -129,10 +131,14 @@ class InstantMessaging
* @return pj_status_t 0 on success
* 1 otherwise
*/
pj_status_t send (pjsip_inv_session*, CallID& id, const std::string&);
pj_status_t sip_send (pjsip_inv_session*, CallID& id, const std::string&);
pj_status_t send_sip_message (pjsip_inv_session*, CallID& id, const std::string&);
bool iax_send (iax_session* session, const CallID& id, const std::string& message);
bool send_iax_message (iax_session *session, const CallID& id, const std::string&);
std::vector<std::string> split_message (const std::string&);
......
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