forward.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 "forward.h"
#include "delayeddelivery.h"
#include "message.h"
#include "stanza.h"
#include "util.h"
namespace gloox
{
Forward::Forward( Stanza *stanza, DelayedDelivery *delay )
: StanzaExtension( ExtForward ),
m_stanza( stanza ), m_tag( 0 ), m_delay( delay )
{
}
Forward::Forward( const Tag* tag )
: StanzaExtension( ExtForward ),
m_stanza( 0 ), m_tag( 0 ), m_delay( 0 )
{
if( !tag || !( tag->name() == "forwarded" && tag->hasAttribute( XMLNS, XMLNS_STANZA_FORWARDING ) ) )
return;
m_delay = new DelayedDelivery( tag->findChild( "delay", XMLNS, XMLNS_DELAY ) );
Tag* m = tag->findChild( "message" );
if( !m )
return;
m_tag = m->clone();
m_stanza = new Message( m );
}
Forward::~Forward()
{
delete m_delay;
delete m_stanza;
delete m_tag;
}
const std::string& Forward::filterString() const
{
static const std::string filter = "/message/forwarded[@xmlns='" + XMLNS_STANZA_FORWARDING + "']"
"|/iq/forwarded[@xmlns='" + XMLNS_STANZA_FORWARDING + "']"
"|/presence/forwarded[@xmlns='" + XMLNS_STANZA_FORWARDING + "']";
return filter;
}
Tag* Forward::tag() const
{
if( !m_stanza )
return 0;
Tag* f = new Tag( "forwarded" );
f->setXmlns( XMLNS_STANZA_FORWARDING );
if( m_delay )
f->addChild( m_delay->tag() );
if( m_stanza )
{
Tag* tmp = m_stanza->tag();
if( tmp->name() == "message" )
tmp->setXmlns( XMLNS_CLIENT );
f->addChild( tmp );
}
return f;
}
StanzaExtension* Forward::clone() const
{
if( !m_tag || !m_delay )
return 0;
return new Forward( new Message( m_tag ), static_cast<DelayedDelivery*>( m_delay->clone() ) );
}
}
gloox::DelayedDelivery
This is an implementation of XEP-0203 (Delayed Delivery).
Definition delayeddelivery.h:39
gloox::Forward::~Forward
virtual ~Forward()
Definition forward.cpp:47
gloox::Forward::clone
StanzaExtension * clone() const
Definition forward.cpp:83
gloox::Forward::filterString
const std::string & filterString() const
Definition forward.cpp:54
gloox::Forward::Forward
Forward(Stanza *stanza, DelayedDelivery *delay)
Definition forward.cpp:24
gloox::Forward::tag
virtual Tag * tag() const
Definition forward.cpp:62
gloox::Message
An abstraction of a message stanza.
Definition message.h:34
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::Tag
This is an abstraction of an XML element.
Definition tag.h:47
gloox::Tag::name
const std::string & name() const
Definition tag.h:394
gloox::Tag::addChild
void addChild(Tag *child)
Definition tag.cpp:424
gloox::Tag::setXmlns
bool setXmlns(const std::string &xmlns, const std::string &prefix=EmptyString)
Definition tag.cpp:522
gloox
The namespace for the gloox library.
Definition adhoc.cpp:28
gloox::XMLNS_DELAY
const std::string XMLNS_DELAY
Definition gloox.cpp:37
gloox::XMLNS_STANZA_FORWARDING
const std::string XMLNS_STANZA_FORWARDING
Definition gloox.cpp:110
gloox::XMLNS_CLIENT
const std::string XMLNS_CLIENT
Definition gloox.cpp:19
gloox::XMLNS
const std::string XMLNS
Definition gloox.cpp:122
gloox::ExtForward
@ ExtForward
Definition stanzaextension.h:90