gloox  1.0.28
annotations.cpp
1 /*
2  Copyright (c) 2005-2023 by Jakob Schröter <js@camaya.net>
3  This file is part of the gloox library. http://camaya.net/gloox
4 
5  This software is distributed under a license. The full license
6  agreement can be found in the file LICENSE in this distribution.
7  This software may not be copied, modified, sold or distributed
8  other than expressed in the named license agreement.
9 
10  This software is distributed without any warranty.
11 */
12 
13 
14 
15 #include "annotations.h"
16 #include "clientbase.h"
17 
18 
19 namespace gloox
20 {
21 
23  : PrivateXML( parent ),
24  m_annotationsHandler( 0 )
25  {
26  }
27 
29  {
30  }
31 
33  {
34  Tag* s = new Tag( "storage", XMLNS, XMLNS_ANNOTATIONS );
35 
36  AnnotationsList::const_iterator it = aList.begin();
37  for( ; it != aList.end(); ++it )
38  {
39  Tag* n = new Tag( s, "note", (*it).note );
40  n->addAttribute( "jid", (*it).jid );
41  n->addAttribute( "cdate", (*it).cdate );
42  n->addAttribute( "mdate", (*it).mdate );
43  }
44 
45  storeXML( s, this );
46  }
47 
49  {
50  requestXML( "storage", XMLNS_ANNOTATIONS, this );
51  }
52 
54  {
55  if( !xml )
56  return;
57 
58  AnnotationsList aList;
59  const TagList& l = xml->children();
60  TagList::const_iterator it = l.begin();
61  for( ; it != l.end(); ++it )
62  {
63  if( (*it)->name() == "note" )
64  {
65  const std::string& jid = (*it)->findAttribute( "jid" );
66  const std::string& note = (*it)->cdata();
67 
68  if( !jid.empty() && !note.empty() )
69  {
70  const std::string& cdate = (*it)->findAttribute( "cdate" );
71  const std::string& mdate = (*it)->findAttribute( "mdate" );
73  item.jid = jid;
74  item.cdate = cdate;
75  item.mdate = mdate;
76  item.note = note;
77  aList.push_back( item );
78  }
79  }
80  }
81 
82  if( m_annotationsHandler )
83  m_annotationsHandler->handleAnnotations( aList );
84  }
85 
86  void Annotations::handlePrivateXMLResult( const std::string& /*uid*/, PrivateXMLResult /*result*/ )
87  {
88  }
89 
90 }
virtual void handleAnnotations(const AnnotationsList &aList)=0
virtual void handlePrivateXML(const Tag *xml)
Definition: annotations.cpp:53
virtual ~Annotations()
Definition: annotations.cpp:28
Annotations(ClientBase *parent)
Definition: annotations.cpp:22
void storeAnnotations(const AnnotationsList &aList)
Definition: annotations.cpp:32
virtual void handlePrivateXMLResult(const std::string &uid, PrivateXMLResult pxResult)
Definition: annotations.cpp:86
This is the common base class for a Jabber/XMPP Client and a Jabber Component.
Definition: clientbase.h:79
This class implements XEP-0049 (Private XML Storage).
Definition: privatexml.h:38
std::string requestXML(const std::string &tag, const std::string &xmlns, PrivateXMLHandler *pxh)
Definition: privatexml.cpp:74
std::string storeXML(const Tag *tag, PrivateXMLHandler *pxh)
Definition: privatexml.cpp:88
This is an abstraction of an XML element.
Definition: tag.h:47
bool addAttribute(Attribute *attr)
Definition: tag.cpp:354
const TagList & children() const
Definition: tag.cpp:510
The namespace for the gloox library.
Definition: adhoc.cpp:28
std::list< Tag * > TagList
Definition: tag.h:26
const std::string XMLNS_ANNOTATIONS
Definition: gloox.cpp:60
std::list< AnnotationsListItem > AnnotationsList
const std::string XMLNS
Definition: gloox.cpp:122