1 /*
2   Copyright (c) 2005-2019 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 
Annotations(ClientBase * parent)22   Annotations::Annotations( ClientBase* parent )
23     : PrivateXML( parent ),
24       m_annotationsHandler( 0 )
25   {
26   }
27 
~Annotations()28   Annotations::~Annotations()
29   {
30   }
31 
storeAnnotations(const AnnotationsList & aList)32   void Annotations::storeAnnotations( const AnnotationsList& aList )
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 
requestAnnotations()48   void Annotations::requestAnnotations()
49   {
50     requestXML( "storage", XMLNS_ANNOTATIONS, this );
51   }
52 
handlePrivateXML(const Tag * xml)53   void Annotations::handlePrivateXML( const Tag* xml )
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" );
72           AnnotationsListItem item;
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 
handlePrivateXMLResult(const std::string &,PrivateXMLResult)86   void Annotations::handlePrivateXMLResult( const std::string& /*uid*/, PrivateXMLResult /*result*/ )
87   {
88   }
89 
90 }
91