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

[#3963] Full instant messaging urilist generation from UriList structure

parent cab85835
......@@ -224,11 +224,27 @@ std::vector<std::string> InstantMessaging::split_message (const std::string& tex
std::string InstantMessaging::generateXmlUriList (UriList& list)
{
std::string xmlbuffer = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
xmlbuffer.append ("<resource-lists xmlns=\"urn:ietf:params:xml:ns:resource-lists\" xmlns:cp=\"urn:ietf:params:xml:ns:copycontrol\">");
xmlbuffer.append ("<list>");
xmlbuffer.append ("<entry uri=\"sip:al@example.com\" cp:copyControl=\"to\" />");
xmlbuffer.append ("<entry uri=\"sip:manu@example.com\" cp:copyControl=\"to\" />");
// An iterator over xml attribute
UriEntry::iterator iterAttr;
// An iterator over list entries
UriList::iterator iterEntry = list.begin();
while (iterEntry != list.end()) {
xmlbuffer.append ("<entry uri=");
UriEntry entry = static_cast<UriEntry> (*iterEntry);
iterAttr = entry.find (sfl::IM_XML_URI);
xmlbuffer.append (iterAttr->second);
xmlbuffer.append (" cp:copyControl=\"to\" />");
iterEntry++;
}
xmlbuffer.append ("</list>");
xmlbuffer.append ("</resource-lists>");
......
......@@ -13,6 +13,7 @@
#include "sip/sipcall.h"
#include <map>
#include <list>
#define EMPTY_MESSAGE pj_str((char*)"")
#define STR_TEXT pj_str((char*)"text")
......@@ -27,13 +28,15 @@
namespace sfl
{
const std::string IM_XML_URI ("IM_XML_URI");
class InstantMessaging
{
public:
typedef std::map <std::string, std::string> UriEntry;
typedef std::map <std::string, UriEntry> UriList;
typedef std::map <std::string, std::string> UriEntry;
typedef std::list <UriEntry> UriList;
/*
* Class constructor
......@@ -125,21 +128,21 @@ class InstantMessaging
/**
* Generate Xml participant list for multi recipient based on RFC Draft 5365
*
* @param A UriList of UriEntry
*
* @return A string containing the full XML formated information to be included in the
* sip instant message.
*/
std::string generateXmlUriList(UriList& list);
/**
* Parse the Urilist from a SIP Instant Message provided by a UriList service.
*
* @param A XML formated string as obtained from a SIP instant message.
*
* @return An UriList of UriEntry containing parsed XML information as a map.
*/
UriList parseXmlUriList(std::string& urilist);
* @param A UriList of UriEntry
*
* @return A string containing the full XML formated information to be included in the
* sip instant message.
*/
std::string generateXmlUriList (UriList& list);
/**
* Parse the Urilist from a SIP Instant Message provided by a UriList service.
*
* @param A XML formated string as obtained from a SIP instant message.
*
* @return An UriList of UriEntry containing parsed XML information as a map.
*/
UriList parseXmlUriList (std::string& urilist);
private:
......
......@@ -143,7 +143,7 @@ void InstantMessagingTest::testSplitMessage ()
CPPUNIT_ASSERT (messages[size- 1] == very_long_message.substr (maxSize * (size-1)));
}
static inline char* dupstr(char dst[], const char src[], size_t len)
static inline char* duplicateString(char dst[], const char src[], size_t len)
{
memcpy(dst, src, len);
dst[len] = 0;
......@@ -166,11 +166,19 @@ static void XMLCALL startElementCallback(void *userData, const char *name, const
const char **val = att+1;
dupstr(attribute, *att, strlen(*att));
duplicateString(attribute, *att, strlen(*att));
std::cout << "att: " << attribute << std::endl;
dupstr(value, *val, strlen(*val));
duplicateString(value, *val, strlen(*val));
std::cout << "val: " << value << std::endl;
if (strcmp(attribute, "uri") == 0) {
if((strcmp(value, "sip:alex@example.com") == 0) ||
(strcmp(value, "sip:manu@example.com") == 0))
CPPUNIT_ASSERT(1==1);
else
CPPUNIT_ASSERT(0==1);
}
}
*nbEntry += 1;
......@@ -189,9 +197,20 @@ void InstantMessagingTest::testGenerateXmlUriList ()
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 buffer = _im->generateXmlUriList(list);
CPPUNIT_ASSERT(buffer.size() != 0);
std::cout << buffer << std::endl;
XML_Parser parser = XML_ParserCreate(NULL);
int nbEntry = 0;
XML_SetUserData(parser, &nbEntry);
......
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