2
Copyright (c) 2007-2009 by Jakob Schroeter <js@camaya.net>
3
This file is part of the gloox library. http://camaya.net/gloox
5
This software is distributed under a license. The full license
6
agreement can be found in the file LICENSE in this distribution.
7
This software may not be copied, modified, sold or distributed
8
other than expressed in the named license agreement.
10
This software is distributed without any warranty.
19
static const char* msgTypeStringValues[] =
21
"chat", "error", "groupchat", "headline", "normal"
24
static inline const std::string typeString( Message::MessageType type )
26
return util::lookup2( type, msgTypeStringValues );
29
Message::Message( Tag* tag )
30
: Stanza( tag ), m_subtype( Invalid ), m_bodies( 0 ), m_subjects( 0 )
32
if( !tag || tag->name() != "message" )
35
const std::string& typestring = tag->findAttribute( TYPE );
36
if( typestring.empty() )
39
m_subtype = (MessageType)util::lookup2( typestring, msgTypeStringValues );
41
const TagList& c = tag->children();
42
TagList::const_iterator it = c.begin();
43
for( ; it != c.end(); ++it )
45
if( (*it)->name() == "body" )
46
setLang( &m_bodies, m_body, (*it) );
47
else if( (*it)->name() == "subject" )
48
setLang( &m_subjects, m_subject, (*it) );
49
else if( (*it)->name() == "thread" )
50
m_thread = (*it)->cdata();
54
Message::Message( MessageType type, const JID& to,
55
const std::string& body, const std::string& subject,
56
const std::string& thread, const std::string& xmllang )
57
: Stanza( to ), m_subtype( type ), m_bodies( 0 ), m_subjects( 0 ), m_thread( thread )
59
setLang( &m_bodies, m_body, body, xmllang );
60
setLang( &m_subjects, m_subject, subject, xmllang );
69
Tag* Message::tag() const
71
if( m_subtype == Invalid )
74
Tag* t = new Tag( "message" );
76
t->addAttribute( "to", m_to.full() );
78
t->addAttribute( "from", m_from.full() );
80
t->addAttribute( "id", m_id );
81
t->addAttribute( TYPE, typeString( m_subtype ) );
83
getLangs( m_bodies, m_body, "body", t );
84
getLangs( m_subjects, m_subject, "subject", t );
86
if( !m_thread.empty() )
87
new Tag( t, "thread", m_thread );
89
StanzaExtensionList::const_iterator it = m_extensionList.begin();
90
for( ; it != m_extensionList.end(); ++it )
91
t->addChild( (*it)->tag() );