Exemple #1
0
static int teel_reader(void* ud)
{
  TelnetState* ts = (TelnetState*) ud;
  int val = -1;
  ReadBuffer* input = &ts->in;
  do
  {
    ReadMark(input);
    CHECK_BREAK(val = ReadByte(input));

    if (val == IAC)
    {
      CHECK_BREAK(val = ReadByte(input));

      if (val >= WILL && val <= DONT)
      {
        int opt;
        CHECK_BREAK(opt = ReadByte(input));
        parseoption(ts, val, opt);
      }
      else if (val == SB)
      {
        int sopt;
        CHECK_BREAK(sopt = ReadByte(input));
        parsesuboption(ts, sopt, input);
      }
      else if (val == IP)
      {
        val = 3;
        break;
      }
      else if (val == SUSP)
      {
        val = 26;
        break;
      }
      else if (val == EOF_)
      {
        val = 4;
        break;
      }
      else if (val == IAC) // escape code
      {
        val = 255;
        break;
      }
      else
        printf("Telnet interpreter: unknown character code: 255, %d. Skipping it...\n", val);
    }
    else // standard char...
      break;
  } while (1);

  ReadMark(input);
  return val;
}
Exemple #2
0
// parse comment
void minipoint::parsecomment(minipointdata *point)
   {
   lunascan scanner;

   scanner.addtoken("$",minipointopts::OPTION_DELIMITER);

   scanner.addtoken("=",minipointopts::OPTION_EQ);
   scanner.addtoken(":=",minipointopts::OPTION_EQ);

   scanner.addtoken("type",minipointopts::OPTION_TYPE);

   scanner.addtoken("signpostsize",minipointopts::OPTION_SIGNPOSTSIZE);
   scanner.addtoken("signpostheight",minipointopts::OPTION_SIGNPOSTHEIGHT);
   scanner.addtoken("signpostnoauto",minipointopts::OPTION_SIGNPOSTNOAUTO);
   scanner.addtoken("signpostturn",minipointopts::OPTION_SIGNPOSTTURN);
   scanner.addtoken("signpostincline",minipointopts::OPTION_SIGNPOSTINCLINE);
   scanner.addtoken("signpostalpha",minipointopts::OPTION_SIGNPOSTALPHA);

   scanner.addtoken("brickfile",minipointopts::OPTION_BRICKFILE);
   scanner.addtoken("bricksize",minipointopts::OPTION_BRICKSIZE);
   scanner.addtoken("brickturn",minipointopts::OPTION_BRICKTURN);
   scanner.addtoken("brickincline",minipointopts::OPTION_BRICKINCLINE);
   scanner.addtoken("brickcolor_red",minipointopts::OPTION_BRICKCOLOR_RED);
   scanner.addtoken("brickcolor_green",minipointopts::OPTION_BRICKCOLOR_GREEN);
   scanner.addtoken("brickcolor_blue",minipointopts::OPTION_BRICKCOLOR_BLUE);
   scanner.addtoken("brickalpha",minipointopts::OPTION_BRICKALPHA);

   scanner.addtoken("datafile",minipointopts::OPTION_DATAFILE);
   scanner.addtoken("datasize",minipointopts::OPTION_DATASIZE);
   scanner.addtoken("dataturn",minipointopts::OPTION_DATATURN);
   scanner.addtoken("dataincline",minipointopts::OPTION_DATAINCLINE);
   scanner.addtoken("datacolor_red",minipointopts::OPTION_DATACOLOR_RED);
   scanner.addtoken("datacolor_green",minipointopts::OPTION_DATACOLOR_GREEN);
   scanner.addtoken("datacolor_blue",minipointopts::OPTION_DATACOLOR_BLUE);
   scanner.addtoken("dataalpha",minipointopts::OPTION_DATAALPHA);
   scanner.addtoken("dataswitch",minipointopts::OPTION_DATASWITCH);
   scanner.addtoken("datacontrol",minipointopts::OPTION_DATACONTROL);
   scanner.addtoken("datarange",minipointopts::OPTION_DATARANGE);

   scanner.setcode(point->comment);

   // options are of the form $option=value
   while (scanner.gettoken()!=lunascan::LUNA_END)
      if (scanner.gettoken()==minipointopts::OPTION_DELIMITER)
         {
         scanner.next();
         parseoption(point,&scanner);
         }
      else scanner.next();
   }
Exemple #3
0
static InterpretCommand processlinemode(TelnetState* ts)
{
  InterpretCommand cmd = IC_EOS;
  ReadBuffer* input = &ts->in;
  WriteBuffer* line = &ts->linemodebuffer;
  int val;
  while (1)
  {
    ReadMark(input);
    CHECK_BREAK(val = ReadByte(input));

    if (val == IAC)
    {
      CHECK_BREAK(val = ReadByte(input));

      if (val >= WILL && val <= DONT)
      {
        int opt;
        CHECK_BREAK(opt = ReadByte(input));
        parseoption(ts, val, opt);
      }
      else if (val == SB)
      {
        int sopt;
        CHECK_BREAK(sopt = ReadByte(input));
        parsesuboption(ts, sopt, input);
      }
      else if (val == IP)
      {
        WriteBytes(&ts->out, "\r\n", 2);
        FreeBuffer(line);
        cmd = IC_IP;
        break;
      }
      else if (val == SUSP)
      {
        WriteBytes(&ts->out, "\r\n", 2);
        FreeBuffer(line);
        cmd = IC_SUSP;
        break;
      }
      else if (val == EOF_)
      {
        if (!line->len) // only close if there the current line is empty !
        {
          cmd = IC_CLOSE;
          break;
        }
      }
      else if (val == 255)
      {
        WriteByte(line, 255);
      }
      else
      {
        printf("Telnet interpreter: unknown character code: 255, %d. Skipping it...\n", val);
      }
    }
    else if (val == 10) // New line
    {
      WriteBytes(line, "\r\n", 2); // store and echo the newline
      cmd = IC_LINE;
      break;
    }
    else if (val == 13) // CR, NULL and CR/NL is interpreted as a new line
    {
      CHECK_BREAK(val = ReadByte(input));
      if (val == 0 || val == 10)
      {
        WriteBytes(line, "\r\n", 2); // store and echo the newline
        cmd = IC_LINE;
        break;
      }
      else // false detection, just store and echo as is.
      {
        WriteByte(line, 10);
        WriteByte(line, val);
      }
    }
    else if (val == 4) // EOF the user requested to close the terminal
    {
      if (!line->len) // only close if there the current line is empty !
      {
        cmd = IC_CLOSE;
        break;
      }
    }
    else if (val == 3) // IP (equivalent to IAC IP)
    {
      WriteBytes(&ts->out, "\r\n", 2);
      FreeBuffer(line);
      cmd = IC_IP;
      break;
    }
    else if (val == 19) // IP (equivalent to IAC SUSP)
    {
      WriteBytes(&ts->out, "\r\n", 2);
      FreeBuffer(line);
      cmd = IC_SUSP;
      break;
    }
    else // other char are just stored
    {
      WriteByte(line, val);
    }
  }

  return cmd;
}