Exemplo n.º 1
0
        /// <summary>
        /// Parses the binary data and returns an extension
        /// </summary>
        /// <param name="data">Data to parse. The data may contain multiple extensions, but only the first one is returned</param>
        /// <returns>New extension if the extension is supported</returns>
        internal ExtensionBase GetExtension(SlpReader reader)
        {
            var id = reader.ReadInt16();

            if (id < 0 || id > 0x8ff)
            {
                throw new ServiceProtocolException(ServiceErrorCode.OptionNotUnderstood, "The ID was out of the allowed range of possible values.");
            }

            if (id >= 0x400 && id < 0x800)
            {
                if (!_RegisteredExtensions.ContainsKey(id))
                {
                    throw new ServiceProtocolException(ServiceErrorCode.OptionNotUnderstood);
                }
            }

            if (!_RegisteredExtensions.ContainsKey(id))
            {
                return(null);
            }

            var result = (ExtensionBase)Services.Locator.GetInstance(_RegisteredExtensions[id]);

            return(result.Create(reader));
        }
Exemplo n.º 2
0
        public virtual AttributeCollection CreateAttributeCollection(SlpReader reader)
        {
            var tmp = reader.ReadRawString();

            var result = new AttributeCollection();

            foreach (var item in tmp.Split(','))
            {
                var    pair = item.Split('=');
                string key = null, value = null;
                if (pair.Length == 1)
                {
                    key = reader.Unescape(pair[0]);
                }
                else if (pair.Length == 2)
                {
                    key   = reader.Unescape(pair[0]);
                    value = reader.Unescape(pair[1]);
                }
                else
                {
                    throw new ServiceProtocolException(ServiceErrorCode.ParseError);
                }

                result.Add(key, value);
            }

            return(result);
        }
Exemplo n.º 3
0
        internal override void Create(SlpReader reader)
        {
            base.Create(reader);

            var tmp = reader.ReadList();
            ServiceTypes = new ReadOnlyCollection<ServiceUri>(tmp.Select(s => new ServiceUri("service:" + s)).ToArray());
        }
Exemplo n.º 4
0
        internal override void Create(SlpReader reader)
        {
            base.Create(reader);

            ErrorCode  = (ServiceErrorCode)reader.ReadInt16();
            Attributes = Services.Locator.GetInstance <AttributeCollection>(reader);
            ReadAuthBlocks(reader, AuthBlocks);
        }
Exemplo n.º 5
0
        internal override void Create(SlpReader reader)
        {
            base.Create(reader);

            Scopes.AddRange(reader.ReadList());
            Service = Services.Locator.GetInstance <ServiceEntry>(reader);
            Tags.AddRange(reader.ReadList());
        }
Exemplo n.º 6
0
        internal override void Create(SlpReader reader)
        {
            base.Create(reader);

            var tmp = reader.ReadList();

            ServiceTypes = new ReadOnlyCollection <ServiceUri>(tmp.Select(s => new ServiceUri("service:" + s)).ToArray());
        }
        internal override void Create(SlpReader reader)
        {
            base.Create(reader);

            Scopes.AddRange(reader.ReadList());
            Service = Services.Locator.GetInstance<ServiceEntry>(reader);
            Tags.AddRange(reader.ReadList());
        }
Exemplo n.º 8
0
        internal override void Create(SlpReader reader)
        {
            base.Create(reader);

            ErrorCode = (ServiceErrorCode)reader.ReadInt16();
            Attributes = Services.Locator.GetInstance<AttributeCollection>(reader);
            ReadAuthBlocks(reader, AuthBlocks);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Initalises a new extension from the received data
        /// </summary>
        /// <param name="data">byte array of data to parse</param>
        /// <returns>new UserDefined Extension</returns>
        internal override ExtensionBase Create(SlpReader reader)
        {
            var result = new UnknownExtension();
            result._Id = reader.ReadInt16();
            result.Offset = reader.ReadInt24();
            result.Data = reader.ReadBytes(result.Offset);

            return result;
        }
Exemplo n.º 10
0
        internal override void Create(SlpReader reader)
        {
            base.Create(reader);

            ReadIPList(reader, PreviousResponders);
            Scopes.AddRange(reader.ReadList());
            AttributeFilter = reader.ReadString();
            Spi             = reader.ReadString();
        }
Exemplo n.º 11
0
        internal override void Create(SlpReader reader)
        {
            base.Create(reader);

            var tmp = reader.ReadString();
            Scopes.AddRange(reader.ReadList());
            Uri = new ServiceUri(tmp, Services.Locator.GetInstance<AttributeCollection>(reader));
            ReadAuthBlocks(reader, AuthBlocks);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Initalises a new extension from the received data
        /// </summary>
        /// <param name="data">byte array of data to parse</param>
        /// <returns>new AttributeMissing Extension</returns>
        internal override ExtensionBase Create(SlpReader reader)
        {
            var result = new AttributeMissingExtension();

            Offset = reader.ReadInt24();
            TemplateName = reader.ReadString();
            Attributes.AddRange(reader.TagListDecode(false));

            return result;
        }
Exemplo n.º 13
0
        /// <summary>
        /// Initalises a new extension from the received data
        /// </summary>
        /// <param name="data">byte array of data to parse</param>
        /// <returns>new UserDefined Extension</returns>
        internal override ExtensionBase Create(SlpReader reader)
        {
            var result = new UnknownExtension();

            result._Id    = reader.ReadInt16();
            result.Offset = reader.ReadInt24();
            result.Data   = reader.ReadBytes(result.Offset);

            return(result);
        }
Exemplo n.º 14
0
 protected void ReadIPList(SlpReader reader, IList<IPAddress> list)
 {
     foreach (var item in reader.ReadList())
     {
         var i = IPAddress.Parse(item);
         if (i.AddressFamily != AddressFamily.InterNetwork)
             throw new ServiceException("IP v4 addresses are the only allowable type.");
         list.Add(i);
     }
 }
Exemplo n.º 15
0
        internal override void Create(SlpReader reader)
        {
            base.Create(reader);

            ReadIPList(reader, PreviousResponders);
            Uri = new ServiceUri(reader.ReadString());
            Scopes.AddRange(reader.ReadList());
            Tags.AddRange(reader.ReadList());
            Spi = reader.ReadString();
        }
Exemplo n.º 16
0
        internal override void Create(SlpReader reader)
        {
            base.Create(reader);

            var tmp = reader.ReadString();

            Scopes.AddRange(reader.ReadList());
            Uri = new ServiceUri(tmp, Services.Locator.GetInstance <AttributeCollection>(reader));
            ReadAuthBlocks(reader, AuthBlocks);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Initalises a new extension from the received data
        /// </summary>
        /// <param name="data">byte array of data to parse</param>
        /// <returns>new AttributeMissing Extension</returns>
        internal override ExtensionBase Create(SlpReader reader)
        {
            var result = new AttributeMissingExtension();

            Offset       = reader.ReadInt24();
            TemplateName = reader.ReadString();
            Attributes.AddRange(reader.TagListDecode(false));

            return(result);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Read the authblocks bytes and create any authblocks, firing the event when a block is added
        /// </summary>
        /// <param name="reader">reader</param>
        /// <param name="authBlocks">list of authblocks</param>
        protected void ReadAuthBlocks(SlpReader reader, ICollection <Security.AuthenticationBlock> authBlocks)
        {
            var count = reader.ReadByte();

            for (int i = 0; i < count; i++)
            {
                var a = Services.Locator.GetInstance <Security.AuthenticationBlock>(reader);
                authBlocks.Add(a);
                OnAuthenticated(this, a);
            }
        }
Exemplo n.º 19
0
        public virtual Security.AuthenticationBlock CreateAuthenticationBlock(SlpReader reader)
        {
            var result = new Security.AuthenticationBlock();
            result.Descriptor = reader.ReadInt16();
            var length = reader.ReadInt16();
            result.TimeStamp = reader.ReadDateTime();
            result.SpiString = reader.ReadString();

            result.Data = reader.ReadBytes(length);

            return result;
        }
Exemplo n.º 20
0
 protected void ReadIPList(SlpReader reader, IList <IPAddress> list)
 {
     foreach (var item in reader.ReadList())
     {
         var i = IPAddress.Parse(item);
         if (i.AddressFamily != AddressFamily.InterNetwork)
         {
             throw new ServiceException("IP v4 addresses are the only allowable type.");
         }
         list.Add(i);
     }
 }
Exemplo n.º 21
0
        public MessageBase Read(SlpReader reader)
        {
            var v = reader.ReadByte();
            if (v != 1 && v != 2)
                throw new ServiceProtocolException(ServiceErrorCode.VersionNotSupported);

            var tmp = reader.ReadByte();
            MessageBase result = null;
            switch (tmp)
            {
                case 1:
                    result = new ServiceRequest();
                    break;
                case 2:
                    result = new ServiceReply();
                    break;
                case 3:
                    result = new ServiceRegistrationRequest();
                    break;
                case 4:
                    result = new ServiceDeregistrationRequest();
                    break;
                case 5:
                    result = new ServiceAcknowledgement();
                    break;
                case 6:
                    result = new AttributeRequest();
                    break;
                case 7:
                    result = new AttributeReply();
                    break;
                case 8:
                    result = new DirectoryAgentAdvert();
                    break;
                case 9:
                    result = new ServiceTypeRequest();
                    break;
                case 10:
                    result = new ServiceTypeReply();
                    break;
                case 11:
                    result = new ServiceAgentAdvert();
                    break;
                default:
                    throw new ServiceProtocolException(ServiceErrorCode.ParseError);
            }

            result.Version = v;
            result.Create(reader);

            return result;
        }
Exemplo n.º 22
0
        internal override void Create(SlpReader reader)
        {
            base.Create(reader);

            ErrorCode     = (ServiceErrorCode)reader.ReadInt16();
            BootTimeStamp = reader.ReadDateTime();
            var url = reader.ReadString();

            Scopes.AddRange(reader.ReadList());
            Uri = new ServiceUri(url, Services.Locator.GetInstance <AttributeCollection>(reader));
            SpiStrings.AddRange(reader.ReadList());
            ReadAuthBlocks(reader, AuthBlocks);
        }
Exemplo n.º 23
0
        internal override void Create(SlpReader reader)
        {
            base.Create(reader);

            var tmp = reader.ReadInt16();
            var result = new ServiceEntry[tmp];
            for (int i = 0; i < tmp; i++)
            {
                result[i] = Slp.Services.Locator.GetInstance<ServiceEntry>(reader);
            }

            Services = new ReadOnlyCollection<ServiceEntry>(result);
        }
Exemplo n.º 24
0
        internal override void Create(SlpReader reader)
        {
            base.Create(reader);

            var tmp    = reader.ReadInt16();
            var result = new ServiceEntry[tmp];

            for (int i = 0; i < tmp; i++)
            {
                result[i] = Slp.Services.Locator.GetInstance <ServiceEntry>(reader);
            }

            Services = new ReadOnlyCollection <ServiceEntry>(result);
        }
Exemplo n.º 25
0
        public virtual Security.AuthenticationBlock CreateAuthenticationBlock(SlpReader reader)
        {
            var result = new Security.AuthenticationBlock();

            result.Descriptor = reader.ReadInt16();
            var length = reader.ReadInt16();

            result.TimeStamp = reader.ReadDateTime();
            result.SpiString = reader.ReadString();

            result.Data = reader.ReadBytes(length);

            return(result);
        }
Exemplo n.º 26
0
        /// <summary>
        /// Read the message bytes and set the properties on this instance
        /// </summary>
        /// <param name="reader"></param>
        internal virtual void Create(SlpReader reader)
        {
            reader.ReadInt24();

            var flags = reader.ReadByte();

            IsOverFlow  = (flags & 0x80) == 0x80;
            IsFresh     = (flags & 0x40) == 0x40;
            IsMulticast = (flags & 0x20) == 0x20;

            reader.ReadByte();
            _ExtensionOffset = reader.ReadInt24();
            MessageId        = reader.ReadInt16();
            Language         = reader.ReadString();
        }
Exemplo n.º 27
0
        internal override void Create(SlpReader reader)
        {
            base.Create(reader);

            var tmp = reader.ReadInt16();

            if (tmp == 0xfff)
            {
                GetAllAuthorities = true;
            }
            else
            {
                NamingAuthority = reader.ReadString(tmp);
            }

            Scopes.AddRange(reader.ReadList());
        }
Exemplo n.º 28
0
        public virtual ServiceEntry CreateServiceEntry(SlpReader reader)
        {
            if (reader.ReadByte() != 0)
                throw new ServiceProtocolException(ServiceErrorCode.ParseError);

            var result = new ServiceEntry();
            result.Lifetime = reader.ReadTimeSpan();
            result.Uri = new ServiceUri(reader.ReadString());

            var count = reader.ReadByte();
            for (int i = 0; i < count; i++)
            {
                var a = CreateAuthenticationBlock(reader);
                result.AuthBlocks.Add(a);
                ServiceEntry.OnAuthenticated(result, a);
            }

            return result;
        }
Exemplo n.º 29
0
        public virtual ServiceEntry CreateServiceEntry(SlpReader reader)
        {
            if (reader.ReadByte() != 0)
            {
                throw new ServiceProtocolException(ServiceErrorCode.ParseError);
            }

            var result = new ServiceEntry();

            result.Lifetime = reader.ReadTimeSpan();
            result.Uri      = new ServiceUri(reader.ReadString());

            var count = reader.ReadByte();

            for (int i = 0; i < count; i++)
            {
                var a = CreateAuthenticationBlock(reader);
                result.AuthBlocks.Add(a);
                ServiceEntry.OnAuthenticated(result, a);
            }

            return(result);
        }
Exemplo n.º 30
0
        public virtual AttributeCollection CreateAttributeCollection(SlpReader reader)
        {
            var tmp = reader.ReadRawString();

            var result = new AttributeCollection();
            foreach (var item in tmp.Split(','))
            {
                var pair = item.Split('=');
                string key = null, value = null;
                if (pair.Length == 1)
                    key = reader.Unescape(pair[0]);
                else if (pair.Length == 2)
                {
                    key = reader.Unescape(pair[0]);
                    value = reader.Unescape(pair[1]);
                }
                else
                    throw new ServiceProtocolException(ServiceErrorCode.ParseError);

                result.Add(key, value);
            }

            return result;
        }
Exemplo n.º 31
0
        internal override void Create(SlpReader reader)
        {
            base.Create(reader);

            ErrorCode = (ServiceErrorCode)reader.ReadInt16();
            BootTimeStamp = reader.ReadDateTime();
            var url = reader.ReadString();
            Scopes.AddRange(reader.ReadList());
            Uri = new ServiceUri(url, Services.Locator.GetInstance<AttributeCollection>(reader));
            SpiStrings.AddRange(reader.ReadList());
            ReadAuthBlocks(reader, AuthBlocks);
        }
Exemplo n.º 32
0
        internal override void Create(SlpReader reader)
        {
            base.Create(reader);

            ReadIPList(reader, PreviousResponders);
            Uri = new ServiceUri(reader.ReadString());
            Scopes.AddRange(reader.ReadList());
            Tags.AddRange(reader.ReadList());
            Spi = reader.ReadString();
        }
Exemplo n.º 33
0
        internal override void Create(SlpReader reader)
        {
            base.Create(reader);

            ReadIPList(reader, PreviousResponders);
            Scopes.AddRange(reader.ReadList());
            AttributeFilter = reader.ReadString();
            Spi = reader.ReadString();
        }
Exemplo n.º 34
0
 /// <summary>
 /// Initalises a new extension from the received data
 /// </summary>
 /// <param name="data">byte array of data to parse</param>
 /// <returns>new Extension</returns>
 internal abstract ExtensionBase Create(SlpReader reader);
Exemplo n.º 35
0
 /// <summary>
 /// Read the authblocks bytes and create any authblocks, firing the event when a block is added
 /// </summary>
 /// <param name="reader">reader</param>
 /// <param name="authBlocks">list of authblocks</param>
 protected void ReadAuthBlocks(SlpReader reader, ICollection<Security.AuthenticationBlock> authBlocks)
 {
     var count = reader.ReadByte();
     for (int i = 0; i < count; i++)
     {
         var a = Services.Locator.GetInstance<Security.AuthenticationBlock>(reader);
         authBlocks.Add(a);
         OnAuthenticated(this, a);
     }
 }
Exemplo n.º 36
0
        /// <summary>
        /// Read the message bytes and set the properties on this instance
        /// </summary>
        /// <param name="reader"></param>
        internal virtual void Create(SlpReader reader)
        {
            reader.ReadInt24();

            var flags = reader.ReadByte();
            IsOverFlow = (flags & 0x80) == 0x80;
            IsFresh = (flags & 0x40) == 0x40;
            IsMulticast = (flags & 0x20) == 0x20;

            reader.ReadByte();
            _ExtensionOffset = reader.ReadInt24();
            MessageId = reader.ReadInt16();
            Language = reader.ReadString();
        }
Exemplo n.º 37
0
        internal override void Create(SlpReader reader)
        {
            base.Create(reader);

            var tmp = reader.ReadInt16();
            if (tmp == 0xfff)
                GetAllAuthorities = true;
            else
                NamingAuthority = reader.ReadString(tmp);

            Scopes.AddRange(reader.ReadList());
        }
Exemplo n.º 38
0
        public MessageBase Read(SlpReader reader)
        {
            var v = reader.ReadByte();

            if (v != 1 && v != 2)
            {
                throw new ServiceProtocolException(ServiceErrorCode.VersionNotSupported);
            }

            var         tmp    = reader.ReadByte();
            MessageBase result = null;

            switch (tmp)
            {
            case 1:
                result = new ServiceRequest();
                break;

            case 2:
                result = new ServiceReply();
                break;

            case 3:
                result = new ServiceRegistrationRequest();
                break;

            case 4:
                result = new ServiceDeregistrationRequest();
                break;

            case 5:
                result = new ServiceAcknowledgement();
                break;

            case 6:
                result = new AttributeRequest();
                break;

            case 7:
                result = new AttributeReply();
                break;

            case 8:
                result = new DirectoryAgentAdvert();
                break;

            case 9:
                result = new ServiceTypeRequest();
                break;

            case 10:
                result = new ServiceTypeReply();
                break;

            case 11:
                result = new ServiceAgentAdvert();
                break;

            default:
                throw new ServiceProtocolException(ServiceErrorCode.ParseError);
            }

            result.Version = v;
            result.Create(reader);

            return(result);
        }
Exemplo n.º 39
0
 /// <summary>
 /// Initalises a new extension from the received data
 /// </summary>
 /// <param name="data">byte array of data to parse</param>
 /// <returns>new Extension</returns>
 internal abstract ExtensionBase Create(SlpReader reader);