Пример #1
0
  void SIProfileFT::handleSIRequest( const JID& from, const JID& to, const std::string& id, const SIManager::SI& si )
  {
    if( si.profile() != XMLNS_SI_FT || !si.tag1() )
      return;

    if( m_handler )
    {
      const Tag* t = si.tag1()->findChild( "desc" );
      const std::string& desc = t ? t->cdata() : EmptyString;

      const std::string& mt = si.mimetype();
      int types = 0;

      if( si.tag2() )
      {
        const DataForm df( si.tag2()->findChild( "x", XMLNS, XMLNS_X_DATA ) );
        const DataFormField* dff = df.field( "stream-method" );

        if( dff )
        {
          const StringMultiMap& options = dff->options();
          StringMultiMap::const_iterator it = options.begin();
          for( ; it != options.end(); ++it )
          {
            if( (*it).second == XMLNS_BYTESTREAMS )
              types |= FTTypeS5B;
            else if( (*it).second == XMLNS_IBB )
              types |= FTTypeIBB;
            else if( (*it).second == XMLNS_IQ_OOB )
              types |= FTTypeOOB;
          }
        }
      }

      const std::string& sid = si.id();
      m_id2sid[sid] = id;
      m_handler->handleFTRequest( from, to, sid, si.tag1()->findAttribute( "name" ),
                                  atol( si.tag1()->findAttribute( "size" ).c_str() ), // if size > LONG_MAX ? commented by JI Yixuan
                                  si.tag1()->findAttribute( "hash" ),
                                  si.tag1()->findAttribute( "date" ),
                                  mt.empty() ? "binary/octet-stream" : mt,
                                  desc, types );
    }
  }
Пример #2
0
  void SIProfileFT::handleSIRequestResult( const JID& from, const JID& to, const std::string& sid,
                                           const SIManager::SI& si )
  {
    if( si.tag2() )
    {
      const DataForm df( si.tag2()->findChild( "x", XMLNS, XMLNS_X_DATA ) );
      const DataFormField* dff = df.field( "stream-method" );

      if( dff )
      {
        if( m_socks5Manager && dff->value() == XMLNS_BYTESTREAMS )
        {
          // check return value:
          m_socks5Manager->requestSOCKS5Bytestream( from, SOCKS5BytestreamManager::S5BTCP, sid, to );
        }
        else if( m_handler )
        {
          if( dff->value() == XMLNS_IBB )
          {
            InBandBytestream* ibb = new InBandBytestream( m_parent, m_parent->logInstance(),
                to ? to : m_parent->jid(), from, sid );

            m_handler->handleFTBytestream( ibb );
          }
          else if( dff->value() == XMLNS_IQ_OOB )
          {
            const std::string& url = m_handler->handleOOBRequestResult( from, to, sid );
            if( !url.empty() )
            {
              const std::string& id = m_parent->getID();
              IQ iq( IQ::Set, from, id );
              if( to )
                iq.setFrom( to );

              iq.addExtension( new OOB( url, EmptyString, true ) );
              m_parent->send( iq, this, OOBSent );
            }
          }
        }
      }
    }
  }
Пример #3
0
int main( int /*argc*/, char** /*argv*/ )
{
  int fail = 0;
  std::string name;
  Tag *t;

  // -------
  {
    name = "empty tag() test";
    SIManager::SI si;
    t = si.tag();
    if( t )
    {
      ++fail;
      printf( "test '%s' failed\n", name.c_str() );
    }
    delete t;
    t = 0;
  }

  // -------
  {
    name = "full ctor";
    Tag* t1 = new Tag( "foo" );
    Tag* t2 = new Tag( "bar" );
    SIManager::SI si( t1, t2, "id", "mime", "prof" );
    t = si.tag();
    if( !t || t->name() != "si" || t->xmlns() != XMLNS_SI
        || !t->hasAttribute( "id", "id" )
        || !t->hasAttribute( "mime-type", "mime" )
        || !t->hasAttribute( "profile", "prof" )
        || !t->hasChild( "foo" )
        || !t->hasChild( "bar" ) )
    {
      ++fail;
      printf( "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() );
    }
    delete t;
    t = 0;
  }

  // -------
  {
    name = "tag ctor";
    Tag* s = new Tag( "si" );
    s->setXmlns( XMLNS_SI );
    s->addAttribute( "id", "id" );
    s->addAttribute( "mime-type", "mime" );
    s->addAttribute( "profile", "prof" );
    Tag* f1 = new Tag( s, "file" );
    f1->setXmlns( XMLNS_SI_FT );
    Tag* f2 = new Tag( s, "feature" );
    f2->setXmlns( XMLNS_FEATURE_NEG );

    SIManager::SI si( s );
    t = si.tag();
    if( !t || *t != *s )
    {
      ++fail;
      printf( "test '%s' failed:\n%s\n%s\n", name.c_str(), t->xml().c_str(), s->xml().c_str() );
    }
    delete s;
    delete t;
    t = 0;
  }

  StanzaExtensionFactory sef;
  sef.registerExtension( new SIManager::SI() );
  // -------
  {
    name = "SIManager::SI/SEFactory test";
    Tag* f = new Tag( "iq" );
    new Tag( f, "si", "xmlns", XMLNS_SI );
    IQ iq( IQ::Set, JID(), "" );
    sef.addExtensions( iq, f );
    const SIManager::SI* se = iq.findExtension<SIManager::SI>( ExtSI );
    if( se == 0 )
    {
      ++fail;
      printf( "test '%s' failed\n", name.c_str() );
    }
    delete f;
  }


  printf( "SIManager::SI: " );
  if( fail == 0 )
  {
    printf( "OK\n" );
    return 0;
  }
  else
  {
    printf( "%d test(s) failed\n", fail );
    return 1;
  }

}
Пример #4
0
  void SIProfileFT::handleSIRequest( const JID& from, const std::string& id,
                                     const SIManager::SI& si )
  {
    if( si.profile() != XMLNS_SI_FT || !si.tag1() )
      return;

    if( m_handler )
    {
      long offset = 0;
      long length = -1;

      const Tag* t = si.tag1()->findChild( "desc" );
      const std::string& desc = t ? t->cdata() : EmptyString;

      if( ( t = si.tag1()->findChild( "range" ) ) )
      {
        if( t->hasAttribute( "offset" ) )
          offset = atol( t->findAttribute( "offset" ).c_str() );
        if( t->hasAttribute( "length" ) )
          length = atol( t->findAttribute( "length" ).c_str() );
      }

      const std::string& mt = si.mimetype();
      int types = 0;

      if( si.tag2() )
      {
        const DataForm df( si.tag2()->findChild( "x", XMLNS, XMLNS_X_DATA ) );
        const DataFormField* dff = df.field( "stream-method" );

        if( dff )
        {
          if( dff->value() == XMLNS_BYTESTREAMS )
            types |= FTTypeS5B;
          else if( dff->value() == XMLNS_IBB )
            types |= FTTypeIBB;
          else if( dff->value() == XMLNS_IQ_OOB )
            types |= FTTypeOOB;
        }
      }

      const std::string& sid = si.id();
      m_id2sid[sid] = id;
      m_handler->handleFTRequest( from, sid, si.tag1()->findAttribute( "name" ),
                                  atol( si.tag1()->findAttribute( "size" ).c_str() ),
                                        si.tag1()->findAttribute( "hash" ),
                                            si.tag1()->findAttribute( "date" ),
                                  mt.empty() ? "binary/octet-stream" : mt,
                                  desc, types, offset, length );
    }
  }