Пример #1
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 );
    }
  }
Пример #2
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() ),
                                        si.tag1()->findAttribute( "hash" ),
                                            si.tag1()->findAttribute( "date" ),
                                  mt.empty() ? "binary/octet-stream" : mt,
                                  desc, types );
    }
  }
Пример #3
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 );
            }
          }
        }
      }
    }
  }