diff --git a/sflphone-common/src/iax/iaxvoiplink.cpp b/sflphone-common/src/iax/iaxvoiplink.cpp index 265cec93b82a5ad0a83703ba8c3f02dc76c26328..eee6c4c6586d980306de60d3256d3fe35b6013bc 100644 --- a/sflphone-common/src/iax/iaxvoiplink.cpp +++ b/sflphone-common/src/iax/iaxvoiplink.cpp @@ -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: diff --git a/sflphone-common/src/im/InstantMessaging.cpp b/sflphone-common/src/im/InstantMessaging.cpp index 1b22d01e3a5acf67bb1e1a8ab32db3e04e1f00c5..2896dfc69e71194e7d6e4876b160e68ec7f308f8 100644 --- a/sflphone-common/src/im/InstantMessaging.cpp +++ b/sflphone-common/src/im/InstantMessaging.cpp @@ -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) { diff --git a/sflphone-common/src/im/InstantMessaging.h b/sflphone-common/src/im/InstantMessaging.h index b87fa402cbbc611ea28afb4e066d3f5461da87e9..2a87e3ea3e0f4e643b16d91ccbd643ba03ceb4c6 100644 --- a/sflphone-common/src/im/InstantMessaging.h +++ b/sflphone-common/src/im/InstantMessaging.h @@ -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&);