bookmarkstorage.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 "bookmarkstorage.h"
#include "clientbase.h"
namespace gloox
{
BookmarkStorage::BookmarkStorage( ClientBase* parent )
: PrivateXML( parent ),
m_bookmarkHandler( 0 )
{
}
BookmarkStorage::~BookmarkStorage()
{
}
void BookmarkStorage::storeBookmarks( const BookmarkList& bList, const ConferenceList& cList )
{
Tag* s = new Tag( "storage" );
s->addAttribute( XMLNS, XMLNS_BOOKMARKS );
BookmarkList::const_iterator itb = bList.begin();
for( ; itb != bList.end(); ++itb )
{
Tag* i = new Tag( s, "url", "name", (*itb).name );
i->addAttribute( "url", (*itb).url );
}
ConferenceList::const_iterator itc = cList.begin();
for( ; itc != cList.end(); ++itc )
{
Tag* i = new Tag( s, "conference", "name", (*itc).name );
i->addAttribute( "jid", (*itc).jid );
i->addAttribute( "autojoin", (*itc).autojoin ? "true" : "false" );
new Tag( i, "nick", (*itc).nick );
new Tag( i, "password", (*itc).password );
}
storeXML( s, this );
}
void BookmarkStorage::requestBookmarks()
{
requestXML( "storage", XMLNS_BOOKMARKS, this );
}
void BookmarkStorage::handlePrivateXML( const Tag* xml )
{
if( !xml )
return;
BookmarkList bList;
ConferenceList cList;
const TagList& l = xml->children();
TagList::const_iterator it = l.begin();
for( ; it != l.end(); ++it )
{
if( (*it)->name() == "url" )
{
const std::string& url = (*it)->findAttribute( "url" );
const std::string& name = (*it)->findAttribute( "name" );
if( !url.empty() )
{
BookmarkListItem item;
item.url = url;
item.name = name;
bList.push_back( item );
}
}
else if( (*it)->name() == "conference" )
{
const std::string& jid = (*it)->findAttribute( "jid" );
const std::string& name = (*it)->findAttribute( "name" );
if( !jid.empty() )
{
const std::string& join = (*it)->findAttribute( "autojoin" );
ConferenceListItem item;
item.jid = jid;
item.name = name;
const Tag* nick = (*it)->findChild( "nick" );
if( nick )
item.nick = nick->cdata();
const Tag* pwd = (*it)->findChild( "password" );
if( pwd )
item.password = pwd->cdata();
item.autojoin = ( join == "true" || join == "1" );
cList.push_back( item );
}
}
}
if( m_bookmarkHandler )
m_bookmarkHandler->handleBookmarks( bList, cList );
}
void BookmarkStorage::handlePrivateXMLResult( const std::string& /*uid*/, PrivateXMLResult /*result*/ )
{
}
}
gloox::BookmarkStorage::requestBookmarks
void requestBookmarks()
Definition bookmarkstorage.cpp:58
gloox::BookmarkStorage::storeBookmarks
void storeBookmarks(const BookmarkList &bList, const ConferenceList &cList)
Definition bookmarkstorage.cpp:32
gloox::BookmarkStorage::~BookmarkStorage
virtual ~BookmarkStorage()
Definition bookmarkstorage.cpp:28
gloox::BookmarkStorage::handlePrivateXML
virtual void handlePrivateXML(const Tag *xml)
Definition bookmarkstorage.cpp:63
gloox::BookmarkStorage::BookmarkStorage
BookmarkStorage(ClientBase *parent)
Definition bookmarkstorage.cpp:22
gloox::BookmarkStorage::handlePrivateXMLResult
virtual void handlePrivateXMLResult(const std::string &uid, PrivateXMLResult pxResult)
Definition bookmarkstorage.cpp:114
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::findChild
Tag * findChild(const std::string &name) const
Definition tag.cpp:624
gloox::Tag::name
const std::string & name() const
Definition tag.h:394
gloox::Tag::addAttribute
bool addAttribute(Attribute *attr)
Definition tag.cpp:354
gloox::Tag::cdata
const std::string cdata() const
Definition tag.cpp:497
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::BookmarkList
std::list< BookmarkListItem > BookmarkList
Definition bookmarkhandler.h:50
gloox::XMLNS_BOOKMARKS
const std::string XMLNS_BOOKMARKS
Definition gloox.cpp:59
gloox::XMLNS
const std::string XMLNS
Definition gloox.cpp:122
gloox::ConferenceList
std::list< ConferenceListItem > ConferenceList
Definition bookmarkhandler.h:55
gloox::BookmarkListItem
Definition bookmarkhandler.h:30
gloox::BookmarkListItem::name
std::string name
Definition bookmarkhandler.h:31
gloox::BookmarkListItem::url
std::string url
Definition bookmarkhandler.h:32
gloox::ConferenceListItem
Definition bookmarkhandler.h:39
gloox::ConferenceListItem::autojoin
bool autojoin
Definition bookmarkhandler.h:44
gloox::ConferenceListItem::password
std::string password
Definition bookmarkhandler.h:43
gloox::ConferenceListItem::jid
std::string jid
Definition bookmarkhandler.h:41
gloox::ConferenceListItem::name
std::string name
Definition bookmarkhandler.h:40
gloox::ConferenceListItem::nick
std::string nick
Definition bookmarkhandler.h:42