// EndTemp /// <summary> /// parse the byte array as a data stream containing a sequence of SCS control /// functions. ( text data is a /// </summary> /// <param name="InputArray"></param> /// <returns></returns> public static Tuple <ControlFunctionList, string> ParseDataStream(InputByteArray InputArray) { ControlFunctionList funcList = null; string errmsg = null; while (InputArray.IsEof() == false) { // check for IAC EOR var telCode = InputArray.PeekTelnetCommandCode(CommandCode.EOR); if (telCode != null) { break; } var func = ControlFunction.Factory(InputArray); if ((func == null) || (func.Errmsg != null)) { errmsg = "invalid control function. Postion:" + InputArray.Index + " invalid bytes:" + InputArray.PeekToEnd().Head(16).ToHex(' '); break; } if (funcList == null) { funcList = new ControlFunctionList(); } funcList.Add(func); } return(new Tuple <ControlFunctionList, string>(funcList, errmsg)); }
/// <summary> /// expecting closing IAC SE command code. If exists at current position of the /// input array, process the IAC SE command. /// </summary> /// <param name="InputArray"></param> protected void ParseClosingSE(InputByteArray InputArray) { // parse the closing IAC SE var seCode = InputArray.PeekTelnetCommandCode(CommandCode.SE); if (seCode != null) { this.GotClosingSE = true; this.RawBytes.Append(InputArray.GetBytes(2)); } }
/// <summary> /// peek at current bytes of input array for a specific telnet command code. /// </summary> /// <param name="InputArray"></param> /// <param name="CmdCode"></param> /// <returns></returns> public static CommandCode?PeekTelnetCommandCode( this InputByteArray InputArray, CommandCode CmdCode) { var cmdCode = InputArray.PeekTelnetCommandCode(); if ((cmdCode != null) && (cmdCode.Value != CmdCode)) { cmdCode = null; } return(cmdCode); }
/// <summary> /// read next Telnet command byte sequence from the input byte array. /// </summary> /// <param name="InputArray"></param> /// <returns></returns> public static TelnetCommand NextTelnetCommand( this InputByteArray InputArray) { TelnetCommand cmd = null; var code = InputArray.PeekTelnetCommandCode( ); if (code != null) { cmd = TelnetCommand.Factory(InputArray, code.Value); } return(cmd); }
/// <summary> /// look at the current bytes of the input array. Determine what type of data /// stream command is starting. /// </summary> /// <param name="InputArray"></param> /// <returns></returns> public static TypeServerData?PeekServerCommand( InputByteArray InputArray) { TypeServerData?typeData = null; if (InputArray.IsEof() == true) { typeData = TypeServerData.eof; } else if (InputArray.PeekTelnetCommandCode() != null) { typeData = TypeServerData.telnetCommand; } else if (InputArray.IsDataStreamHeader() == true) { typeData = TypeServerData.workstationHeader; } return(typeData); }
ParseWorkstationCommandList( InputByteArray InputArray, SessionSettings SessionSettings) { var wrkstnCmdList = new WorkstationCommandList(); DataStreamHeader dsh = null; bool gotEOR = false; bool needMoreBytes = false; string errmsg = null; if (InputArray.IsDataStreamHeader()) { var rv = DataStreamHeader.Factory(InputArray); dsh = rv.Item1; errmsg = rv.Item2; } bool lastCmdWasTelnet_EOR = false; bool gotWorkstationCommand = true; gotEOR = false; while ((InputArray.IsEof( ) == false) && (gotEOR == false) && (gotWorkstationCommand == true)) { // no input data to process. lastCmdWasTelnet_EOR = false; gotWorkstationCommand = false; // check for IAC EOR var telCode = InputArray.PeekTelnetCommandCode(CommandCode.EOR); if (telCode != null) { var telCmd = InputArray.NextTelnetCommand(); lastCmdWasTelnet_EOR = true; gotEOR = true; } // process the input as workstation data stream commands. else { var rv = ParseAndProcessWorkstationCommand(InputArray); var workstationCommand = rv.Item1; var howRead = rv.Item2; if (workstationCommand != null) { wrkstnCmdList.Add(workstationCommand); gotWorkstationCommand = true; } } } // read available bytes from input stream. if (InputArray.IsEof() && (lastCmdWasTelnet_EOR == false)) { needMoreBytes = true; } return(new Tuple <DataStreamHeader, WorkstationCommandList, bool, bool>( dsh, wrkstnCmdList, gotEOR, needMoreBytes)); }