void ClientBase::send( IQ& iq, IqHandler* ih, int ctx ) { const PrivateXML::Query* q = iq.findExtension<PrivateXML::Query>( ExtPrivateXML ); if( !q ) return; Tag* tag = q->tag(); switch( m_test ) { case 1: { if( iq.subtype() == IQ::Set && tag && *(tag->findChild( "foo", "xmlns", "test" )) == *t1 ) { IQ re( IQ::Result, iq.from(), iq.id() ); re.addExtension( new PrivateXML::Query() ); ih->handleIqID( re, ctx ); } break; } case 2: { if( iq.subtype() == IQ::Get && tag && tag->hasChild( "foo", "xmlns", "test" ) ) { IQ re( IQ::Result, iq.from(), iq.id() ); re.addExtension( new PrivateXML::Query( t1->clone() ) ); ih->handleIqID( re, ctx ); } break; } } delete tag; }
void PrivateXML::handleIqID( const IQ& iq, int context ) { TrackMap::iterator t = m_track.find( iq.id() ); if( t == m_track.end() ) return; if( iq.subtype() == IQ::Result ) { if( context == RequestXml ) { const Query* q = iq.findExtension<Query>( ExtPrivateXML ); if( q ) (*t).second->handlePrivateXML( q->privateXML() ); } else if( context == StoreXml ) (*t).second->handlePrivateXMLResult( iq.id(), PrivateXMLHandler::PxmlStoreOk ); } else if( iq.subtype() == IQ::Error ) { if( context == RequestXml ) (*t).second->handlePrivateXMLResult( iq.id(), PrivateXMLHandler::PxmlRequestError ); else if( context == StoreXml ) (*t).second->handlePrivateXMLResult( iq.id(), PrivateXMLHandler::PxmlStoreError ); } m_track.erase( t ); }
void RosterManager::handleIqID( const IQ& iq, int context ) { if( iq.subtype() == IQ::Result ) // initial roster { const Query* q = iq.findExtension<Query>( ExtRoster ); if( q ) mergeRoster( q->roster() ); if( context == RequestRoster ) { if( m_parent ) m_parent->rosterFilled(); if( m_rosterListener ) m_rosterListener->handleRoster( m_roster ); } } else if( iq.subtype() == IQ::Error ) { if( context == RequestRoster && m_parent ) m_parent->rosterFilled(); if( m_rosterListener ) m_rosterListener->handleRosterError( iq ); } }
void FlexibleOffline::handleIqID( const IQ& iq, int context ) { if( !m_flexibleOfflineHandler ) return; switch( context ) { case FORequestMsgs: switch( iq.subtype() ) { case IQ::Result: m_flexibleOfflineHandler->handleFlexibleOfflineResult( FomrRequestSuccess ); break; case IQ::Error: switch( iq.error()->error() ) { case StanzaErrorForbidden: m_flexibleOfflineHandler->handleFlexibleOfflineResult( FomrForbidden ); break; case StanzaErrorItemNotFound: m_flexibleOfflineHandler->handleFlexibleOfflineResult( FomrItemNotFound ); break; default: m_flexibleOfflineHandler->handleFlexibleOfflineResult( FomrUnknownError ); break; } break; default: break; } break; case FORemoveMsgs: switch( iq.subtype() ) { case IQ::Result: m_flexibleOfflineHandler->handleFlexibleOfflineResult( FomrRemoveSuccess ); break; case IQ::Error: switch( iq.error()->error() ) { case StanzaErrorForbidden: m_flexibleOfflineHandler->handleFlexibleOfflineResult( FomrForbidden ); break; case StanzaErrorItemNotFound: m_flexibleOfflineHandler->handleFlexibleOfflineResult( FomrItemNotFound ); break; default: m_flexibleOfflineHandler->handleFlexibleOfflineResult( FomrUnknownError ); break; } break; default: break; } break; } }
void Adhoc::handleIqID( const IQ& iq, int context ) { if( context != ExecuteAdhocCommand ) return; m_adhocTrackMapMutex.lock(); AdhocTrackMap::iterator it = m_adhocTrackMap.find( iq.id() ); bool haveIdHandler = ( it != m_adhocTrackMap.end() ); m_adhocTrackMapMutex.unlock(); if( !haveIdHandler || (*it).second.context != context || (*it).second.remote != iq.from() ) return; switch( iq.subtype() ) { case IQ::Error: (*it).second.ah->handleAdhocError( iq.from(), iq.error(), (*it).second.handlerContext ); break; case IQ::Result: { const Adhoc::Command* ac = iq.findExtension<Adhoc::Command>( ExtAdhocCommand ); if( ac ) (*it).second.ah->handleAdhocExecutionResult( iq.from(), *ac, (*it).second.handlerContext ); break; } default: break; } m_adhocTrackMapMutex.lock(); m_adhocTrackMap.erase( it ); m_adhocTrackMapMutex.unlock(); }
void Client::processResourceBind( const IQ& iq ) { switch( iq.subtype() ) { case IQ::Result: { const ResourceBind* rb = iq.findExtension<ResourceBind>( ExtResourceBind ); if( !rb || !rb->jid() ) { notifyOnResourceBindError( 0 ); break; } m_jid = rb->jid(); m_resourceBound = true; m_selectedResource = m_jid.resource(); notifyOnResourceBind( m_jid.resource() ); if( m_streamFeatures & StreamFeatureSession ) createSession(); else connected(); break; } case IQ::Error: { notifyOnResourceBindError( iq.error() ); break; } default: break; } }
void LastActivity::handleIqID( const IQ& iq, int /*context*/ ) { if( !m_lastActivityHandler ) return; if( iq.subtype() == IQ::Result ) { const Query* q = iq.findExtension<Query>( ExtLastActivity ); if( !q || q->seconds() < 0 ) return; m_lastActivityHandler->handleLastActivityResult( iq.from(), q->seconds(), q->status() ); } else if( iq.subtype() == IQ::Error && iq.error() ) m_lastActivityHandler->handleLastActivityError( iq.from(), iq.error()->error() ); }
void NonSaslAuth::handleIqID( const IQ& iq, int context ) { switch( iq.subtype() ) { case IQ::Error: { const Error* e = iq.error(); if( e ) { switch( e->error() ) { case StanzaErrorConflict: m_parent->setAuthFailure( NonSaslConflict ); break; case StanzaErrorNotAcceptable: m_parent->setAuthFailure( NonSaslNotAcceptable ); break; case StanzaErrorNotAuthorized: m_parent->setAuthFailure( NonSaslNotAuthorized ); break; default: break; } } m_parent->setAuthed( false ); m_parent->disconnect( ConnAuthenticationFailed ); break; } case IQ::Result: switch( context ) { case TrackRequestAuthFields: { const Query* q = iq.findExtension<Query>( ExtNonSaslAuth ); if( !q ) return; const std::string& id = m_parent->getID(); IQ re( IQ::Set, JID(), id ); re.addExtension( q->newInstance( m_parent->username(), m_sid, m_parent->password(), m_parent->jid().resource() ) ); m_parent->send( re, this, TrackSendAuth ); break; } case TrackSendAuth: m_parent->setAuthed( true ); m_parent->connected(); break; } break; default: break; } }
void Search::handleIqID( const IQ& iq, int context ) { TrackMap::iterator it = m_track.find( iq.id() ); if( it != m_track.end() ) { switch( iq.subtype() ) { case IQ::Result: { const Query* q = iq.findExtension<Query>( ExtSearch ); if( !q ) return; switch( context ) { case FetchSearchFields: { if( q->form() ) { (*it).second->handleSearchFields( iq.from(), q->form() ); } else { (*it).second->handleSearchFields( iq.from(), q->fields(), q->instructions() ); } break; } case DoSearch: { if( q->form() ) { (*it).second->handleSearchResult( iq.from(), q->form() ); } else { (*it).second->handleSearchResult( iq.from(), q->result() ); } break; } } break; } case IQ::Error: (*it).second->handleSearchError( iq.from(), iq.error() ); break; default: break; } m_track.erase( it ); } return; }
bool LastActivity::handleIq( const IQ& iq ) { const Query* q = iq.findExtension<Query>( ExtLastActivity ); if( !q || iq.subtype() != IQ::Get ) return false; IQ re( IQ::Result, iq.from(), iq.id() ); re.addExtension( new Query( EmptyString, (long)( time( 0 ) - m_active ) ) ); m_parent->send( re ); return true; }
bool PrivacyManager::handleIq( const IQ& iq ) { const Query* q = iq.findExtension<Query>( ExtPrivacy ); if( iq.subtype() != IQ::Set || !m_privacyListHandler || !q || q->name().empty() ) return false; m_privacyListHandler->handlePrivacyListChanged( q->name() ); IQ re( IQ::Result, JID(), iq.id() ); m_parent->send( re ); return true; }
bool RosterManager::handleIq( const IQ& iq ) { if( iq.subtype() != IQ::Set ) // FIXME add checks for 'from' attribute (empty or bare self jid?) return false; // single roster item push const Query* q = iq.findExtension<Query>( ExtRoster ); if( q && q->roster().size() ) mergePush( q->roster() ); IQ re( IQ::Result, JID(), iq.id() ); m_parent->send( re ); return true; }
void Client::processCreateSession( const IQ& iq ) { switch( iq.subtype() ) { case IQ::Result: connected(); break; case IQ::Error: notifyOnSessionCreateError( iq.error() ); break; default: break; } }
void TestInitiator::send( const IQ& iq ) { // printf( "TestInitiator::senD(IQ): %s\n", iq.tag()->xml().c_str() ); m_result2 = false; switch( m_test ) { case 2: case 3: if( iq.subtype() == IQ::Result && iq.to().full() == "foo@bar" ) m_result2 = true; break; } }
void TestResponder::send( const IQ& iq ) { m_result2 = false; // printf( "TestResponder::senD(IQ): %s\n", iq.tag()->xml().c_str() ); switch( m_test ) { case 1: if( iq.subtype() == IQ::Result && iq.to().full() == "self" ) { // printf( "m_result2 = true;\n" ); m_result2 = true; } break; } }
void Session::handleIqID( const IQ& iq, int context ) { if( iq.subtype() == IQ::Error ) { const Error* e = iq.findExtension<Error>( ExtError ); m_handler->handleSessionActionError( (Action)context, this, e ); switch( context ) { case ContentAccept: break; case ContentAdd: break; case ContentModify: break; case ContentReject: break; case ContentRemove: break; case DescriptionInfo: break; case SessionAccept: break; case SessionInfo: break; case SessionInitiate: m_state = Ended; break; case SessionTerminate: break; case TransportAccept: break; case TransportInfo: break; case TransportReject: break; case TransportReplace: break; case InvalidAction: break; default: break; } } }
void SIManager::handleIqID( const IQ& iq, int context ) { switch( iq.subtype() ) { case IQ::Result: if( context == OfferSI ) { TrackMap::iterator it = m_track.find( iq.id() ); if( it != m_track.end() ) { const SI* si = iq.findExtension<SI>( ExtSI ); if( !si /*|| si->profile().empty()*/ ) return; // Tag* si = iq.query(); // Tag* ptag = 0; // Tag* fneg = 0; // if( si && si->name() == "si" && si->xmlns() == XMLNS_SI ) // { // ptag = si->findChildWithAttrib( XMLNS, (*it).second.profile ); // fneg = si->findChild( "feature", XMLNS, XMLNS_FEATURE_NEG ); // } // FIXME: remove above commented code and // check corectness of last 3 params! (*it).second.sih->handleSIRequestResult( iq.from(), iq.to(), (*it).second.sid, *si ); m_track.erase( it ); } } break; case IQ::Error: if( context == OfferSI ) { TrackMap::iterator it = m_track.find( iq.id() ); if( it != m_track.end() ) { (*it).second.sih->handleSIRequestError( iq, (*it).second.sid ); m_track.erase( it ); } } break; default: break; } }
void InBandBytestream::handleIqID( const IQ& iq, int context ) { switch( iq.subtype() ) { case IQ::Result: if( context == IBBOpen && m_handler ) { m_handler->handleBytestreamOpen( this ); m_open = true; } break; case IQ::Error: closed(); break; default: break; } }
bool InBandBytestream::handleIq( const IQ& iq ) // data or open request, always 'set' { const IBB* i = iq.findExtension<IBB>( ExtIBB ); if( !i || !m_handler || iq.subtype() != IQ::Set ) return false; if( !m_open ) { if( i->type() == IBBOpen ) { returnResult( iq.from(), iq.id() ); m_open = true; m_handler->handleBytestreamOpen( this ); return true; } return false; } if( i->type() == IBBClose ) { returnResult( iq.from(), iq.id() ); closed(); return true; } if( ( m_lastChunkReceived + 1 ) != i->seq() ) { m_open = false; returnError( iq.from(), iq.id(), StanzaErrorTypeModify, StanzaErrorItemNotFound ); return false; } if( i->data().empty() ) { m_open = false; returnError( iq.from(), iq.id(), StanzaErrorTypeModify, StanzaErrorBadRequest ); return false; } returnResult( iq.from(), iq.id() ); m_handler->handleBytestreamData( this, i->data() ); m_lastChunkReceived++; return true; }
bool Adhoc::handleIq( const IQ& iq ) { if( iq.subtype() != IQ::Set ) return false; const Adhoc::Command* ac = iq.findExtension<Adhoc::Command>( ExtAdhocCommand ); if( !ac || ac->node().empty()) return false; AdhocCommandProviderMap::const_iterator it = m_adhocCommandProviders.find( ac->node() ); if( it != m_adhocCommandProviders.end() ) { const std::string& sess = ac->sessionID().empty() ? m_parent->getID() : ac->sessionID(); m_activeSessions[sess] = iq.id(); (*it).second->handleAdhocCommand( iq.from(), *ac, sess ); return true; } return false; }
void Disco::handleIqID( const IQ& iq, int context ) { DiscoHandlerMap::iterator it = m_track.find( iq.id() ); if( it != m_track.end() && (*it).second.dh ) { switch( iq.subtype() ) { case IQ::Result: switch( context ) { case GetDiscoInfo: { const Info* di = iq.findExtension<Info>( ExtDiscoInfo ); if( di ) (*it).second.dh->handleDiscoInfo( iq.from(), *di, (*it).second.context ); break; } case GetDiscoItems: { const Items* di = iq.findExtension<Items>( ExtDiscoItems ); if( di ) (*it).second.dh->handleDiscoItems( iq.from(), *di, (*it).second.context ); break; } } break; case IQ::Error: { (*it).second.dh->handleDiscoError( iq.from(), iq.error(), (*it).second.context ); break; } default: break; } m_track.erase( it ); } }
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( (VCardHandler::VCardContext)context, iq.from(), iq.error() ? iq.error()->error() : StanzaErrorUndefined ); break; } default: break; } m_trackMap.erase( it ); } }
bool SOCKS5BytestreamManager::handleIq( const IQ& iq ) { const Query* q = iq.findExtension<Query>( ExtS5BQuery ); if( !q || !m_socks5BytestreamHandler || m_trackMap.find( iq.id() ) != m_trackMap.end() ) return false; switch( iq.subtype() ) { case IQ::Set: { const std::string& sid = q->sid(); // FIXME What is haveStream() good for? if( /*haveStream( iq.from() ) ||*/ sid.empty() || q->mode() == S5BUDP ) { rejectSOCKS5Bytestream( iq.from(), iq.id(), StanzaErrorNotAcceptable ); return true; } AsyncS5BItem asi; asi.sHosts = q->hosts(); asi.id = iq.id(); asi.from = iq.from(); asi.to = iq.to(); asi.incoming = true; m_asyncTrackMap[sid] = asi; m_socks5BytestreamHandler->handleIncomingBytestreamRequest( sid, iq.from() ); break; } case IQ::Error: m_socks5BytestreamHandler->handleBytestreamError( iq, EmptyString ); break; default: break; } return true; }
bool Disco::handleIq( const IQ& iq ) { switch( iq.subtype() ) { case IQ::Get: { IQ re( IQ::Result, iq.from(), iq.id() ); re.setFrom( iq.to() ); const SoftwareVersion* sv = iq.findExtension<SoftwareVersion>( ExtVersion ); if( sv ) { re.addExtension( new SoftwareVersion( m_versionName, m_versionVersion, m_versionOs ) ); m_parent->send( re ); return true; } const Info *info = iq.findExtension<Info>( ExtDiscoInfo ); if( info ) { Info *i = new Info( EmptyString, true ); if( !info->node().empty() ) { i->setNode( info->node() ); IdentityList identities; StringList features; DiscoNodeHandlerMap::const_iterator it = m_nodeHandlers.find( info->node() ); if( it == m_nodeHandlers.end() ) { delete i; IQ re( IQ::Error, iq.from(), iq.id() ); re.addExtension( new Error( StanzaErrorTypeCancel, StanzaErrorItemNotFound ) ); m_parent->send( re ); return true; } else { DiscoNodeHandlerList::const_iterator in = (*it).second.begin(); for( ; in != (*it).second.end(); ++in ) { IdentityList il = (*in)->handleDiscoNodeIdentities( iq.from(), info->node() ); il.sort(); // needed on win32 identities.merge( il ); StringList fl = (*in)->handleDiscoNodeFeatures( iq.from(), info->node() ); fl.sort(); // needed on win32 features.merge( fl ); } } i->setIdentities( identities ); i->setFeatures( features ); } else { IdentityList il; IdentityList::const_iterator it = m_identities.begin(); for( ; it != m_identities.end(); ++it ) { il.push_back( new Identity( *(*it) ) ); } i->setIdentities( il ); i->setFeatures( m_features ); if( m_form ) i->setForm( new DataForm( *m_form ) ); } re.addExtension( i ); m_parent->send( re ); return true; } const Items *items = iq.findExtension<Items>( ExtDiscoItems ); if( items ) { Items *i = new Items( items->node() ); if( !items->node().empty() ) { DiscoNodeHandlerMap::const_iterator it = m_nodeHandlers.find( items->node() ); if( it == m_nodeHandlers.end() ) { delete i; IQ re( IQ::Error, iq.from(), iq.id() ); re.addExtension( new Error( StanzaErrorTypeCancel, StanzaErrorItemNotFound ) ); m_parent->send( re ); return true; } else { ItemList itemlist; DiscoNodeHandlerList::const_iterator in = (*it).second.begin(); for( ; in != (*it).second.end(); ++in ) { ItemList il = (*in)->handleDiscoNodeItems( iq.from(), iq.to(), items->node() ); il.sort(); // needed on win32 itemlist.merge( il ); } i->setItems( itemlist ); } } re.addExtension( i ); m_parent->send( re ); return true; } break; } case IQ::Set: { bool res = false; DiscoHandlerList::const_iterator it = m_discoHandlers.begin(); for( ; it != m_discoHandlers.end(); ++it ) { if( (*it)->handleDiscoSet( iq ) ) res = true; } return res; break; } default: break; } return false; }
void Registration::handleIqID( const IQ& iq, int context ) { if( !m_registrationHandler ) return; if( iq.subtype() == IQ::Result ) { switch( context ) { case FetchRegistrationFields: { const Query* q = iq.findExtension<Query>( ExtRegistration ); if( !q ) return; if( q->registered() ) m_registrationHandler->handleAlreadyRegistered( iq.from() ); if( q->form() ) m_registrationHandler->handleDataForm( iq.from(), *(q->form()) ); if( q->oob() ) m_registrationHandler->handleOOB( iq.from(), *(q->oob()) ); m_registrationHandler->handleRegistrationFields( iq.from(), q->fields(), q->instructions() ); break; } case CreateAccount: case ChangePassword: case RemoveAccount: m_registrationHandler->handleRegistrationResult( iq.from(), RegistrationSuccess ); break; } } else if( iq.subtype() == IQ::Error ) { const Error* e = iq.error(); if( !e ) return; switch( e->error() ) { case StanzaErrorConflict: m_registrationHandler->handleRegistrationResult( iq.from(), RegistrationConflict ); break; case StanzaErrorNotAcceptable: m_registrationHandler->handleRegistrationResult( iq.from(), RegistrationNotAcceptable ); break; case StanzaErrorBadRequest: m_registrationHandler->handleRegistrationResult( iq.from(), RegistrationBadRequest ); break; case StanzaErrorForbidden: m_registrationHandler->handleRegistrationResult( iq.from(), RegistrationForbidden ); break; case StanzaErrorRegistrationRequired: m_registrationHandler->handleRegistrationResult( iq.from(), RegistrationRequired ); break; case StanzaErrorUnexpectedRequest: m_registrationHandler->handleRegistrationResult( iq.from(), RegistrationUnexpectedRequest ); break; case StanzaErrorNotAuthorized: m_registrationHandler->handleRegistrationResult( iq.from(), RegistrationNotAuthorized ); break; case StanzaErrorNotAllowed: m_registrationHandler->handleRegistrationResult( iq.from(), RegistrationNotAllowed ); break; default: m_registrationHandler->handleRegistrationResult( iq.from(), RegistrationUnknownError ); break; } } }
int main( int /*argc*/, char** /*argv*/ ) { int fail = 0; std::string name; Tag *iq = new Tag( "iq" ); iq->addAttribute( "from", "[email protected]/gloox" ); iq->addAttribute( "to", "[email protected]/gloox" ); iq->addAttribute( "id", "id1" ); iq->addAttribute( "type", "set" ); IQ* i = 0; // ------- name = "parse IQ set"; i = new IQ( iq ); if( i->subtype() != IQ::Set || i->from().full() != "[email protected]/gloox" || i->to().full() != "[email protected]/gloox" || i->id() != "id1" ) { ++fail; printf( "test '%s' failed\n", name.c_str() ); } delete i; i = 0; // ------- name = "parse IQ get"; iq->addAttribute( "type", "get" ); i = new IQ( iq ); if( i->subtype() != IQ::Get || i->from().full() != "[email protected]/gloox" || i->to().full() != "[email protected]/gloox" || i->id() != "id1" ) { ++fail; printf( "test '%s' failed\n", name.c_str() ); } delete i; i = 0; // ------- name = "parse IQ error"; iq->addAttribute( "type", "error" ); i = new IQ( iq ); if( i->subtype() != IQ::Error || i->from().full() != "[email protected]/gloox" || i->to().full() != "[email protected]/gloox" || i->id() != "id1" ) { ++fail; printf( "test '%s' failed\n", name.c_str() ); } delete i; i = 0; // ------- name = "parse IQ result"; iq->addAttribute( "type", "result" ); i = new IQ( iq ); if( i->subtype() != IQ::Result || i->from().full() != "[email protected]/gloox" || i->to().full() != "[email protected]/gloox" || i->id() != "id1" ) { ++fail; printf( "test '%s' failed\n", name.c_str() ); } delete i; i = 0; // ------- { name = "new simple IQ error"; IQ iq( IQ::Error, JID( "[email protected]/blah" ), "id2" ); Tag* i = iq.tag(); if( !i->hasAttribute( "type", "error" ) || !i->hasAttribute( "id", "id2" ) || !i->hasAttribute( "to", "[email protected]/blah" ) ) { ++fail; printf( "test '%s' failed: %s\n", name.c_str(), i->xml().c_str() ); } delete i; } // ------- { name = "new simple IQ result"; IQ iq( IQ::Result, JID( "[email protected]/blah" ), "id2" ); Tag* i = iq.tag(); if( !i->hasAttribute( "type", "result" ) || !i->hasAttribute( "id", "id2" ) || !i->hasAttribute( "to", "[email protected]/blah" ) ) { ++fail; printf( "test '%s' failed: %s\n", name.c_str(), i->xml().c_str() ); } delete i; } // ------- { name = "new simple IQ get"; IQ iq( IQ::Get, JID( "[email protected]/blah" ), "id2" ); Tag* i = iq.tag(); if( !i->hasAttribute( "type", "get" ) || !i->hasAttribute( "id", "id2" ) || !i->hasAttribute( "to", "[email protected]/blah" ) ) { ++fail; printf( "test '%s' failed: %s\n", name.c_str(), i->xml().c_str() ); } delete i; } // ------- { name = "new simple IQ set 1"; IQ iq( IQ::Set, JID( "[email protected]/blah" ), "id2" ); Tag* i = iq.tag(); if( !i->hasAttribute( "type", "set" ) || !i->hasAttribute( "id", "id2" ) || !i->hasAttribute( "to", "[email protected]/blah" ) ) { ++fail; printf( "test '%s' failed: %s\n", name.c_str(), i->xml().c_str() ); } delete i; } // FIXME these need to use SEs, as IQ::query() will go away eventually // // ------- // { // name = "new simple IQ set 2"; // IQ iq( IQ::Set, JID( "[email protected]/blah" ), "id2", "mynamespace" ); // Tag* i = iq.tag(); // if( !i->hasAttribute( "type", "set" ) || !i->hasAttribute( "id", "id2" ) // || !i->hasAttribute( "to", "[email protected]/blah" ) || !i->hasChild( "query", "xmlns", "mynamespace" ) ) // { // ++fail; // printf( "test '%s' failed: %s\n", name.c_str(), i->xml().c_str() ); // } // delete i; // } // // // ------- // { // name = "new simple IQ set 3"; // IQ iq( IQ::Set, JID( "[email protected]/blah" ), "id2", "mynamespace", "testtag" ); // Tag* i = iq.tag(); // if( !i->hasAttribute( "type", "set" ) || !i->hasAttribute( "id", "id2" ) // || !i->hasAttribute( "to", "[email protected]/blah" ) // || !i->hasChild( "testtag", "xmlns", "mynamespace" ) ) // { // ++fail; // printf( "test '%s' failed: %s\n", name.c_str(), i->xml().c_str() ); // } // delete i; // } // // // ------- // { // name = "new simple IQ set 4"; // IQ iq( IQ::Set, JID( "[email protected]/blah" ), "id2", "mynamespace", "testtag", // JID( "[email protected]/foo" ) ); // Tag* i = iq.tag(); // if( !i->hasAttribute( "type", "set" ) || !i->hasAttribute( "id", "id2" ) // || !i->hasAttribute( "to", "[email protected]/blah" ) || !i->hasChild( "testtag", "xmlns", "mynamespace" ) // || !i->hasAttribute( "from", "[email protected]/foo" ) ) // { // ++fail; // printf( "test '%s' failed: %s\n", name.c_str(), i->xml().c_str() ); // } // delete i; // } // FIXME fix the following test. how to test private functions, ctors, etc? // // ------- // name = "rip off"; // i = new IQ( iq ); // if( !i->hasAttribute( "type", "result" ) || !i->hasAttribute( "id", "id1" ) // || !i->hasAttribute( "to", "[email protected]/gloox" ) || !i->hasChild( "query", "xmlns", "mynamespace" ) // || !i->hasAttribute( "from", "[email protected]/gloox" ) // || iq->children().size() != 0 ) // { // ++fail; // printf( "test '%s' failed: %s\n", name.c_str(), i->xml().c_str() ); // } // delete i; // i = 0; delete iq; iq = 0; if( fail == 0 ) { printf( "IQ: OK\n" ); return 0; } else { printf( "IQ: %d test(s) failed\n", fail ); return 1; } }
void SOCKS5BytestreamManager::handleIqID( const IQ& iq, int context ) { StringMap::iterator it = m_trackMap.find( iq.id() ); if( it == m_trackMap.end() ) return; switch( context ) { case S5BOpenStream: { switch( iq.subtype() ) { case IQ::Result: { const Query* q = iq.findExtension<Query>( ExtS5BQuery ); if( q && m_socks5BytestreamHandler ) { const std::string& proxy = q->jid().full(); const StreamHost* sh = findProxy( iq.from(), proxy, (*it).second ); if( sh ) { SOCKS5Bytestream* s5b = 0; bool selfProxy = ( proxy == m_parent->jid().full() && m_server ); if( selfProxy ) { SHA sha; sha.feed( (*it).second ); sha.feed( iq.to().full() ); sha.feed( iq.from().full() ); s5b = new SOCKS5Bytestream( this, m_server->getConnection( sha.hex() ), m_parent->logInstance(), iq.to(), iq.from(), (*it).second ); } else { s5b = new SOCKS5Bytestream( this, m_parent->connectionImpl()->newInstance(), m_parent->logInstance(), iq.to(), iq.from(), (*it).second ); s5b->setStreamHosts( StreamHostList( 1, *sh ) ); } m_s5bMap[(*it).second] = s5b; m_socks5BytestreamHandler->handleOutgoingBytestream( s5b ); if( selfProxy ) s5b->activate(); } } break; } case IQ::Error: m_socks5BytestreamHandler->handleBytestreamError( iq, (*it).second ); break; default: break; } break; } case S5BActivateStream: { switch( iq.subtype() ) { case IQ::Result: { S5BMap::const_iterator it5 = m_s5bMap.find( (*it).second ); if( it5 != m_s5bMap.end() ) (*it5).second->activate(); break; } case IQ::Error: m_socks5BytestreamHandler->handleBytestreamError( iq, (*it).second ); break; default: break; } break; } default: break; } m_trackMap.erase( it ); }
void whistleVcardHandler::handleIqID( const IQ& iq, int context ) { switch( iq.subtype() ) { case IQ::Result: { switch( context ) { case VCardHandler::FetchVCard: { json::jobject jobj; json::jobject status = json::jobject(); if (iq.findExtension( ExtVCard )) { boost::shared_ptr<gloox::Tag> ptag(iq.findExtension( ExtVCard )->tag()); for (TagList::const_iterator cit = ptag->children().begin(); cit != ptag->children().end(); ++cit) { Tag* ptag = *cit; if (ptag->name() == s_VcardPrivacy) { jobj[ptag->name()] = json::jobject(ptag->cdata()); } else if (ptag->name() == s_VcardStatus) { //获取vcard协议改变 新的解析iq Tag* presource = ptag->findChild("resource"); Tag* pshow = ptag->findChild("show"); if ( presource && pshow) { json::jobject itemdata; itemdata["resource"] = presource->cdata(); itemdata["show"] = pshow->cdata(); status.arr_push(itemdata); } } else { jobj[ptag->name()] = ptag->cdata(); } } jobj[s_VcardJid] = iq.from().bare(); gwhistleVcard::instance().handleVCard(iq.from(), jobj, status, waitCallback_); } break; } case VCardHandler::StoreVCard: gwhistleVcard::instance().handleVCardResult(VCardHandler::StoreVCard, iq.from()); break; } } break; case IQ::Error: { switch( context ) { case VCardHandler::FetchVCard: if (!waitCallback_.empty()) { waitCallback_(); } else { gwhistleVcard::instance().updatedVcard(iq.from()); } break; case VCardHandler::StoreVCard: gwhistleVcard::instance().handleVCardResult( (VCardHandler::VCardContext)context, iq.from(), iq.error() ? iq.error()->error() : StanzaErrorUndefined ); break; } } default: break; } }
void PrivacyManager::handleIqID( const IQ& iq, int context ) { if( !m_privacyListHandler ) return; switch( iq.subtype() ) { case IQ::Result: switch( context ) { case PLStore: m_privacyListHandler->handlePrivacyListResult( iq.id(), ResultStoreSuccess ); break; case PLActivate: m_privacyListHandler->handlePrivacyListResult( iq.id(), ResultActivateSuccess ); break; case PLDefault: m_privacyListHandler->handlePrivacyListResult( iq.id(), ResultDefaultSuccess ); break; case PLRemove: m_privacyListHandler->handlePrivacyListResult( iq.id(), ResultRemoveSuccess ); break; case PLRequestNames: { const Query* q = iq.findExtension<Query>( ExtPrivacy ); if( !q ) return; m_privacyListHandler->handlePrivacyListNames( q->def(), q->active(), q->names() ); break; } case PLRequestList: { const Query* q = iq.findExtension<Query>( ExtPrivacy ); if( !q ) return; m_privacyListHandler->handlePrivacyList( q->name(), q->items() ); break; } } break; case IQ::Error: { switch( iq.error()->error() ) { case StanzaErrorConflict: m_privacyListHandler->handlePrivacyListResult( iq.id(), ResultConflict ); break; case StanzaErrorItemNotFound: m_privacyListHandler->handlePrivacyListResult( iq.id(), ResultItemNotFound ); break; case StanzaErrorBadRequest: m_privacyListHandler->handlePrivacyListResult( iq.id(), ResultBadRequest ); break; default: m_privacyListHandler->handlePrivacyListResult( iq.id(), ResultUnknownError ); break; } break; } default: break; } }