Exemplo n.º 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 );
    }
  }
Exemplo n.º 2
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 );
    }
  }