public static List <DeviceDiscoveryData> GetDevices(SoapMessage <WSD.ProbeMatchesType> message, Net.IPAddress sender)
        {
            List <DeviceDiscoveryData> devices = new List <DeviceDiscoveryData>();

            if (message.Object.ProbeMatch != null)
            {
                for (int i = 0; i < message.Object.ProbeMatch.Length; i++)
                {
                    WSD.ProbeMatchType match = message.Object.ProbeMatch[i];
                    if ((match.XAddrs != null) && (CheckDeviceMatchType(message, i)))
                    {
                        DeviceDiscoveryData device = new DeviceDiscoveryData();
                        device.Type            = match.Types;
                        device.Scopes          = match.Scopes.Text[0];
                        device.EndPointAddress = sender.ToString();

                        string[] addresses = match.XAddrs.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        device.ServiceAddresses.AddRange(addresses);
                        device.UUID            = match.EndpointReference.Address.Value;
                        device.MetadataVersion = match.MetadataVersion;
                        devices.Add(device);
                    }
                }
            }
            return(devices);
        }
        public static List <DeviceDiscoveryData> GetDevices(
            SoapMessage <WSD.ProbeMatchesType> message, Net.IPAddress sender, DiscoveryType[][] types)
        {
            List <DeviceDiscoveryData> devices = new List <DeviceDiscoveryData>();

            if (message.Object.ProbeMatch != null)
            {
                for (int i = 0; i < message.Object.ProbeMatch.Length; i++)
                {
                    WSD.ProbeMatchType match = message.Object.ProbeMatch[i];
                    if ((match.XAddrs != null) &&
                        (types == null
                         //check devices according to Test Spec Annex A.1
                            ? CheckDeviceMatchType(message, i, true, false)
                         //check if device contains at least one item from types array
                            : CheckDeviceMatchType(message, i, types)))
                    {
                        DeviceDiscoveryData device = new DeviceDiscoveryData();
                        device.Type            = match.Types;
                        device.Scopes          = match.Scopes.Text[0];
                        device.EndPointAddress = sender.ToString();

                        string[] addresses = match.XAddrs.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        device.ServiceAddresses.AddRange(addresses);
                        device.UUID            = match.EndpointReference.Address.Value;
                        device.MetadataVersion = match.MetadataVersion;
                        devices.Add(device);
                    }
                }
            }
            return(devices);
        }
Exemple #3
0
        public byte[] BuildProbeMatches(string[] scopes, bool onvif20, string[] xAddrs, string relateTo)
        {
            WSD.ProbeMatchesType probeMatches = new WSD.ProbeMatchesType();

            probeMatches.ProbeMatch = new WSD.ProbeMatchType[1];
            WSD.ProbeMatchType probeMatch = new WSD.ProbeMatchType();

            // Scopes
            probeMatch.Scopes = BuildScopes(scopes, null);

            // Types
            XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();

            probeMatch.Types = BuildTypes(onvif20, ref namespaces);

            // EndpointReference
            probeMatch.EndpointReference = BuildEndpointReference();

            // XAddrs
            probeMatch.XAddrs = BuildXAddrs(xAddrs);

            // MetadataVersion
            probeMatch.MetadataVersion = 0;

            probeMatches.ProbeMatch[0] = probeMatch;

            DiscoveryHeaderBuilder header = new DiscoveryHeaderBuilder();

            header.OrigingMessageId = relateTo;

            byte[] msg = SoapBuilder.BuildMessage(probeMatches, Encoding.UTF8, header, namespaces);

            return(msg);
        }
        public WSD.ProbeMatchesType BuildProbeMatches(WSD.ProbeType probe)
        {
            WSD.ProbeMatchType match = new WSD.ProbeMatchType();
            match.EndpointReference               = new WSD.EndpointReferenceType();
            match.EndpointReference.Address       = new WSD.AttributedURI();
            match.EndpointReference.Address.Value = _uuid;
            match.Types       = "dn:NetworkVideoTransmitter";
            match.Scopes      = new WSD.ScopesType();
            match.Scopes.Text = _scopes;
            match.XAddrs      = ServiceAddress;

            WSD.ProbeMatchesType matches = new WSD.ProbeMatchesType();
            matches.ProbeMatch = new WSD.ProbeMatchType[] { match };
            return(matches);
        }
Exemple #5
0
 /// <summary>
 /// Validates ProbeMatch element of ProbeMatches message
 /// </summary>
 /// <param name="match">Element to be validated</param>
 /// <param name="reason">Reason why element is invalid</param>
 /// <returns>true, if element is valid</returns>
 protected bool ValidateProbeMatch(WSD.ProbeMatchType match, out string reason)
 {
     reason = null;
     if (match.Scopes == null)
     {
         reason = Resources.ErrorNoScopes_Text;
         return(false);
     }
     if (match.Types == null)
     {
         //it looks like this check is unnecessary,
         //because only ProbeMatch with valid type should be validated
         reason = Resources.ErrorNoTypes_Text;
         return(false);
     }
     if (match.EndpointReference == null)
     {
         reason = Resources.ErrorNoEndpointReference_Text;
         return(false);
     }
     if (string.IsNullOrEmpty(match.XAddrs))
     {
         reason = Resources.ErrorNoXAddrs_Text;
         return(false);
     }
     string[] addresses = match.XAddrs.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
     foreach (string address in addresses)
     {
         Uri addr;
         if (!Uri.TryCreate(address, UriKind.Absolute, out addr))
         {
             reason = string.Format(Resources.ErrorInvalidXAddrs_Format, address);
             return(false);
         }
         else if (string.Compare(addr.LocalPath, "/onvif/device_service", true) != 0)
         {
             reason = string.Format(Resources.ErrorInvalidServicePath_Format, addr.LocalPath);
             return(false);
         }
     }
     return(true);
 }
        /// <summary>
        /// Validates ProbeMatches messages
        /// </summary>
        /// <param name="message">Message to be validated</param>
        /// <param name="reason">Reason why message is invalid</param>
        /// <returns>true, if message is valid</returns>
        protected bool ValidateProbeMatchMessage(SoapMessage <WSD.ProbeMatchesType> message, out string reason)
        {
            bool mode1 = Features.Contains(Feature.DiscoveryTypesDnNetworkVideoTransmitter);
            bool mode2 = Features.Contains(Feature.DiscoveryTypesTdsDevice);
            bool res   = true;

            reason = null;
            try
            {
                //check Types namespace
                if (message.Object.ProbeMatch == null)
                {
                    reason = Resources.ErrorNoProbeMatch_Text;
                    return(false);
                }
                bool found = false;
                for (int i = 0; i < message.Object.ProbeMatch.Length; i++)
                {
                    WSD.ProbeMatchType match = message.Object.ProbeMatch[i];
                    if (DiscoveryUtils.CheckDeviceMatchType(message, i, out reason, mode1, mode2))
                    {
                        if (!ValidateProbeMatch(match, out reason))
                        {
                            return(false);
                        }
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                reason = e.Message;
                res    = false;
            }
            return(res);
        }
Exemple #7
0
        /// <summary>
        /// Validates ProbeMatches messages
        /// </summary>
        /// <param name="message">Message to be validated</param>
        /// <param name="reason">Reason why message is invalid</param>
        /// <returns>true, if message is valid</returns>
        protected bool ValidateProbeMatchMessage(SoapMessage <WSD.ProbeMatchesType> message, out string reason)
        {
            bool res = true;

            reason = null;
            try
            {
                //check Types namespace
                if (message.Object.ProbeMatch == null)
                {
                    reason = Resources.ErrorNoProbeMatch_Text;
                    return(false);
                }
                bool found = false;
                for (int i = 0; i < message.Object.ProbeMatch.Length; i++)
                {
                    WSD.ProbeMatchType match = message.Object.ProbeMatch[i];
                    if (DiscoveryUtils.CheckDeviceMatchType(message, i))
                    {
                        if (!ValidateProbeMatch(match, out reason))
                        {
                            return(false);
                        }
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    reason = string.Format(Resources.ErrorIncorrectTypes_Format, DiscoveryUtils.ONVIF_DISCOVER_TYPES, DiscoveryUtils.ONVIF_NETWORK_WSDL_URL);
                    return(false);
                }
            }
            catch (Exception e)
            {
                reason = e.Message;
                res    = false;
            }
            return(res);
        }
        public byte[] BuildProbeMatches(string[] scopes, bool onvif20, string[] xAddrs, string relateTo)
        {
            WSD.ProbeMatchesType probeMatches = new WSD.ProbeMatchesType();

            probeMatches.ProbeMatch = new WSD.ProbeMatchType[1];
            WSD.ProbeMatchType probeMatch = new WSD.ProbeMatchType();

            probeMatches.Xmlns = new XmlSerializerNamespaces();
            probeMatches.Xmlns.Add("dis", "http://schemas.xmlsoap.org/ws/2005/04/discovery");
            probeMatch.Xmlns = new XmlSerializerNamespaces();
            probeMatch.Xmlns.Add("", "http://www.onvif.org/ver10/device/wsdl");

            // Scopes
            probeMatch.Scopes = BuildScopes(scopes, null);

            // Types
            XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();

            namespaces.Add("dis", "http://schemas.xmlsoap.org/ws/2005/04/discovery");
            probeMatch.Types = BuildTypes(onvif20, ref namespaces);

            // EndpointReference
            probeMatch.EndpointReference = BuildEndpointReference();

            // XAddrs
            probeMatch.XAddrs = BuildXAddrs(xAddrs);

            // MetadataVersion
            probeMatch.MetadataVersion = 0;

            probeMatches.ProbeMatch[0] = probeMatch;

            DiscoveryHeaderBuilder header = new DiscoveryHeaderBuilder();

            header.OrigingMessageId = relateTo;

            byte[] msg = SoapBuilder.BuildMessage(probeMatches, Encoding.UTF8, header, namespaces);

            return(msg);
        }