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 );