⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clientbase.cpp

📁 Jabber code library, developed with c
💻 CPP
📖 第 1 页 / 共 3 页
字号:
      m_messageSessionHandlerHeadline = msh;  }  void ClientBase::registerPresenceHandler( PresenceHandler *ph )  {    if( ph )      m_presenceHandlers.push_back( ph );  }  void ClientBase::removePresenceHandler( PresenceHandler *ph )  {    if( ph )      m_presenceHandlers.remove( ph );  }  void ClientBase::registerPresenceHandler( const JID& jid, PresenceHandler *ph )  {    if( ph && jid )    {      JidPresHandlerStruct jph;      jph.jid = new JID( jid.bare() );      jph.ph = ph;      m_presenceJidHandlers.push_back( jph );    }  }  void ClientBase::removePresenceHandler( const JID& jid, PresenceHandler *ph )  {    PresenceJidHandlerList::iterator t;    PresenceJidHandlerList::iterator it = m_presenceJidHandlers.begin();    while( it != m_presenceJidHandlers.end() )    {      t = it;      ++it;      if( ( !ph || (*t).ph == ph ) && (*t).jid->bare() == jid.bare() )      {        delete (*t).jid;        m_presenceJidHandlers.erase( t );      }    }  }  void ClientBase::trackID( IqHandler *ih, const std::string& id, int context )  {    if( ih && !id.empty() )    {      TrackStruct track;      track.ih = ih;      track.context = context;      m_iqIDHandlers[id] = track;    }  }  void ClientBase::removeIDHandler( IqHandler *ih )  {    IqTrackMap::iterator t;    IqTrackMap::iterator it = m_iqIDHandlers.begin();    while( it != m_iqIDHandlers.end() )    {      t = it;      ++it;      if( ih == (*t).second.ih )        m_iqIDHandlers.erase( t );    }  }  void ClientBase::registerIqHandler( IqHandler *ih, const std::string& xmlns )  {    if( ih && !xmlns.empty() )      m_iqNSHandlers[xmlns] = ih;  }  void ClientBase::removeIqHandler( const std::string& xmlns )  {    if( !xmlns.empty() )      m_iqNSHandlers.erase( xmlns );  }  void ClientBase::registerMessageSession( MessageSession *session )  {    if( session )      m_messageSessions.push_back( session );  }  void ClientBase::disposeMessageSession( MessageSession *session )  {    if( !session )      return;    MessageSessionList::iterator it = std::find( m_messageSessions.begin(), m_messageSessions.end(),                                                 session );    if( it != m_messageSessions.end() )    {      delete (*it);      m_messageSessions.erase( it );    }  }  void ClientBase::registerMessageHandler( MessageHandler *mh )  {    if( mh )      m_messageHandlers.push_back( mh );  }  void ClientBase::removeMessageHandler( MessageHandler *mh )  {    if( mh )      m_messageHandlers.remove( mh );  }  void ClientBase::registerSubscriptionHandler( SubscriptionHandler *sh )  {    if( sh )      m_subscriptionHandlers.push_back( sh );  }  void ClientBase::removeSubscriptionHandler( SubscriptionHandler *sh )  {    if( sh )      m_subscriptionHandlers.remove( sh );  }  void ClientBase::registerTagHandler( TagHandler *th, const std::string& tag, const std::string& xmlns )  {    if( th && !tag.empty() )    {      TagHandlerStruct ths;      ths.tag = tag;      ths.xmlns = xmlns;      ths.th = th;      m_tagHandlers.push_back( ths );    }  }  void ClientBase::removeTagHandler( TagHandler *th, const std::string& tag, const std::string& xmlns )  {    if( th )    {      TagHandlerList::iterator it = m_tagHandlers.begin();      for( ; it != m_tagHandlers.end(); ++it )      {        if( (*it).th == th && (*it).tag == tag && (*it).xmlns == xmlns )          m_tagHandlers.erase( it );      }    }  }  void ClientBase::registerStatisticsHandler( StatisticsHandler *sh )  {    if( sh )      m_statisticsHandler = sh;  }  void ClientBase::removeStatisticsHandler()  {    m_statisticsHandler = 0;  }  void ClientBase::registerMUCInvitationHandler( MUCInvitationHandler *mih )  {    if( mih )    {      m_mucInvitationHandler = mih;      m_disco->addFeature( XMLNS_MUC );    }  }  void ClientBase::removeMUCInvitationHandler()  {    m_mucInvitationHandler = 0;    m_disco->removeFeature( XMLNS_MUC );  }  void ClientBase::registerConnectionListener( ConnectionListener *cl )  {    if( cl )      m_connectionListeners.push_back( cl );  }  void ClientBase::removeConnectionListener( ConnectionListener *cl )  {    if( cl )      m_connectionListeners.remove( cl );  }  void ClientBase::notifyOnConnect()  {    ConnectionListenerList::const_iterator it = m_connectionListeners.begin();    for( ; it != m_connectionListeners.end(); ++it )    {      (*it)->onConnect();    }  }  void ClientBase::notifyOnDisconnect( ConnectionError e )  {    ConnectionListenerList::const_iterator it = m_connectionListeners.begin();    for( ; it != m_connectionListeners.end(); ++it )    {      (*it)->onDisconnect( e );    }    init();  }  bool ClientBase::notifyOnTLSConnect( const CertInfo& info )  {    ConnectionListenerList::const_iterator it = m_connectionListeners.begin();    for( ; it != m_connectionListeners.end() && (*it)->onTLSConnect( info ); ++it )      ;    return m_stats.encryption = ( it == m_connectionListeners.end() );  }  void ClientBase::notifyOnResourceBindError( ResourceBindError error )  {    ConnectionListenerList::const_iterator it = m_connectionListeners.begin();    for( ; it != m_connectionListeners.end(); ++it )    {      (*it)->onResourceBindError( error );    }  }  void ClientBase::notifyOnSessionCreateError( SessionCreateError error )  {    ConnectionListenerList::const_iterator it = m_connectionListeners.begin();    for( ; it != m_connectionListeners.end(); ++it )    {      (*it)->onSessionCreateError( error );    }  }  void ClientBase::notifyStreamEvent( StreamEvent event )  {    ConnectionListenerList::const_iterator it = m_connectionListeners.begin();    for( ; it != m_connectionListeners.end(); ++it )    {      (*it)->onStreamEvent( event );    }  }  void ClientBase::notifyPresenceHandlers( Stanza *stanza )  {    bool match = false;    PresenceJidHandlerList::const_iterator itj = m_presenceJidHandlers.begin();    for( ; itj != m_presenceJidHandlers.end(); ++itj )    {      if( (*itj).jid->bare() == stanza->from().bare() && (*itj).ph )      {        (*itj).ph->handlePresence( stanza );        match = true;      }    }    if( match )      return;    PresenceHandlerList::const_iterator it = m_presenceHandlers.begin();    for( ; it != m_presenceHandlers.end(); ++it )    {      (*it)->handlePresence( stanza );    }  }  void ClientBase::notifySubscriptionHandlers( Stanza *stanza )  {    SubscriptionHandlerList::const_iterator it = m_subscriptionHandlers.begin();    for( ; it != m_subscriptionHandlers.end(); ++it )    {      (*it)->handleSubscription( stanza );    }  }  void ClientBase::notifyIqHandlers( Stanza *stanza )  {    bool res = false;    IqHandlerMap::const_iterator it = m_iqNSHandlers.begin();    for( ; it != m_iqNSHandlers.end(); ++it )    {      if( stanza->hasChildWithAttrib( "xmlns", (*it).first ) )      {        if( (*it).second->handleIq( stanza ) )          res = true;      }    }    IqTrackMap::iterator it_id = m_iqIDHandlers.find( stanza->id() );    if( it_id != m_iqIDHandlers.end() )    {      if( (*it_id).second.ih->handleIqID( stanza, (*it_id).second.context ) )        res = true;      m_iqIDHandlers.erase( it_id );    }    if( !res && ( stanza->type() == StanzaIq ) &&         ( ( stanza->subtype() == StanzaIqGet ) || ( stanza->subtype() == StanzaIqSet ) ) )    {      Tag *iq = new Tag( "iq" );      iq->addAttribute( "type", "error" );      iq->addAttribute( "id", stanza->id() );      iq->addAttribute( "to", stanza->from().full() );      Tag *e = new Tag( iq, "error", "type", "cancel", false );      new Tag( e, "service-unavailable", "xmlns", XMLNS_XMPP_STANZAS );      send( iq );    }  }  void ClientBase::notifyMessageHandlers( Stanza *stanza )  {    if( m_mucInvitationHandler )    {      Tag *x = stanza->findChild( "x", "xmlns", XMLNS_MUC_USER );      if( x && x->hasChild( "invite" ) )      {        Tag *i = x->findChild( "invite" );        JID invitee( i->findAttribute( "from" ) );        Tag * t = i->findChild( "reason" );        std::string reason ( t ? t->cdata() : "" );        t = x->findChild( "password" );        std::string password ( t ? t->cdata() : "" );        m_mucInvitationHandler->handleMUCInvitation( stanza->from(), invitee,                                              reason, stanza->body(), password,                                              i->hasChild( "continue" ) );        return;      }    }    MessageSessionList::const_iterator it1 = m_messageSessions.begin();    for( ; it1 != m_messageSessions.end(); ++it1 )    {      if( (*it1)->target().full() == stanza->from().full() &&            ( stanza->thread().empty() || (*it1)->threadID() == stanza->thread() ) &&            ( (*it1)->types() & stanza->subtype() || (*it1)->types() == StanzaSubUndefined ) )      {        (*it1)->handleMessage( stanza );        return;      }    }    it1 = m_messageSessions.begin();    for( ; it1 != m_messageSessions.end(); ++it1 )    {      if( (*it1)->target().bare() == stanza->from().bare() &&            ( stanza->thread().empty() || (*it1)->threadID() == stanza->thread() ) &&            ( (*it1)->types() & stanza->subtype() || (*it1)->types() == StanzaSubUndefined ) )      {        (*it1)->handleMessage( stanza );        return;      }    }    MessageSessionHandler *msHandler = 0;    switch( stanza->subtype() )    {      case StanzaMessageChat:        msHandler = m_messageSessionHandlerChat;        break;      case StanzaMessageNormal:        msHandler = m_messageSessionHandlerNormal;        break;      case StanzaMessageGroupchat:        msHandler = m_messageSessionHandlerGroupchat;        break;      case StanzaMessageHeadline:        msHandler = m_messageSessionHandlerHeadline;        break;      default:        break;    }    if( msHandler )    {      MessageSession *session = new MessageSession( this, stanza->from(), true, stanza->subtype() );      msHandler->handleMessageSession( session );      session->handleMessage( stanza );    }    else    {      MessageHandlerList::const_iterator it = m_messageHandlers.begin();      for( ; it != m_messageHandlers.end(); ++it )      {        (*it)->handleMessage( stanza );      }    }  }  void ClientBase::notifyTagHandlers( Tag *tag )  {    TagHandlerList::const_iterator it = m_tagHandlers.begin();    for( ; it != m_tagHandlers.end(); ++it )    {      if( (*it).tag == tag->name() && tag->hasAttribute( "xmlns", (*it).xmlns ) )        (*it).th->handleTag( tag );    }  }  CompressionBase* ClientBase::getDefaultCompression()  {    if( !m_compress )      return 0;#ifdef HAVE_ZLIB    return new CompressionZlib( this );#else    return 0;#endif  }  TLSBase* ClientBase::getDefaultEncryption()  {    if( m_tls == TLSDisabled || !hasTls() )      return 0;    return new TLSDefault( this, m_server );  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -