delayeddelivery.cpp
/*
Copyright (c) 2006-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 "delayeddelivery.h"
#include "tag.h"
namespace gloox
{
DelayedDelivery::DelayedDelivery( const JID& from, const std::string stamp, const std::string& reason )
: StanzaExtension( ExtDelay ), m_from( from ), m_stamp( stamp ), m_reason( reason )
{
if( !m_stamp.empty() )
m_valid = true;
}
DelayedDelivery::DelayedDelivery( const Tag* tag )
: StanzaExtension( ExtDelay )
{
if( !tag || !tag->hasAttribute( "stamp" ) )
return;
if( !( tag->name() == "x" && tag->hasAttribute( XMLNS, XMLNS_X_DELAY ) ) )
if( !( tag->name() == "delay" && tag->hasAttribute( XMLNS, XMLNS_DELAY ) ) )
return;
m_reason = tag->cdata();
m_stamp = tag->findAttribute( "stamp" );
m_from = tag->findAttribute( "from" );
m_valid = true;
}
DelayedDelivery::~DelayedDelivery()
{
}
const std::string& DelayedDelivery::filterString() const
{
static const std::string filter =
"/presence/delay[@xmlns='" + XMLNS_DELAY + "']"
"|/message/delay[@xmlns='" + XMLNS_DELAY + "']"
"|/presence/x[@xmlns='" + XMLNS_X_DELAY + "']"
"|/message/x[@xmlns='" + XMLNS_X_DELAY + "']";
return filter;
}
Tag* DelayedDelivery::tag() const
{
if( !m_valid )
return 0;
Tag* t = new Tag( "delay" );
t->addAttribute( XMLNS, XMLNS_DELAY );
if( m_from )
t->addAttribute( "from", m_from.full() );
if( !m_stamp.empty() )
t->addAttribute( "stamp", m_stamp );
if( !m_reason.empty() )
t->setCData( m_reason );
return t;
}
}
gloox::DelayedDelivery::~DelayedDelivery
virtual ~DelayedDelivery()
Definition delayeddelivery.cpp:45
gloox::DelayedDelivery::DelayedDelivery
DelayedDelivery(const JID &from, const std::string stamp, const std::string &reason="")
Definition delayeddelivery.cpp:21
gloox::DelayedDelivery::stamp
const std::string & stamp() const
Definition delayeddelivery.h:68
gloox::DelayedDelivery::filterString
virtual const std::string & filterString() const
Definition delayeddelivery.cpp:49
gloox::DelayedDelivery::from
const JID & from() const
Definition delayeddelivery.h:83
gloox::DelayedDelivery::reason
const std::string & reason() const
Definition delayeddelivery.h:95
gloox::DelayedDelivery::tag
virtual Tag * tag() const
Definition delayeddelivery.cpp:59
gloox::JID
An abstraction of a JID.
Definition jid.h:31
gloox::StanzaExtension::StanzaExtension
StanzaExtension(int type)
Definition stanzaextension.h:211
gloox::Tag
This is an abstraction of an XML element.
Definition tag.h:47
gloox::Tag::setCData
bool setCData(const std::string &cdata)
Definition tag.cpp:447
gloox::Tag::addAttribute
bool addAttribute(Attribute *attr)
Definition tag.cpp:354
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_X_DELAY
const std::string XMLNS_X_DELAY
Definition gloox.cpp:53
gloox::XMLNS
const std::string XMLNS
Definition gloox.cpp:122
gloox::ExtDelay
@ ExtDelay
Definition stanzaextension.h:43