receipt.cpp
/*
Copyright (c) 2007-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 "receipt.h"
#include "tag.h"
#include "util.h"
namespace gloox
{
/* chat state type values */
static const char* receiptValues [] = {
"request",
"received"
};
static inline Receipt::ReceiptType receiptType( const std::string& type )
{
return static_cast<Receipt::ReceiptType>( util::lookup( type, receiptValues ) );
}
Receipt::Receipt( const Tag* tag )
: StanzaExtension( ExtReceipt ), m_rcpt( Invalid )
{
if( !tag )
return;
m_rcpt = receiptType( tag->name() );
m_id = tag->findAttribute( "id" );
}
const std::string& Receipt::filterString() const
{
static const std::string filter =
"/message/request[@xmlns='" + XMLNS_RECEIPTS + "']"
"|/message/received[@xmlns='" + XMLNS_RECEIPTS + "']";
return filter;
}
Tag* Receipt::tag() const
{
if( m_rcpt == Invalid )
return 0;
Tag* tag = new Tag( util::lookup( m_rcpt, receiptValues ), XMLNS, XMLNS_RECEIPTS );
if ( !m_id.empty() )
tag->addAttribute( "id", m_id );
return tag;
}
}
gloox::Receipt::ReceiptType
ReceiptType
Definition receipt.h:39
gloox::Receipt::Invalid
@ Invalid
Definition receipt.h:42
gloox::Receipt::filterString
virtual const std::string & filterString() const
Definition receipt.cpp:41
gloox::Receipt::Receipt
Receipt(const Tag *tag)
Definition receipt.cpp:31
gloox::Receipt::tag
Tag * tag() const
Definition receipt.cpp:49
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
The namespace for the gloox library.
Definition adhoc.cpp:28
gloox::XMLNS_RECEIPTS
const std::string XMLNS_RECEIPTS
Definition gloox.cpp:98
gloox::XMLNS
const std::string XMLNS
Definition gloox.cpp:122
gloox::ExtReceipt
@ ExtReceipt
Definition stanzaextension.h:41