14 #include "simanager.h"
16 #include "siprofilehandler.h"
17 #include "sihandler.h"
18 #include "clientbase.h"
26 SIManager::SI::SI(
const Tag* tag )
27 : StanzaExtension(
ExtSI ), m_tag1( 0 ), m_tag2( 0 )
29 if( !tag || tag->name() !=
"si" || tag->xmlns() !=
XMLNS_SI )
34 m_id = tag->findAttribute(
"id" );
35 m_mimetype = tag->findAttribute(
"mime-type" );
36 m_profile = tag->findAttribute(
"profile" );
38 Tag* c = tag->findChild(
"file",
"xmlns",
XMLNS_SI_FT );
46 SIManager::SI::SI( Tag* tag1, Tag* tag2,
const std::string&
id,
47 const std::string& mimetype,
const std::string& profile )
48 : StanzaExtension(
ExtSI ), m_tag1( tag1 ), m_tag2( tag2 ),
49 m_id( id ), m_mimetype( mimetype ), m_profile( profile )
60 const std::string& SIManager::SI::filterString()
const
62 static const std::string filter =
"/iq/si[@xmlns='" +
XMLNS_SI +
"']";
66 Tag* SIManager::SI::tag()
const
71 Tag* t =
new Tag(
"si" );
74 t->addAttribute(
"id", m_id );
75 if( !m_mimetype.empty() )
76 t->addAttribute(
"mime-type", m_mimetype.empty() ?
"binary/octet-stream" : m_mimetype );
77 if( !m_profile.empty() )
78 t->addAttribute(
"profile", m_profile );
80 t->addChildCopy( m_tag1 );
82 t->addChildCopy( m_tag2 );
90 : m_parent( parent ), m_advertise( advertise )
96 if( m_parent->
disco() && m_advertise )
107 if( m_parent->
disco() && m_advertise )
113 Tag* child1,
Tag* child2,
const std::string& mimetype,
114 const JID& from,
const std::string& sid )
116 if( !m_parent || !sih )
119 const std::string&
id = m_parent->
getID();
120 const std::string& sidToUse = sid.empty() ? m_parent->
getID() : sid;
123 iq.
addExtension(
new SI( child1, child2, sidToUse, mimetype, profile ) );
132 m_parent->
send( iq,
this, OfferSI );
144 m_parent->
send( iq );
168 m_parent->
send( iq );
173 if( !sih || profile.empty() )
176 m_handlers[profile] = sih;
178 if( m_parent && m_advertise && m_parent->
disco() )
184 if( profile.empty() )
187 m_handlers.erase( profile );
189 if( m_parent && m_advertise && m_parent->
disco() )
195 TrackMap::iterator itt = m_track.find( iq.
id() );
196 if( itt != m_track.end() )
200 if( !si || si->profile().empty() )
203 HandlerMap::const_iterator it = m_handlers.find( si->profile() );
204 if( it != m_handlers.end() && (*it).second )
206 (*it).second->handleSIRequest( iq.
from(), iq.
to(), iq.
id(), *si );
218 if( context == OfferSI )
220 TrackMap::iterator it = m_track.find( iq.
id() );
221 if( it != m_track.end() )
238 (*it).second.sih->handleSIRequestResult( iq.
from(), iq.
to(), (*it).second.sid, *si );
244 if( context == OfferSI )
246 TrackMap::iterator it = m_track.find( iq.
id() );
247 if( it != m_track.end() )
249 (*it).second.sih->handleSIRequestError( iq, (*it).second.sid );
void addFeature(const std::string &feature)
void removeProfile(const std::string &profile)
void removeIDHandler(IqHandler *ih)
An abstract base class to handle results of outgoing SI requests, i.e. you requested a stream (using ...
const std::string XMLNS_SI_FT
An abstraction of an IQ stanza.
void removeIqHandler(IqHandler *ih, int exttype)
void registerIqHandler(IqHandler *ih, int exttype)
void addExtension(const StanzaExtension *se)
void declineSI(const JID &to, const std::string &id, SIError reason, const std::string &text=EmptyString)
void registerStanzaExtension(StanzaExtension *ext)
virtual void handleIqID(const IQ &iq, int context)
A stanza error abstraction implemented as a StanzaExtension.
void setFrom(const JID &from)
void registerProfile(const std::string &profile, SIProfileHandler *sih)
const std::string requestSI(SIHandler *sih, const JID &to, const std::string &profile, Tag *child1, Tag *child2=0, const std::string &mimetype="binary/octet-stream", const JID &from=JID(), const std::string &sid=EmptyString)
The namespace for the gloox library.
void acceptSI(const JID &to, const std::string &id, Tag *child1, Tag *child2=0, const JID &from=JID())
virtual Disco * disco() const
const std::string XMLNS_SI
virtual bool handleIq(const IQ &iq)
const std::string & text(const std::string &lang=EmptyString) const
SIManager(ClientBase *parent, bool advertise=true)
const std::string getID()
const std::string XMLNS_FEATURE_NEG
void removeFeature(const std::string &feature)
const std::string & id() const
const std::string EmptyString
This is the common base class for a Jabber/XMPP Client and a Jabber Component.
const StanzaExtension * findExtension(int type) const
This is an abstraction of an XML element.
An abstract base class to handle SI requests for a specific profile, e.g. file transfer.