예제 #1
0
        public void UPnP10DeviceValidator_FailsDeviceTypeNamespaceOverMaxLength()
        {
            var rootDevice = new SsdpRootDevice()
            {
                FriendlyName = "Basic Device 1",
                Manufacturer = "Test Manufacturer",
                ManufacturerUrl = new Uri("http://testmanufacturer.com"),
                ModelDescription = "A test model device",
                ModelName = "Test Model",
                ModelNumber = "Model #1234",
                ModelUrl = new Uri("http://modelurl.com"),
                SerialNumber = "SN-123",
                Uuid = System.Guid.NewGuid().ToString(),
                Location = new Uri("http://testdevice:1700/xml"),
            };

            var testDevice = new SsdpEmbeddedDevice()
            {
                DeviceType = "TestEmbeddedDevice",
                FriendlyName = "Embedded Device 1",
                DeviceTypeNamespace = new String('A', 65),
                Manufacturer = "Test Manufacturer",
                ManufacturerUrl = new Uri("http://testmanufacturer.com"),
                ModelDescription = "A test model device",
                ModelName = "Test Model",
                ModelNumber = "Model #1234",
                ModelUrl = new Uri("http://modelurl.com"),
                SerialNumber = "SN-123",
                Uuid = System.Guid.NewGuid().ToString(),
            };
            rootDevice.AddDevice(testDevice);

            var validator = new Upnp10DeviceValidator();
            var results = validator.GetValidationErrors(testDevice);
            Assert.IsNotNull(results);
            Assert.IsTrue(results.First().IndexOf("DeviceTypeNamespace", StringComparison.OrdinalIgnoreCase) >= 0);
        }
예제 #2
0
        private SsdpEmbeddedDevice CreateValidEmbeddedDevice(SsdpRootDevice rootDevice)
        {
            var uuid = Guid.NewGuid().ToString();

            var retVal = new SsdpEmbeddedDevice()
            {
                DeviceType = "TestEmbeddedDevice",
                FriendlyName = "Test Embedded Device " + uuid,
                Manufacturer = "Test Manufacturer",
                ModelName = "Test Model",
                Uuid = uuid
            };
            rootDevice.AddDevice(retVal);

            return retVal;
        }
예제 #3
0
        public void UPnP10DeviceValidator_FailsNegativeWidth()
        {
            var rootDevice = new SsdpRootDevice()
            {
                FriendlyName = "Basic Device 1",
                Manufacturer = "Test Manufacturer",
                ManufacturerUrl = new Uri("http://testmanufacturer.com"),
                ModelDescription = "A test model device",
                ModelName = "Test Model",
                ModelNumber = "Model #1234",
                ModelUrl = new Uri("http://modelurl.com"),
                SerialNumber = "SN-123",
                Uuid = System.Guid.NewGuid().ToString(),
                Location = new Uri("http://testdevice:1700/xml"),
            };

            var testDevice = new SsdpEmbeddedDevice()
            {
                DeviceType = "TestEmbeddedDevice",
                FriendlyName = "Embedded Device 1",
                DeviceTypeNamespace = "testdevice-org",
                Manufacturer = "Test Manufacturer",
                ManufacturerUrl = new Uri("http://testmanufacturer.com"),
                ModelDescription = "A test model device",
                ModelName = "Test Model",
                ModelNumber = "Model #1234",
                ModelUrl = new Uri("http://modelurl.com"),
                SerialNumber = "SN-123",
                Uuid = System.Guid.NewGuid().ToString()
            };
            rootDevice.AddDevice(testDevice);

            var icon = new SsdpDeviceIcon()
            {
                ColorDepth = 32,
                Width = -1,
                Height = 48,
                MimeType = "image/png",
                Url = new Uri("someimage.png", UriKind.Relative)
            };
            testDevice.Icons.Add(icon);

            var validator = new Upnp10DeviceValidator();
            var results = validator.GetValidationErrors(testDevice);
            Assert.IsNotNull(results);
            Assert.AreEqual(1, results.Count());
            Assert.IsTrue(results.First().IndexOf("width", StringComparison.OrdinalIgnoreCase) >= 0);
        }
예제 #4
0
        public void UPnP10DeviceValidator_UpcCodeIsOptional()
        {
            var rootDevice = new SsdpRootDevice()
            {
                FriendlyName = "Basic Device 1",
                Manufacturer = "Test Manufacturer",
                ManufacturerUrl = new Uri("http://testmanufacturer.com"),
                ModelDescription = "A test model device",
                ModelName = "Test Model",
                ModelNumber = "Model #1234",
                ModelUrl = new Uri("http://modelurl.com"),
                SerialNumber = "SN-123",
                Uuid = System.Guid.NewGuid().ToString(),
                Location = new Uri("http://testdevice:1700/xml")
            };

            var testDevice = new SsdpEmbeddedDevice()
            {
                DeviceType = "TestEmbeddedDevice",
                FriendlyName = "Embedded Device 1",
                Manufacturer = "Test Manufacturer",
                ManufacturerUrl = new Uri("http://testmanufacturer.com"),
                ModelDescription = "A test model device",
                ModelName = "Test Model",
                ModelNumber = "Model #1234",
                ModelUrl = new Uri("http://modelurl.com"),
                SerialNumber = "SN-123",
                Uuid = System.Guid.NewGuid().ToString(),
                Upc = null
            };
            rootDevice.AddDevice(testDevice);

            var validator = new Upnp10DeviceValidator();
            var results = validator.GetValidationErrors(testDevice);
            Assert.IsNotNull(results);
            Assert.AreEqual(0, results.Count());
        }
예제 #5
0
        public void UPnP10DeviceValidator_FailsUpcCodeMoreThan12Chars()
        {
            var rootDevice = new SsdpRootDevice()
            {
                FriendlyName = "Basic Device 1",
                Manufacturer = "Test Manufacturer",
                ManufacturerUrl = new Uri("http://testmanufacturer.com"),
                ModelDescription = "A test model device",
                ModelName = "Test Model",
                ModelNumber = "Model #1234",
                ModelUrl = new Uri("http://modelurl.com"),
                SerialNumber = "SN-123",
                Uuid = System.Guid.NewGuid().ToString(),
                Location = new Uri("http://testdevice:1700/xml")
            };

            var testDevice = new SsdpEmbeddedDevice()
            {
                DeviceType = "TestEmbeddedDevice",
                FriendlyName = "Embedded Device 1",
                Manufacturer = "Test Manufacturer",
                ManufacturerUrl = new Uri("http://testmanufacturer.com"),
                ModelDescription = "A test model device",
                ModelName = "Test Model",
                ModelNumber = "Model #1234",
                ModelUrl = new Uri("http://modelurl.com"),
                SerialNumber = "SN-123",
                Uuid = System.Guid.NewGuid().ToString(),
                Upc = "1234567890123"
            };
            rootDevice.AddDevice(testDevice);

            var validator = new Upnp10DeviceValidator();
            var results = validator.GetValidationErrors(testDevice);
            Assert.IsNotNull(results);
            Assert.AreEqual(1, results.Count());
            Assert.IsTrue(results.First().IndexOf("UPC", StringComparison.OrdinalIgnoreCase) >= 0);
        }
예제 #6
0
        private SsdpEmbeddedDevice CreateEmbeddedDevice(SsdpRootDevice rootDevice)
        {
            var retVal = new SsdpEmbeddedDevice()
            {
                DeviceType = "TestEmbeddedDeviceType",
                DeviceTypeNamespace = "test-device-ns",
                FriendlyName = "Test Embedded Device 1",
                Manufacturer = "Test Manufacturer",
                ManufacturerUrl = new Uri("http://testman.com"),
                ModelDescription = "A test embeddeddevice",
                ModelName = "Test Model",
                ModelNumber = "1234",
                ModelUrl = new Uri("http://testmodel.com"),
                PresentationUrl = new Uri("http://testmodel.com/embedded/presentation"),
                SerialNumber = "TM-12345",
                Upc = "123456789012",
                Uuid = Guid.NewGuid().ToString()
            };
            rootDevice.AddDevice(retVal);

            return retVal;
        }
예제 #7
0
        private async Task RegisterServerEndpoints()
        {
            if (!_config.GetDlnaConfiguration().BlastAliveMessages)
            {
                return;
            }

            var cacheLength = _config.GetDlnaConfiguration().BlastAliveMessageIntervalSeconds;
            _Publisher.SupportPnpRootDevice = false;

            var addresses = (await _appHost.GetLocalIpAddresses().ConfigureAwait(false)).ToList();

            foreach (var address in addresses)
            {
                //if (IPAddress.IsLoopback(address))
                //{
                //    // Should we allow this?
                //    continue;
                //}

                var addressString = address.ToString();

                var udn = CreateUuid(addressString);

                var fullService = "urn:schemas-upnp-org:device:MediaServer:1";

                _logger.Info("Registering publisher for {0} on {1}", fullService, addressString);

                var descriptorUri = "/dlna/" + udn + "/description.xml";
                var uri = new Uri(_appHost.GetLocalApiUrl(address) + descriptorUri);

                var device = new SsdpRootDevice
                {
                    CacheLifetime = TimeSpan.FromSeconds(cacheLength), //How long SSDP clients can cache this info.
                    Location = uri, // Must point to the URL that serves your devices UPnP description document. 
                    FriendlyName = "Emby Server",
                    Manufacturer = "Emby",
                    ModelName = "Emby Server",
                    Uuid = udn
                    // This must be a globally unique value that survives reboots etc. Get from storage or embedded hardware etc.                
                };

                SetProperies(device, fullService);
                _Publisher.AddDevice(device);

                var embeddedDevices = new List<string>
                {
                    "urn:schemas-upnp-org:service:ContentDirectory:1",
                    "urn:schemas-upnp-org:service:ConnectionManager:1",
                    "urn:microsoft.com:service:X_MS_MediaReceiverRegistrar:1"
                };

                foreach (var subDevice in embeddedDevices)
                {
                    var embeddedDevice = new SsdpEmbeddedDevice
                    {
                        FriendlyName = device.FriendlyName,
                        Manufacturer = device.Manufacturer,
                        ModelName = device.ModelName,
                        Uuid = udn
                        // This must be a globally unique value that survives reboots etc. Get from storage or embedded hardware etc.                
                    };

                    SetProperies(embeddedDevice, subDevice);
                    device.AddDevice(embeddedDevice);
                }
            }
        }