annotations.cpp
/*
Copyright (c) 2005-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 "annotations.h"
#include "clientbase.h"
namespace gloox
{
Annotations::Annotations( ClientBase* parent )
: PrivateXML( parent ),
m_annotationsHandler( 0 )
{
}
Annotations::~Annotations()
{
}
void Annotations::storeAnnotations( const AnnotationsList& aList )
{
Tag* s = new Tag( "storage", XMLNS, XMLNS_ANNOTATIONS );
AnnotationsList::const_iterator it = aList.begin();
for( ; it != aList.end(); ++it )
{
Tag* n = new Tag( s, "note", (*it).note );
n->addAttribute( "jid", (*it).jid );
n->addAttribute( "cdate", (*it).cdate );
n->addAttribute( "mdate", (*it).mdate );
}
storeXML( s, this );
}
void Annotations::requestAnnotations()
{
requestXML( "storage", XMLNS_ANNOTATIONS, this );
}
void Annotations::handlePrivateXML( const Tag* xml )
{
if( !xml )
return;
AnnotationsList aList;
const TagList& l = xml->children();
TagList::const_iterator it = l.begin();
for( ; it != l.end(); ++it )
{
if( (*it)->name() == "note" )
{
const std::string& jid = (*it)->findAttribute( "jid" );
const std::string& note = (*it)->cdata();
if( !jid.empty() && !note.empty() )
{
const std::string& cdate = (*it)->findAttribute( "cdate" );
const std::string& mdate = (*it)->findAttribute( "mdate" );
AnnotationsListItem item;
item.jid = jid;
item.cdate = cdate;
item.mdate = mdate;
item.note = note;
aList.push_back( item );
}
}
}
if( m_annotationsHandler )
m_annotationsHandler->handleAnnotations( aList );
}
void Annotations::handlePrivateXMLResult( const std::string& /*uid*/, PrivateXMLResult /*result*/ )
{
}
}
gloox::Annotations::handlePrivateXML
virtual void handlePrivateXML(const Tag *xml)
Definition annotations.cpp:53
gloox::Annotations::~Annotations
virtual ~Annotations()
Definition annotations.cpp:28
gloox::Annotations::Annotations
Annotations(ClientBase *parent)
Definition annotations.cpp:22
gloox::Annotations::storeAnnotations
void storeAnnotations(const AnnotationsList &aList)
Definition annotations.cpp:32
gloox::Annotations::requestAnnotations
void requestAnnotations()
Definition annotations.cpp:48
gloox::Annotations::handlePrivateXMLResult
virtual void handlePrivateXMLResult(const std::string &uid, PrivateXMLResult pxResult)
Definition annotations.cpp:86
gloox::ClientBase
This is the common base class for a Jabber/XMPP Client and a Jabber Component.
Definition clientbase.h:79
gloox::PrivateXMLHandler::PrivateXMLResult
PrivateXMLResult
Definition privatexmlhandler.h:42
gloox::PrivateXML::PrivateXML
PrivateXML(ClientBase *parent)
Definition privatexml.cpp:54
gloox::PrivateXML::requestXML
std::string requestXML(const std::string &tag, const std::string &xmlns, PrivateXMLHandler *pxh)
Definition privatexml.cpp:74
gloox::PrivateXML::storeXML
std::string storeXML(const Tag *tag, PrivateXMLHandler *pxh)
Definition privatexml.cpp:88
gloox::Tag
This is an abstraction of an XML element.
Definition tag.h:47
gloox::Tag::addAttribute
bool addAttribute(Attribute *attr)
Definition tag.cpp:354
gloox::Tag::children
const TagList & children() const
Definition tag.cpp:510
gloox
The namespace for the gloox library.
Definition adhoc.cpp:28
gloox::TagList
std::list< Tag * > TagList
Definition tag.h:31
gloox::XMLNS_ANNOTATIONS
const std::string XMLNS_ANNOTATIONS
Definition gloox.cpp:60
gloox::AnnotationsList
std::list< AnnotationsListItem > AnnotationsList
Definition annotationshandler.h:40
gloox::XMLNS
const std::string XMLNS
Definition gloox.cpp:122
gloox::AnnotationsListItem
Definition annotationshandler.h:30
gloox::AnnotationsListItem::mdate
std::string mdate
Definition annotationshandler.h:33
gloox::AnnotationsListItem::jid
std::string jid
Definition annotationshandler.h:31
gloox::AnnotationsListItem::cdate
std::string cdate
Definition annotationshandler.h:32
gloox::AnnotationsListItem::note
std::string note
Definition annotationshandler.h:34