virtual int set(const char *pcszAdapter, const char *pcszAddress, const char *pcszNetmask = 0)
     {
         const char *pcszFamily = isAddrV6(pcszAddress) ? "inet6" : "inet";
         if (execute(CmdList(pcszAdapter) << pcszFamily))
             execute(CmdList(pcszAdapter) << pcszFamily << "plumb" << "up");
         return CmdIfconfig::set(pcszAdapter, pcszAddress, pcszNetmask);
     };
 virtual int addV4(const char *pcszAdapter, const char *pcszAddress, const char *pcszNetmask = 0)
     {
         AddressIPv4 addr(pcszAddress, pcszNetmask);
         bringUp(pcszAdapter);
         return execute(CmdList("addr") << "add" << addr.getAddressAndMask() <<
                        "broadcast" << addr.getBroadcast() << "dev" << pcszAdapter);
     };
Пример #3
0
oexBOOL CVfsFtpSession::OnRead( oexINT x_nErr )
{
    // Process the incomming data
    if ( !TBufferedPort< CAutoSocket >::OnRead( x_nErr ) )
	    return oexFALSE;

    // Grab the data
    CStr8 sData = Rx().Read();

    // First token should be the command
    CStr8 sCmd = sData.ParseNextToken().ToUpper();

    // USER
    if ( sCmd == "USER" )
    {   m_sUser = sData.ParseNextToken();
        Write( CStr8( "331 Password required for " ) << m_sUser << ".\n" );
    } // end if

    // PASS
    else if ( sCmd == "PASS" )
    {   m_sPassword = sData.ParseNextToken();
        Write( CStr8( "230 User \'" ) << m_sUser << "\' logged in at " << oexStrToStr8( CSysTime( 2 ).FormatTime( oexT( "GMT : %Y/%c/%d - %g:%m:%s.%l" ) ) ) << ".\n" );
    } // end else if

    // SYST
    else if ( sCmd == "SYST" )
        Write( "215 Windows_NT\n" );

    // PWD
    else if ( sCmd == "PWD" )
    {   if ( !m_sCurrent.Length() )
            m_sCurrent = "/";
        Write( CStr8( "257 \"" ) << m_sCurrent << "\" is current directory.\n" );
    } // end else if

    // CWD
    else if ( sCmd == "CWD" )
    {   sData = sData.TrimWhiteSpace();
        if ( *sData != '/' && *sData != '\\' )
            sData = CStr8::BuildPath( m_sCurrent, sData );
        m_sCurrent = sData;
        Write( "250 CWD command successful.\n" );
    } // end else if

    // MKD
    else if ( sCmd == "MKD" )
    {   sData = sData.TrimWhiteSpace();
        if ( *sData != '/' && *sData != '\\' )
            sData = CStr8::BuildPath( m_sCurrent, sData );
        m_vfs.MakeFolder( CStr8::BuildPath( m_sRoot, sData ).Ptr() );
        Write( "250 MKD command successful.\n" );
    } // end else if

    // RMD
    else if ( sCmd == "RMD" )
    {   sData = sData.TrimWhiteSpace();
        if ( *sData != '/' && *sData != '\\' )
            sData = CStr8::BuildPath( m_sCurrent, sData );
        m_vfs.Delete( CStr8::BuildPath( m_sRoot, sData ).Ptr() );
        Write( "250 RMD command successful.\n" );
    } // end else if

    // CDUP
    else if ( sCmd == "CDUP" )
    {   m_sCurrent.RParse( "/\\" );
        Write( "250 CDUP command successful.\n" );
    } // end else if

    // NOOP
    else if ( sCmd == "NOOP" )
        Write( "200 Ok.\n" );

    // NOOP
    else if ( sCmd == "REST" )
    {   m_nsData.Destroy();
        Write( "200 Ok.\n" );
    } // end else if

    // PASV
    else if ( sCmd == "PASV" )
        CmdPasv();

    // TYPE
    else if ( sCmd == "TYPE" )
    {   m_sType = sData.ParseNextToken();
        Write( CStr8( "200 Type set to " ) << m_sType << ".\n" );
    } // end else if

    // LIST
    else if ( sCmd == "LIST" )
        CmdList();

    // RETR
    else if ( sCmd == "RETR" )
        CmdRetr( sData.TrimWhiteSpace().Ptr() );

    // STOR
    else if ( sCmd == "STOR" )
        CmdStor( sData.TrimWhiteSpace().Ptr() );

    // DELE
    else if ( sCmd == "DELE" )
    {   sData = sData.TrimWhiteSpace();
        if ( *sData != '/' && *sData != '\\' )
            sData = CStr8::BuildPath( m_sCurrent, sData );
        m_vfs.Delete( CStr8::BuildPath( m_sRoot, sData ).Ptr() );
        Write( "250 DELE command successful.\n" );
    } // end if

    // QUIT
    else if ( sCmd == "QUIT" )
    {   Write( "221 Goodbye.\n" );
        CloseSession();
    }

    // Error...
    else
        Write( CStr8( "500 \'" ) << sCmd << "\': Huh?\n" );

    return oexTRUE;
}
 /** Brings up the adapter */
 void bringUp(const char *pcszAdapter)
     { execute(CmdList("link") << "set" << "dev" << pcszAdapter << "up"); };
 virtual CmdList getShowCommand(const char *pcszAdapter) const
     { return CmdList("addr") << "show" << "dev" << pcszAdapter; };
 virtual int addV6(const char *pcszAdapter, const char *pcszAddress, const char *pcszNetmask = 0)
     {
         bringUp(pcszAdapter);
         return execute(CmdList("addr") << "add" << pcszAddress << "dev" << pcszAdapter);
         NOREF(pcszNetmask);
     };
 /**
  * IPv4 and IPv6 syntax is the same, so we override `remove` instead of implementing
  * family-specific commands. It would be easier to use the same body in both
  * 'removeV4' and 'removeV6', so we override 'remove' to illustrate how to do common
  * implementation.
  */
 virtual int remove(const char *pcszAdapter, const char *pcszAddress)
     { return execute(CmdList("addr") << "del" << pcszAddress << "dev" << pcszAdapter); };
 /* We can umplumb IPv4 interfaces only! */
 virtual int removeV4(const char *pcszAdapter, const char *pcszAddress)
     {
         int rc = CmdIfconfig::removeV4(pcszAdapter, pcszAddress);
         execute(CmdList(pcszAdapter) << "inet" << "unplumb");
         return rc;
     };
 virtual int removeV4(const char *pcszAdapter, const char *pcszAddress)
     { return execute(CmdList(pcszAdapter) << "0.0.0.0"); NOREF(pcszAddress); };
 virtual int removeV6(const char *pcszAdapter, const char *pcszAddress)
     { return execute(CmdList(pcszAdapter) << "inet6" << delCmdArg() << pcszAddress); };
 virtual int setV4(const char *pcszAdapter, const char *pcszAddress, const char *pcszNetmask = 0)
     {
         if (!pcszNetmask)
             return execute(CmdList(pcszAdapter) << pcszAddress);
         return execute(CmdList(pcszAdapter) << pcszAddress << "netmask" << pcszNetmask);
     };
 virtual int addV6(const char *pcszAdapter, const char *pcszAddress, const char *pcszNetmask = 0)
     {
         return execute(CmdList(pcszAdapter) << "inet6" << addCmdArg() << pcszAddress);
         NOREF(pcszNetmask);
     };
 virtual CmdList getShowCommand(const char *pcszAdapter) const
     { return CmdList(pcszAdapter); };