Ejemplo n.º 1
0
        public IppResponseMessage ReadIppResponse(Stream stream)
        {
            var res = new IppResponseMessage();

            try
            {
                using var reader = new BinaryReader(stream, Encoding.ASCII, true);
                res.Version      = (IppVersion)reader.ReadInt16BigEndian();
                res.StatusCode   = (IppStatusCode)reader.ReadInt16BigEndian();
                res.RequestId    = reader.ReadInt32BigEndian();
                ReadSection(reader, res);
                return(res);
            }
            catch (Exception ex)
            {
                throw new IppResponseException(
                          $"Failed to parse ipp response. Current response parsing ended on: \n{res}", ex, res);
            }
        }
Ejemplo n.º 2
0
        private void ReadSection(BinaryReader reader, IppResponseMessage res)
        {
            IppAttribute?       prevAttribute = null;
            List <IppAttribute>?attributes    = null;

            do
            {
                var data       = reader.ReadByte();
                var sectionTag = (SectionTag)data;
                switch (sectionTag)
                {
                //https://tools.ietf.org/html/rfc8010#section-3.5.1
                case SectionTag.EndOfAttributesTag: return;

                case SectionTag.Reserved:
                case SectionTag.OperationAttributesTag:
                case SectionTag.JobAttributesTag:
                case SectionTag.PrinterAttributesTag:
                case SectionTag.UnsupportedAttributesTag:
                    var section = new IppSection {
                        Tag = sectionTag
                    };
                    res.Sections.Add(section);
                    attributes = section.Attributes;
                    break;

                default:
                    var attribute = ReadAttribute((Tag)data, reader, prevAttribute);
                    prevAttribute = attribute;
                    if (attributes == null)
                    {
                        throw new ArgumentException(
                                  $"Section start tag not found in stream. Expected < 0x06. Actual: {data}");
                    }

                    attributes.Add(attribute);

                    break;
                }
            } while (true);
        }
Ejemplo n.º 3
0
 public static IDictionary <string, IppAttribute[]> AllAttributes(this IppResponseMessage ippResponseMessage) =>
 ippResponseMessage.Sections.SelectMany(x => x.Attributes)
 .GroupBy(x => x.Name)
 .ToDictionary(g => g.Key, g => g.ToArray());
Ejemplo n.º 4
0
 public IppResponseException(IppResponseMessage responseMessage)
 {
     ResponseMessage = responseMessage;
 }
Ejemplo n.º 5
0
 public IppResponseException(string message, Exception innerException, IppResponseMessage responseMessage) :
     base(message, innerException)
 {
     ResponseMessage = responseMessage;
 }
Ejemplo n.º 6
0
 public IppResponseException(string message, IppResponseMessage responseMessage) : base(message)
 {
     ResponseMessage = responseMessage;
 }
Ejemplo n.º 7
0
 protected IppResponseException(SerializationInfo info, StreamingContext context,
                                IppResponseMessage responseMessage) : base(info, context)
 {
     ResponseMessage = responseMessage;
 }