Beispiel #1
0
        public TelnetSymbol(TelnetCommands myCommand, TelnetOptions myOption)
        {
            _Command = myCommand;
            _Option  = myOption;

            _TelnetSymbolType = TelnetSymbolTypes.Command;
        }
Beispiel #2
0
        public TelnetSymbol(TelnetCommands myCommand, TelnetOptions myOption)
        {
            _Command = myCommand;
            _Option = myOption;

            _TelnetSymbolType = TelnetSymbolTypes.Command;
        }
Beispiel #3
0
 public TelnetSymbol(Byte[] myDataBytes)
 {
     _Data             = myDataBytes;
     _TelnetSymbolType = TelnetSymbolTypes.Data;
 }
Beispiel #4
0
 public TelnetSymbol(TelnetCommands myCommand)
 {
     _Command          = myCommand;
     _TelnetSymbolType = TelnetSymbolTypes.Command;
 }
Beispiel #5
0
        public Boolean Parse(Byte[] myBytes)
        {
            //List<TelnetSymbol> resolvedSymbols = new List<TelnetSymbol>();
            TelnetSymbolTypes lastByteType        = TelnetSymbolTypes.Unknown;
            List <Byte>       dataBytes           = new List <byte>();
            List <Byte>       subnegotiationBytes = new List <byte>();

            for (Int32 i = 0; i < myBytes.Length; i++)
            {
                //As required by the Telnet protocol, any occurrence of 255 in the subnegotiation must be doubled to distinguish it from the IAC character (which has a value of 255)
                if (myBytes[i] == (Byte)TelnetCommands.Iac || lastByteType == TelnetSymbolTypes.Subnegotiation)
                {
                    if (lastByteType == TelnetSymbolTypes.Data)
                    {
                        HandleData(dataBytes.ToArray());
                        HandleKeys(dataBytes.ToArray());
                        dataBytes.Clear();
                    }

                    #region Read the next command or subnegotiation data

                    TelnetCommands command;
                    if (lastByteType == TelnetSymbolTypes.Subnegotiation)
                    {
                        command = (TelnetCommands)myBytes[i];
                    }
                    else
                    {
                        command = (TelnetCommands)myBytes[++i];
                    }

                    if (lastByteType == TelnetSymbolTypes.Subnegotiation)
                    {
                        if (command != TelnetCommands.Iac || myBytes[i + 1] != (Byte)TelnetCommands.SubnegotiationEnd)
                        {
                            Console.Write(myBytes[i] + ", ");
                            subnegotiationBytes.Add(myBytes[i]);

                            //As required by the Telnet protocol, any occurrence of 255 in the subnegotiation must be doubled to distinguish it from the IAC character (which has a value of 255)
                            if (command == TelnetCommands.Iac && i + 1 < myBytes.Length && myBytes[i + 1] == (Byte)TelnetCommands.Iac)
                            {
                                i++;
                            }

                            continue;
                        }
                        else
                        {
                            command = (TelnetCommands)myBytes[++i];
                        }
                    }

                    #endregion

                    switch (command)
                    {
                        #region Subnegotiation

                    case TelnetCommands.Subnegotiation:
                        //throw new NotImplementedException("TelnetCommands.Subnegotiation");
                        Console.WriteLine("TelnetCommands.Subnegotiation");
                        subnegotiationBytes.Clear();
                        lastByteType = TelnetSymbolTypes.Subnegotiation;
                        break;

                    case TelnetCommands.SubnegotiationEnd:
                        //throw new NotImplementedException("TelnetCommands.SubnegotiationEnd");
                        Console.WriteLine("TelnetCommands.SubnegotiationEnd");
                        HandleSubnegotiation(subnegotiationBytes.ToArray());
                        lastByteType = TelnetSymbolTypes.Unknown;
                        break;

                        #endregion

                        #region Simple commands without option

                    case TelnetCommands.NoOperation:
                    case TelnetCommands.DataMark:
                    case TelnetCommands.Break:
                    case TelnetCommands.InterruptProcess:
                    case TelnetCommands.AbortOutput:
                    case TelnetCommands.AreYouThere:
                    case TelnetCommands.EraseCharacter:
                    case TelnetCommands.EraseLine:
                    case TelnetCommands.GoAhead:
                        //resolvedSymbols.Add(new TelnetSymbol(command));
                        lastByteType = TelnetSymbolTypes.Command;
                        HandleTelnetCommand(new TelnetSymbol(command));
                        break;

                        #endregion

                        #region Option commands

                    case TelnetCommands.Will:
                    case TelnetCommands.Wont:
                    case TelnetCommands.Do:
                    case TelnetCommands.Dont:
                        TelnetOptions option = (TelnetOptions)myBytes[++i];
                        //resolvedSymbols.Add(new TelnetSymbol(command, option));
                        lastByteType = TelnetSymbolTypes.Command;
                        HandleTelnetOption(new TelnetSymbol(command, option));
                        break;

                        #endregion

                    default:
                        throw new NotSupportedException("Not supported command: " + command);
                    }
                }
                else
                {
                    lastByteType = TelnetSymbolTypes.Data;
                    //if (myBytes[i] != (Byte)ASCIIControlCodes.CR && myBytes[i] != (Byte)ASCIIControlCodes.LF)
                    dataBytes.Add(myBytes[i]);
                }
            }

            if (lastByteType == TelnetSymbolTypes.Data && dataBytes.Count > 0)
            {
                HandleData(dataBytes.ToArray());
                HandleKeys(dataBytes.ToArray());
            }

            return(true);
        }
Beispiel #6
0
 public TelnetSymbol(Byte[] myDataBytes)
 {
     _Data = myDataBytes;
     _TelnetSymbolType = TelnetSymbolTypes.Data;
 }
Beispiel #7
0
 public TelnetSymbol(TelnetCommands myCommand)
 {
     _Command = myCommand;
     _TelnetSymbolType = TelnetSymbolTypes.Command;
 }