carbons.cpp
/*
* Copyright (c) 2013-2023 by Jakob Schröter <js@camaya.net>
* This file is part of the gloox library. http://camaya.net/gloox
*
* This software is distributed under a license. The full license
* agreement can be found in the file LICENSE in this distribution.
* This software may not be copied, modified, sold or distributed
* other than expressed in the named license agreement.
*
* This software is distributed without any warranty.
*/
#include "carbons.h"
#include "forward.h"
#include "util.h"
namespace gloox
{
/* chat state type values */
static const char* typeValues [] = {
"received",
"sent",
"enable",
"disable",
"private"
};
Carbons::Carbons( Carbons::Type type )
: StanzaExtension( ExtCarbons ), m_forward( 0 ), m_type( type )
{
}
Carbons::Carbons( const Tag* tag )
: StanzaExtension( ExtCarbons ), m_forward( 0 ), m_type( Invalid )
{
if( !tag )
return;
const std::string& name = tag->name();
m_type = static_cast<Type>( util::lookup( name, typeValues ) );
switch( m_type )
{
case Sent:
case Received:
{
Tag* f = tag->findChild( "forwarded", XMLNS, XMLNS_STANZA_FORWARDING );
if( f )
m_forward = new Forward( f );
break;
}
default:
break;
}
}
Carbons::~Carbons()
{
delete m_forward;
}
const std::string& Carbons::filterString() const
{
static const std::string filter = "/message/*[@xmlns='" + XMLNS_MESSAGE_CARBONS + "']";
return filter;
}
Stanza* Carbons::embeddedStanza() const
{
if( !m_forward || m_type == Invalid )
return 0;
return m_forward->embeddedStanza();
}
Tag* Carbons::embeddedTag() const
{
if( !m_forward || m_type == Invalid )
return 0;
return m_forward->embeddedTag();
}
Tag* Carbons::tag() const
{
if( m_type == Invalid )
return 0;
Tag* t = new Tag( util::lookup( m_type, typeValues ), XMLNS, XMLNS_MESSAGE_CARBONS );
if( m_forward && ( m_type == Received || m_type == Sent ) )
t->addChild( m_forward->tag() );
return t;
}
StanzaExtension* Carbons::clone() const
{
return 0; // TODO
}
}
gloox::Carbons::embeddedStanza
virtual Stanza * embeddedStanza() const
Definition carbons.cpp:70
gloox::Carbons::Type
Type
Definition carbons.h:123
gloox::Carbons::Sent
@ Sent
Definition carbons.h:125
gloox::Carbons::Received
@ Received
Definition carbons.h:124
gloox::Carbons::Invalid
@ Invalid
Definition carbons.h:129
gloox::Carbons::Carbons
Carbons(Type type)
Definition carbons.cpp:30
gloox::Carbons::clone
virtual StanzaExtension * clone() const
Definition carbons.cpp:98
gloox::Carbons::embeddedTag
virtual Tag * embeddedTag() const
Definition carbons.cpp:78
gloox::Carbons::~Carbons
virtual ~Carbons()
Definition carbons.cpp:59
gloox::Carbons::filterString
virtual const std::string & filterString() const
Definition carbons.cpp:64
gloox::Carbons::type
Type type() const
Definition carbons.h:154
gloox::Carbons::tag
virtual Tag * tag() const
Definition carbons.cpp:86
gloox::Forward
This is an implementation of Stanza Forwarding (XEP-0297) as a StanzaExtension.
Definition forward.h:41
gloox::StanzaExtension::StanzaExtension
StanzaExtension(int type)
Definition stanzaextension.h:211
gloox::Stanza
This is the base class for XMPP stanza abstractions.
Definition stanza.h:34
gloox::Stanza::embeddedStanza
Stanza * embeddedStanza() const
Definition stanza.cpp:69
gloox::Tag
This is an abstraction of an XML element.
Definition tag.h:47
gloox::Tag::addChild
void addChild(Tag *child)
Definition tag.cpp:424
gloox
The namespace for the gloox library.
Definition adhoc.cpp:28
gloox::XMLNS_MESSAGE_CARBONS
const std::string XMLNS_MESSAGE_CARBONS
Definition gloox.cpp:111
gloox::XMLNS_STANZA_FORWARDING
const std::string XMLNS_STANZA_FORWARDING
Definition gloox.cpp:110
gloox::XMLNS
const std::string XMLNS
Definition gloox.cpp:122
gloox::ExtCarbons
@ ExtCarbons
Definition stanzaextension.h:91