コード例 #1
0
        /// <summary>
        /// construct an OptionVariable starting at the next byte in the input array.
        /// </summary>
        /// <param name="ByteArray"></param>
        /// <returns></returns>
        public static OptionVariable Construct(InputByteArray InputArray)
        {
            OptionVariable optnVar = null;

            if (InputArray.IsEof() == false)
            {
                var b1 = InputArray.PeekNextByte();
                var ev = b1.ToEnvironVarCode();
                if (ev != null)
                {
                    var varCode = ev.Value;
                    if ((varCode == EnvironVarCode.VAR) || (varCode == EnvironVarCode.USERVAR))
                    {
                        byte[] valueBytes = null;
                        bool   gotValue   = false;

                        // advance past the VAR or USERVAR code.
                        InputArray.GetNextByte();

                        // isolate the name text which follows the VAR or USERVAR code.
                        // ( return the stop code. But do not consume it. )
                        var rv = InputArray.GetBytesUntilCode(
                            new byte[] { 0xff, 0x00, 0x01, 0x02, 0x03 });
                        var nameBytes    = rv.Item1;
                        var endAccumCode = rv.Item2.ToEnvironVarCode();

                        // the name text ends with VALUE marker. The text that follows is the text value
                        // of the variable.
                        if ((endAccumCode != null) && (endAccumCode.Value == EnvironVarCode.VALUE))
                        {
                            gotValue = true;

                            // advance past the VALUE var code.
                            InputArray.GetNextByte();

                            // get the value bytes until end of value code.
                            var rv2 = InputArray.GetBytesUntilCode(
                                new byte[] { 0xff, 0x00, 0x01, 0x02, 0x03 });
                            valueBytes = rv2.Item1;
                        }

                        optnVar = new OptionVariable(varCode, nameBytes, valueBytes);
                        if (gotValue == true)
                        {
                            optnVar.ValueEmpty = true;
                        }
                    }
                }
            }

            return(optnVar);
        }
コード例 #2
0
        public TerminalTypeCommand(InputByteArray InputArray, CommandCode CmdCode)
            : base(InputArray, CmdCode, TelnetSubject.TerminalType)
        {
            this.SubOption = null;
            this.EndFound  = false;

            // statement contains additional parameters.
            if (this.CmdCode == CommandCode.SB)
            {
                var b1 = InputArray.GetNextByte();
                this.SubOption = b1.ToTelnetOptionParm();
                this.RawBytes.Append(b1);

                if ((this.SubOption != null) &&
                    (this.SubOption.Value == TelnetOptionParm.IS))
                {
                    var rv = InputArray.GetBytesUntilCode(new byte[] { 0xff });
                    this.TerminalNameBytes = rv.Item1;
                    this.RawBytes.Append(this.TerminalNameBytes);
                }

                // parse the closing IAC SE
                ParseClosingSE(InputArray);
            }
        }
コード例 #3
0
 /// <summary>
 /// get the next byte from the input array if the command has an option.
 /// </summary>
 /// <param name="Code"></param>
 /// <param name="ByteArray"></param>
 /// <returns></returns>
 public static SubjectByte GetOptionByte(
     this CommandCode Code, InputByteArray ByteArray)
 {
     if (ByteArray.RemainingLength == 0)
     {
         return(null);
     }
     else if ((Code == CommandCode.SB) || (Code == CommandCode.WILL) ||
              (Code == CommandCode.WONT) || (Code == CommandCode.DO) ||
              (Code == CommandCode.DONT))
     {
         var b1 = ByteArray.GetNextByte();
         return(new SubjectByte(b1));
     }
     else
     {
         return(null);
     }
 }
コード例 #4
0
        public NewEnvironCommand(InputByteArray InputArray, CommandCode CmdCode)
            : base(InputArray, CmdCode, TelnetSubject.NEW_ENVIRON)
        {
            this.SubOption  = null;
            this.OptionList = new List <OptionVariable>();
            this.EndFound   = false;

            // statement contains additional parameters.
            if (this.CmdCode == CommandCode.SB)
            {
                var b1 = InputArray.GetNextByte();
                this.RawBytes.Append(b1);
                this.SubOption = b1.ToTelnetOptionParm(); // IS, SEND, INFO

                // list of VARs and USERVARS follow until IAC SE.
                if ((this.SubOption.Value == TelnetOptionParm.SEND) ||
                    (this.SubOption.Value == TelnetOptionParm.IS))
                {
                    while (true)
                    {
                        var ov = OptionVariable.Construct(InputArray);
                        if (ov == null)
                        {
                            break;
                        }
                        this.OptionList.Add(ov);
                        this.RawBytes.Append(ov.ToBytes());
                    }

                    if (InputArray.PeekIacSe())
                    {
                        this.EndFound = true;
                        this.RawBytes.Append(InputArray.GetBytes(2));
                    }
                }

                // parse the closing IAC SE
                ParseClosingSE(InputArray);
            }
        }