예제 #1
0
 public new static bool TryParse(Frame parentFrame, int packetStartIndex, int packetEndIndex, out AbstractPacket result)
 {
     /**
      *  The control file must be an ASCII stream with the ends of lines
      *  indicated by ASCII LF.
      *  [...]
      *  Once all of the contents have
      *  been delivered, an octet of zero bits is sent as an indication that
      *  the file being sent is complete.
      */
     result = null;
     if (parentFrame.Data[packetEndIndex] != 0x00)
     {
         return(false);
     }
     if (packetEndIndex > packetStartIndex && parentFrame.Data[packetEndIndex - 1] != 0x0a)
     {
         return(false);
     }
     for (int i = packetStartIndex; i < packetEndIndex - 1; i++)
     {
         if (parentFrame.Data[i] > 126)
         {
             return(false);
         }
         if (parentFrame.Data[i] != 0x0a && char.IsControl((char)parentFrame.Data[i]) && !WHITE_SPACE_CHARS.Contains((char)parentFrame.Data[i]))
         {
             return(false);
         }
     }
     try {
         result = new LpdControlFilePacket(parentFrame, packetStartIndex, packetEndIndex);
         return(true);
     }
     catch {
         return(false);
     }
 }
예제 #2
0
 public static bool TryParse(Frame parentFrame, int packetStartIndex, int packetEndIndex, bool clientToServer, out AbstractPacket result)
 {
     result = null;
     try {
         if (clientToServer)
         {
             if (LpdRequestPacket.TryParseCommandLine(parentFrame.Data, packetStartIndex, packetEndIndex, out _, out _, out _))
             {
                 result = new LpdRequestPacket(parentFrame, packetStartIndex, packetEndIndex);
             }
             else
             {
                 return(LpdControlFilePacket.TryParse(parentFrame, packetStartIndex, packetEndIndex, out result));
             }
         }
         else if (packetStartIndex == packetEndIndex)
         {
             result = new LpdResponsePacket(parentFrame, packetStartIndex);
         }
     }
     catch { }
     return(result != null);
 }