gloox 1.0.24
bookmarkstorage.cpp
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 "bookmarkstorage.h"
16#include "clientbase.h"
17
18
19namespace gloox
20{
21
23 : PrivateXML( parent ),
24 m_bookmarkHandler( 0 )
25 {
26 }
27
29 {
30 }
31
33 {
34 Tag* s = new Tag( "storage" );
36
37 BookmarkList::const_iterator itb = bList.begin();
38 for( ; itb != bList.end(); ++itb )
39 {
40 Tag* i = new Tag( s, "url", "name", (*itb).name );
41 i->addAttribute( "url", (*itb).url );
42 }
43
44 ConferenceList::const_iterator itc = cList.begin();
45 for( ; itc != cList.end(); ++itc )
46 {
47 Tag* i = new Tag( s, "conference", "name", (*itc).name );
48 i->addAttribute( "jid", (*itc).jid );
49 i->addAttribute( "autojoin", (*itc).autojoin ? "true" : "false" );
50
51 new Tag( i, "nick", (*itc).nick );
52 new Tag( i, "password", (*itc).password );
53 }
54
55 storeXML( s, this );
56 }
57
59 {
60 requestXML( "storage", XMLNS_BOOKMARKS, this );
61 }
62
64 {
65 if( !xml )
66 return;
67
68 BookmarkList bList;
69 ConferenceList cList;
70 const TagList& l = xml->children();
71 TagList::const_iterator it = l.begin();
72 for( ; it != l.end(); ++it )
73 {
74 if( (*it)->name() == "url" )
75 {
76 const std::string& url = (*it)->findAttribute( "url" );
77 const std::string& name = (*it)->findAttribute( "name" );
78
79 if( !url.empty() && !name.empty() )
80 {
82 item.url = url;
83 item.name = name;
84 bList.push_back( item );
85 }
86 }
87 else if( (*it)->name() == "conference" )
88 {
89 const std::string& jid = (*it)->findAttribute( "jid" );
90 const std::string& name = (*it)->findAttribute( "name" );
91
92 if( !jid.empty() && !name.empty() )
93 {
94 const std::string& join = (*it)->findAttribute( "autojoin" );
96 item.jid = jid;
97 item.name = name;
98 const Tag* nick = (*it)->findChild( "nick" );
99 if( nick )
100 item.nick = nick->cdata();
101 const Tag* pwd = (*it)->findChild( "password" );
102 if( pwd )
103 item.password = pwd->cdata();
104 item.autojoin = ( join == "true" || join == "1" );
105 cList.push_back( item );
106 }
107 }
108 }
109
110 if( m_bookmarkHandler )
111 m_bookmarkHandler->handleBookmarks( bList, cList );
112 }
113
114 void BookmarkStorage::handlePrivateXMLResult( const std::string& /*uid*/, PrivateXMLResult /*result*/ )
115 {
116 }
117
118}
virtual void handleBookmarks(const BookmarkList &bList, const ConferenceList &cList)=0
void storeBookmarks(const BookmarkList &bList, const ConferenceList &cList)
virtual void handlePrivateXML(const Tag *xml)
BookmarkStorage(ClientBase *parent)
virtual void handlePrivateXMLResult(const std::string &uid, PrivateXMLResult pxResult)
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
Tag * findChild(const std::string &name) const
Definition: tag.cpp:624
const std::string & name() const
Definition: tag.h:394
bool addAttribute(Attribute *attr)
Definition: tag.cpp:354
const std::string cdata() const
Definition: tag.cpp:497
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:31
std::list< BookmarkListItem > BookmarkList
const std::string XMLNS_BOOKMARKS
Definition: gloox.cpp:59
const std::string XMLNS
Definition: gloox.cpp:122
std::list< ConferenceListItem > ConferenceList