Example #1
0
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;
  }
}
Example #2
0
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;
  }
}
Example #3
0
  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;
    }
  }
Example #4
0
  bool SIManager::handleIq( const IQ& iq )
  {
    TrackMap::iterator itt = m_track.find( iq.id() );
    if( itt != m_track.end() )
      return false;

    const SI* si = iq.findExtension<SI>( ExtSI );
    if( !si || si->profile().empty() )
      return false;

    HandlerMap::const_iterator it = m_handlers.find( si->profile() );
    if( it != m_handlers.end() && (*it).second )
    {
      (*it).second->handleSIRequest( iq.from(), iq.to(), iq.id(), *si );
      return true;
    }

    return false;
  }
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;
}
Example #6
0
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;
  }

}
Example #7
0
  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 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 );
}