Commit 454b3254 authored by Alexandre Savard's avatar Alexandre Savard
Browse files

[#3963] Format outgoin instant message as specified by RFC 5365

parent f62426cd
......@@ -15,13 +15,10 @@ static inline char* duplicateString (char dst[], const char src[], size_t len)
static void XMLCALL startElementCallback (void *userData, const char *name, const char **atts)
{
int *depthPtr = (int *) userData;
char attribute[100];
char value[100];
const char **att;
const char **val;
if (strcmp (name, "entry") == 0) {
......@@ -137,8 +134,7 @@ pj_status_t InstantMessaging::send (pjsip_inv_session *session, CallID& id, cons
pj_str_t message;
msg_method.id = PJSIP_OTHER_METHOD;
msg_method.name = METHOD_NAME ;
msg_method.name = METHOD_NAME;
// Get the dialog associated to the call
dialog = session->dlg;
......@@ -155,6 +151,24 @@ pj_status_t InstantMessaging::send (pjsip_inv_session *session, CallID& id, cons
// Attach "text/plain" body
tdata->msg->body = pjsip_msg_body_create (tdata->pool, &type, &subtype, &message);
// Create the Require header to handle recipient-list Content-Disposition type
pjsip_generic_string_hdr reqhdr;
pj_str_t reqhname = pj_str ("Require");
pj_str_t reqhvalue = pj_str ("recipient-list");
// Create the Content-Type header to handle multipart/mixed and boundary MIME types
pj_str_t ctype = pj_str ("Content-Type");
pj_str_t sctype = pj_str ("ctype"); // small version of the header name
// ctypehdr = pjsip_msg_find_hdr_by_names (tdata->msg, &ctype, &sctype, NULL);
// pjsip_generic_string_hdr ctypehdr;
// pj_str_t ctypehname = pj_str ("Content-Type");
// pj_str_t ctypehvalue = pj_str ("multipart/mixed;boundary=\"boundary\"");
// Add headers to the message
pjsip_generic_string_hdr_init2 (&reqhdr, &reqhname, &reqhvalue);
pj_list_push_back (& (tdata->msg->hdr), (pjsip_hdr*) (&reqhdr));
// pj_list_push_back (& (tdata->msg->hdr), (pjsip_hdr*) (&ctypehdr));
// Send the request
status = pjsip_dlg_send_request (dialog, tdata, -1, NULL);
// PJ_ASSERT_RETURN (status == PJ_SUCCESS, 1);
......@@ -182,7 +196,7 @@ pj_status_t InstantMessaging::send_message (pjsip_inv_session *session, CallID&
/* 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 size = multiple_messages.size();
int i = 0;
// Maximum is above 1500 character
......@@ -268,4 +282,22 @@ InstantMessaging::UriList InstantMessaging::parseXmlUriList (std::string& urilis
return list;
}
std::string InstantMessaging::appendUriList (std::string text, UriList& list)
{
std::string formatedText = "--boundary\nContent-Type: text/plain\n\n";
formatedText.append (text);
formatedText.append ("\n--boundary\nContent-Type: application/resource-lists+xml\n");
formatedText.append ("Content-Disposition: recipient-list\n\n");
std::string recipientlist = generateXmlUriList (list);
formatedText.append (recipientlist);
formatedText.append ("--boundary--");
return formatedText;
}
}
......@@ -29,6 +29,7 @@ namespace sfl
{
const std::string IM_XML_URI ("IM_XML_URI");
const std::string BOUNDARY ("--boundary");
class InstantMessaging
{
......@@ -144,6 +145,16 @@ class InstantMessaging
*/
UriList parseXmlUriList (std::string& urilist);
/**
* Format text message according to RFC 5365, append recipient-list to the message
*
* @param text to be displayed
* @param list containing the recipients
*
* @return formated text stored into a string to be included in sip MESSAGE
*/
std::string appendUriList (std::string text, UriList& list);
private:
/**
......
......@@ -1072,7 +1072,20 @@ SIPVoIPLink::sendTextMessage (const std::string& callID, const std::string& mess
if (call) {
/* Send IM message */
status = imModule->send_message (call->getInvSession (), (CallID&) callID, message);
sfl::InstantMessaging::UriList list;
sfl::InstantMessaging::UriEntry entry1;
entry1[sfl::IM_XML_URI] = "\"sip:alex@example.com\"";
sfl::InstantMessaging::UriEntry entry2;
entry2[sfl::IM_XML_URI] = "\"sip:manu@example.com\"";
list.push_front (&entry1);
list.push_front (&entry2);
std::string formatedMessage = imModule->appendUriList (message, list);
status = imModule->send_message (call->getInvSession (), (CallID&) callID, formatedMessage);
} else {
/* Notify the client of an error */
/*Manager::instance ().incomingMessage ( "",
......
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