Beispiel #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);
        }
Beispiel #2
0
        public static Tuple <TerminalVt100Statement, Vt100OutputText> Factory(
            InputByteArray InputArray)
        {
            TerminalVt100Statement stmt   = null;
            Vt100OutputText        otStmt = null;

            var          escapeCmd = InputArray.PeekNextByte().ToTelnetCommand();
            Vt100Command?cmd       = null;

            if ((escapeCmd != null) && (escapeCmd.Value == TelnetCommand.ESCAPE) &&
                (InputArray.RemainingLength > 1))
            {
                InputArray.AdvanceIndex(1);
                var rv  = InputArray.GetBytesUntilCode(new byte[] { 0x1b });
                var buf = rv.Item1;
                int rx  = 0;

                var stmtText = buf.ToAscii();

                stmt = Factory_FromStmtText(stmtText);

                // process any output text that follows the stmt text.
                {
                    int lx = stmt.StmtText.Length;
                    if (stmtText.Length > lx)
                    {
                        stmtText = stmtText.Substring(lx);
                        otStmt   = new Vt100OutputText(stmtText);
                    }
                }
            }

            return(new Tuple <TerminalVt100Statement, Vt100OutputText>(stmt, otStmt));
        }
        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);
            }
        }