Esempio n. 1
0
oexBOOL CCircBuf::Peek( CStr8 &x_sStr, t_size x_uMax )
{
	// Lock the buffer
	oexAutoLock ll( &m_lock );
	if ( !ll.IsLocked() )
        return oexFALSE;

    // Zero means all of it
    if ( !x_uMax )
        x_uMax = GetMaxRead();

    // Anything to read?
    if ( !x_uMax )
        return oexFALSE;

    // Allocate memory
    if ( !x_sStr.OexAllocate( x_uMax ) )
        return oexFALSE;

	t_size uRead = 0;

	// Read the string from the buffer
	Peek( x_sStr._Ptr(), x_uMax, &uRead );

    // Ensure didn't read more than we should have
    oexASSERT( x_uMax >= uRead );

    // Don't assume it's NULL terminated
    x_sStr.SetLength( uRead );

    return oexTRUE;
}
Esempio n. 2
0
int CSys::vPrint( oexCSTR8 x_pFmt, oexVaList pArgs )
{   //_STT();
    CStr8 s;
    s.vFmt( x_pFmt, pArgs );
    Echo( s.Ptr() );
    return s.Length();
}
Esempio n. 3
0
int CSys::Print( oexCSTR8 x_pFmt, ... )
{   //_STT();
    CStr8 s;
    oexVaList ap;
    oexVaStart( ap, x_pFmt );
    s.vFmt( x_pFmt, (va_list)ap );
    oexVaEnd( ap );
    Echo( s.Ptr() );
    return s.Length();
}
Esempio n. 4
0
int CSys::Echo( oexCSTRW x_pFmt )
{//_STT();
	if ( !x_pFmt )
		return 0;
	CStr8 s = oexStrWToStr( x_pFmt );
#if defined( oexUNICODE )
	CUtil::AddOutput( x_pFmt, s.Length(), oexTRUE );
#else
	CUtil::AddOutput( s.Ptr(), s.Length(), oexTRUE );
#endif
	return ::puts( s.Ptr() );
}
Esempio n. 5
0
void CConsole::SaveHistory()
{
	WriteBuffer buffer;
	const int linesToSkip = (int)m_deqBufHistory.size() - m_MaxHistoryLines;
	std::deque<std::wstring>::reverse_iterator it = m_deqBufHistory.rbegin();
	if(linesToSkip > 0)
		std::advance(it, linesToSkip);
	for (; it != m_deqBufHistory.rend(); ++it)
	{
		CStr8 line = CStrW(*it).ToUTF8();
		buffer.Append(line.data(), line.length());
		static const char newline = '\n';
		buffer.Append(&newline, 1);
	}
	g_VFS->CreateFile(m_sHistoryFile, buffer.Data(), buffer.Size());
}
Esempio n. 6
0
oexBOOL CVfsFtpSession::CmdPasv()
{
    oexBOOL bStarted = oexFALSE;

    // Loop through port numbers
    if ( m_uPasvPort >= 3900 )
        m_uPasvPort = 3110;

    while ( m_uPasvPort < 4000 && !bStarted )
    {
        // Next port
        m_uPasvPort++;

        // Ensure the thread is running
        if ( !m_nsData.IsRunning() )
            m_nsData.Start();

        // Reset server
        m_nsData.Queue( 0, oexCall( oexT( "Reset" ) ) );

        // Bind to port
        if ( m_nsData.Queue( 0, oexCall( oexT( "Bind" ), m_uPasvPort ) )
                .Wait( oexDEFAULT_TIMEOUT ).GetReply().ToInt()

             && m_nsData.Queue( 0, oexCall( oexT( "Listen" ), 0 ) )
                .Wait( oexDEFAULT_TIMEOUT ).GetReply().ToInt() )

            bStarted = oexTRUE;

    } // end while

    // Did we get a server?
    if ( bStarted )
    {
        // Tell the client where the server is
        CStr8 sAddress = oexStrToStr8( LocalAddress().GetDotAddress().Replace( '.', ',' ) );
        Write( CStr8().Fmt( "227 Entering Passive Mode (%s,%u,%u).\n",
                            sAddress.Ptr(), m_uPasvPort >> 8 & 0xff, m_uPasvPort & 0xff ) );
    } // end if

    else
Esempio n. 7
0
CStr8 CIpSocket::Recv( oexUINT x_uMax, oexUINT x_uFlags )
{
    // Do we have a size limit?
    if ( x_uMax )
    {
        // Allocate buffer
        CStr8 sBuf;
        sBuf.Allocate( x_uMax );

        // Attempt to read data
        oexUINT uRead = Recv( sBuf._Ptr(), x_uMax, oexNULL, x_uFlags );

        // Accept as the length
        sBuf.SetLength( uRead );

        return sBuf;

    } // end if

    // Allocate buffer
    CStr8 sBuf;
    oexUINT uRead = 0, uOffset = 0;

    // Allocate space
    if ( !sBuf.OexAllocate( oexSTRSIZE ) )
        return sBuf;

    // Read all available data
    while ( 0 < ( uRead = Recv( sBuf._Ptr( uOffset ), oexSTRSIZE, oexNULL, x_uFlags ) )
            && (oexINT)uRead >= oexSTRSIZE )
    {
		if ( (oexINT)uRead > oexSTRSIZE )
			uRead = oexSTRSIZE;

        // Allocate more space
        uOffset += uRead;
        if ( !sBuf.Allocate( uOffset + oexSTRSIZE ) )
            return sBuf;

    } // end while

    // Set the length
    sBuf.SetLength( uOffset + uRead );

    return sBuf;
}
Esempio n. 8
0
CStr8 CSerialPort::Read( oexSIZE_T x_nSize )
{_STT();
	SSerialPortSettings *pS = (SSerialPortSettings*)m_pSettings;
	if ( !pS || 0 > pS->fd )
		return CStr8();
	
	CStr8 s;
	oexSTR8 p = s.Allocate( x_nSize );
	if ( !p )
		return CStr8();

	// Attempt to read data from port
	int nRead = read( pS->fd, p, x_nSize );
	if ( 0 > nRead )
	{	m_nError = errno;
		return CStr8();
	} // end if

	// How many bytes did we read?
	s.SetLength( nRead );

	return s;
}
Esempio n. 9
0
PSRETURN IGUIObject::LogInvalidSettings(const CStr8& Setting) const
{
	LOGWARNING("IGUIObject: setting %s was not found on an object",
		Setting.c_str());
	return PSRETURN_GUI_InvalidSetting;
}
Esempio n. 10
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;
}
Esempio n. 11
0
CStr CBaseFile::GetSysFolder( oexBOOL x_bShared, oexINT x_nFolderId, oexINT x_nMaxLength )
{
	// Get the folder
	switch( x_nFolderId )
	{
		case eFidNone :
			break;

		case eFidTemp :
		{
			const char *pTmp;
			if ( !( pTmp = getenv( "TMPDIR" ) ) 
				 && !( pTmp = getenv( "TEMP" ) )
				 && !( pTmp = getenv( "TMP" ) ) 
			   )
				return oexT( "/tmp" );

			return oexMbToStr( pTmp );

		} break;

		case eFidSystem :
			return CBaseFile_GetHome();

		case eFidUserOs :
			return oexT( "/sys" );

		case eFidCurrent :
		{
			// Ask for the current working directory
			CStr8 s;
			char *cwd = s.Allocate( oexSTRSIZE );
			if ( !cwd || !getcwd( cwd, oexSTRSIZE ) || !*cwd )
				s.Destroy();

			return s;

		} break;

		case eFidRoot :
		case eFidDefDrive :
			return oexT( "/" );

		case eFidFonts :
			return oexT( "/usr/share/fonts/truetype/msttcorefonts" );

		case eFidSettings :
			if ( x_bShared )
				return oexT( "/var/lib" );
			return oexBuildPath( CBaseFile_GetHome(), oexT( ".config" ) );

		case eFidDesktop :
			return oexBuildPath( CBaseFile_GetHome(), oexT( "Desktop" ) );

		case eFidDownloads :
			return oexBuildPath( CBaseFile_GetHome(), oexT( "Downloads" ) );

		case eFidTemplates :
			return oexBuildPath( CBaseFile_GetHome(), oexT( "Templates" ) );

		case eFidPublic :
			return oexBuildPath( CBaseFile_GetHome(), oexT( "Public" ) );

		case eFidDocuments :
			return oexBuildPath( CBaseFile_GetHome(), oexT( "Documents" ) );

		case eFidMusic :
			return oexBuildPath( CBaseFile_GetHome(), oexT( "Music" ) );

		case eFidPictures :
			return oexBuildPath( CBaseFile_GetHome(), oexT( "Pictures" ) );

		case eFidVideo :
			return oexBuildPath( CBaseFile_GetHome(), oexT( "Videos" ) );

		default :
			break;

	} // end switch

	return oexT( "" );
}