vcardmanager.cpp
/*
Copyright (c) 2006-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 "vcardmanager.h"
#include "vcardhandler.h"
#include "vcard.h"
#include "clientbase.h"
#include "disco.h"
#include "error.h"
namespace gloox
{
VCardManager::VCardManager( ClientBase* parent )
: m_parent( parent )
{
if( m_parent )
{
m_parent->registerIqHandler( this, ExtVCard );
m_parent->disco()->addFeature( XMLNS_VCARD_TEMP );
m_parent->registerStanzaExtension( new VCard() );
}
}
VCardManager::~VCardManager()
{
if( m_parent )
{
m_parent->disco()->removeFeature( XMLNS_VCARD_TEMP );
m_parent->removeIqHandler( this, ExtVCard );
m_parent->removeIDHandler( this );
}
}
void VCardManager::fetchVCard( const JID& jid, VCardHandler* vch )
{
if( !m_parent || !vch )
return;
TrackMap::const_iterator it = m_trackMap.find( jid.bare() );
if( it != m_trackMap.end() )
return;
const std::string& id = m_parent->getID();
IQ iq ( IQ::Get, jid, id );
iq.addExtension( new VCard() );
m_trackMap[id] = vch;
m_parent->send( iq, this,VCardHandler::FetchVCard );
}
void VCardManager::cancelVCardOperations( VCardHandler* vch )
{
TrackMap::iterator t;
TrackMap::iterator it = m_trackMap.begin();
while( it != m_trackMap.end() )
{
t = it;
++it;
if( (*t).second == vch )
m_trackMap.erase( t );
}
}
void VCardManager::storeVCard( VCard* vcard, VCardHandler* vch )
{
if( !m_parent || !vch )
return;
const std::string& id = m_parent->getID();
IQ iq( IQ::Set, JID(), id );
iq.addExtension( vcard );
m_trackMap[id] = vch;
m_parent->send( iq, this, VCardHandler::StoreVCard );
}
void VCardManager::handleIqID( const IQ& iq, int context )
{
TrackMap::iterator it = m_trackMap.find( iq.id() );
if( it != m_trackMap.end() )
{
switch( iq.subtype() )
{
case IQ::Result:
{
switch( context )
{
case VCardHandler::FetchVCard:
{
const VCard* v = iq.findExtension<VCard>( ExtVCard );
(*it).second->handleVCard( iq.from(), v );
break;
}
case VCardHandler::StoreVCard:
(*it).second->handleVCardResult( VCardHandler::StoreVCard, iq.from() );
break;
}
}
break;
case IQ::Error:
{
(*it).second->handleVCardResult( static_cast<VCardHandler::VCardContext>( context ),
iq.from(),
iq.error() ? iq.error()->error()
: StanzaErrorUndefined );
break;
}
default:
break;
}
m_trackMap.erase( it );
}
}
}
gloox::ClientBase
This is the common base class for a Jabber/XMPP Client and a Jabber Component.
Definition clientbase.h:79
gloox::Error::error
StanzaError error() const
Definition error.h:75
gloox::IQ
An abstraction of an IQ stanza.
Definition iq.h:34
gloox::IQ::subtype
IqType subtype() const
Definition iq.h:74
gloox::IQ::Set
@ Set
Definition iq.h:46
gloox::IQ::Error
@ Error
Definition iq.h:49
gloox::IQ::Result
@ Result
Definition iq.h:48
gloox::IQ::Get
@ Get
Definition iq.h:45
gloox::JID
An abstraction of a JID.
Definition jid.h:31
gloox::JID::bare
const std::string & bare() const
Definition jid.h:67
gloox::Stanza::addExtension
void addExtension(const StanzaExtension *se)
Definition stanza.cpp:52
gloox::Stanza::id
const std::string & id() const
Definition stanza.h:63
gloox::Stanza::error
const Error * error() const
Definition stanza.cpp:47
gloox::Stanza::from
const JID & from() const
Definition stanza.h:51
gloox::Stanza::findExtension
const StanzaExtension * findExtension(int type) const
Definition stanza.cpp:57
gloox::VCardHandler
A virtual interface that helps requesting Jabber VCards.
Definition vcardhandler.h:37
gloox::VCardHandler::VCardContext
VCardContext
Definition vcardhandler.h:43
gloox::VCardHandler::StoreVCard
@ StoreVCard
Definition vcardhandler.h:45
gloox::VCardHandler::FetchVCard
@ FetchVCard
Definition vcardhandler.h:44
gloox::VCardManager::handleIqID
virtual void handleIqID(const IQ &iq, int context)
Definition vcardmanager.cpp:88
gloox::VCardManager::~VCardManager
virtual ~VCardManager()
Definition vcardmanager.cpp:35
gloox::VCardManager::fetchVCard
void fetchVCard(const JID &jid, VCardHandler *vch)
Definition vcardmanager.cpp:45
gloox::VCardManager::storeVCard
void storeVCard(VCard *vcard, VCardHandler *vch)
Definition vcardmanager.cpp:75
gloox::VCardManager::cancelVCardOperations
void cancelVCardOperations(VCardHandler *vch)
Definition vcardmanager.cpp:62
gloox::VCardManager::VCardManager
VCardManager(ClientBase *parent)
Definition vcardmanager.cpp:24
gloox::VCard
A VCard abstraction.
Definition vcard.h:35
gloox
The namespace for the gloox library.
Definition adhoc.cpp:28
gloox::XMLNS_VCARD_TEMP
const std::string XMLNS_VCARD_TEMP
Definition gloox.cpp:56
gloox::StanzaErrorUndefined
@ StanzaErrorUndefined
Definition gloox.h:952
gloox::ExtVCard
@ ExtVCard
Definition stanzaextension.h:78