Ejemplo n.º 1
0
        public ControlResponse ProcessControlRequest(ControlRequest request)
        {
            var profile = _dlna.GetProfile(request.Headers) ??
                          _dlna.GetDefaultProfile();

            var serverAddress = request.RequestedUrl.Substring(0, request.RequestedUrl.IndexOf("/dlna", StringComparison.OrdinalIgnoreCase));
            string accessToken = null;

            var user = GetUser(profile);

            return new ControlHandler(
                Logger,
                _libraryManager,
                profile,
                serverAddress,
                accessToken,
                _imageProcessor,
                _userDataManager,
                user,
                SystemUpdateId,
                _config,
                _localization,
                _channelManager,
                _mediaSourceManager,
                _userViewManager,
                _mediaEncoder())
                .ProcessControlRequest(request);
        }
Ejemplo n.º 2
0
        public ControlResponse ProcessControlRequest(ControlRequest request)
        {
            try
            {
                var enableDebugLogging = Config.GetDlnaConfiguration().EnableDebugLog;

                if (enableDebugLogging)
                {
                    LogRequest(request);
                }

                var response = ProcessControlRequestInternal(request);

                if (enableDebugLogging)
                {
                    LogResponse(response);
                }

                return response;
            }
            catch (Exception ex)
            {
                Logger.ErrorException("Error processing control request", ex);

                return new ControlErrorHandler().GetResponse(ex);
            }
        }
Ejemplo n.º 3
0
 public ControlResponse ProcessControlRequest(ControlRequest request)
 {
     return new ControlHandler(
         _config,
         Logger)
         .ProcessControlRequest(request);
 }
Ejemplo n.º 4
0
        public ControlResponse ProcessControlRequest(ControlRequest request)
        {
            var profile = _dlna.GetProfile(request.Headers) ??
                         _dlna.GetDefaultProfile();

            return new ControlHandler(_logger, profile, _config).ProcessControlRequest(request);
        }
Ejemplo n.º 5
0
        private ControlResponse ProcessControlRequestInternal(ControlRequest request)
        {
            var soap = new XmlDocument();
            soap.LoadXml(request.InputXml);
            var sparams = new Headers();
            var body = soap.GetElementsByTagName("Body", NS_SOAPENV).Item(0);

            var method = body.FirstChild;

            foreach (var p in method.ChildNodes)
            {
                var e = p as XmlElement;
                if (e == null)
                {
                    continue;
                }
                sparams.Add(e.LocalName, e.InnerText.Trim());
            }

            Logger.Debug("Received control request {0}", method.LocalName);

            var result = GetResult(method.LocalName, sparams);

            var env = new XmlDocument();
            env.AppendChild(env.CreateXmlDeclaration("1.0", "utf-8", string.Empty));
            var envelope = env.CreateElement("SOAP-ENV", "Envelope", NS_SOAPENV);
            env.AppendChild(envelope);
            envelope.SetAttribute("encodingStyle", NS_SOAPENV, "http://schemas.xmlsoap.org/soap/encoding/");

            var rbody = env.CreateElement("SOAP-ENV:Body", NS_SOAPENV);
            env.DocumentElement.AppendChild(rbody);

            var response = env.CreateElement(String.Format("u:{0}Response", method.LocalName), method.NamespaceURI);
            rbody.AppendChild(response);

            foreach (var i in result)
            {
                var ri = env.CreateElement(i.Key);
                ri.InnerText = i.Value;
                response.AppendChild(ri);
            }

            var xml = env.OuterXml.Replace("xmlns:m=", "xmlns:u=");
            
            var controlResponse = new ControlResponse
            {
                Xml = xml,
                IsSuccessful = true
            };

            //Logger.Debug(xml);

            controlResponse.Headers.Add("EXT", string.Empty);

            return controlResponse;
        }
Ejemplo n.º 6
0
        public ControlResponse ProcessControlRequest(ControlRequest request)
        {
            try
            {
                return ProcessControlRequestInternal(request);
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Error processing control request", ex);

                return GetErrorResponse(ex);
            }
        }
Ejemplo n.º 7
0
        public ControlResponse ProcessControlRequest(ControlRequest request)
        {
            var profile = _dlna.GetProfile(request.Headers) ??
                          _dlna.GetDefaultProfile();

            var serverAddress = request.RequestedUrl.Substring(0, request.RequestedUrl.IndexOf("/dlna", StringComparison.OrdinalIgnoreCase));
            
            var user = GetUser(profile);

            return new ControlHandler(
                Logger,
                _libraryManager,
                profile,
                serverAddress,
                _imageProcessor,
                _userDataManager,
                user,
                SystemUpdateId,
                _config)
                .ProcessControlRequest(request);
        }
Ejemplo n.º 8
0
        public ControlResponse ProcessControlRequest(ControlRequest request)
        {
            var profile = _dlna.GetProfile(request.Headers) ??
                          _dlna.GetDefaultProfile();

            var device = DlnaServerEntryPoint.Instance.GetServerUpnpDevice(request.TargetServerUuId);

            var serverAddress = device.Descriptor.ToString().Substring(0, device.Descriptor.ToString().IndexOf("/dlna", StringComparison.OrdinalIgnoreCase));

            var user = GetUser(profile);

            return new ControlHandler(
                _logger,
                _libraryManager,
                profile,
                serverAddress,
                _dtoService,
                _imageProcessor,
                _userDataManager,
                user,
                _systemUpdateId)
                .ProcessControlRequest(request);
        }
Ejemplo n.º 9
0
        private void LogRequest(ControlRequest request)
        {
            var builder = new StringBuilder();

            var headers = string.Join(", ", request.Headers.Select(i => string.Format("{0}={1}", i.Key, i.Value)).ToArray());
            builder.AppendFormat("Headers: {0}", headers);
            builder.AppendLine();
            builder.Append(request.InputXml);

            Logger.LogMultiline("Control request", LogSeverity.Debug, builder);
        }
Ejemplo n.º 10
0
        private ControlResponse ProcessControlRequestInternal(ControlRequest request)
        {
            var soap = new XmlDocument();
            soap.LoadXml(request.InputXml);
            var sparams = new Headers();
            var body = soap.GetElementsByTagName("Body", NS_SOAPENV).Item(0);

            var method = body.FirstChild;

            foreach (var p in method.ChildNodes)
            {
                var e = p as XmlElement;
                if (e == null)
                {
                    continue;
                }
                sparams.Add(e.LocalName, e.InnerText.Trim());
            }

            var deviceId = "fgd";

            var env = new XmlDocument();
            env.AppendChild(env.CreateXmlDeclaration("1.0", "utf-8", "yes"));
            var envelope = env.CreateElement("SOAP-ENV", "Envelope", NS_SOAPENV);
            env.AppendChild(envelope);
            envelope.SetAttribute("encodingStyle", NS_SOAPENV, "http://schemas.xmlsoap.org/soap/encoding/");

            var rbody = env.CreateElement("SOAP-ENV:Body", NS_SOAPENV);
            env.DocumentElement.AppendChild(rbody);

            IEnumerable<KeyValuePair<string, string>> result;

            _logger.Debug("Received control request {0}", method.Name);

            var user = _user;

            if (string.Equals(method.LocalName, "GetSearchCapabilities", StringComparison.OrdinalIgnoreCase))
                result = HandleGetSearchCapabilities();
            else if (string.Equals(method.LocalName, "GetSortCapabilities", StringComparison.OrdinalIgnoreCase))
                result = HandleGetSortCapabilities();
            else if (string.Equals(method.LocalName, "GetSystemUpdateID", StringComparison.OrdinalIgnoreCase))
                result = HandleGetSystemUpdateID();
            else if (string.Equals(method.LocalName, "Browse", StringComparison.OrdinalIgnoreCase))
                result = HandleBrowse(sparams, user, deviceId);
            else if (string.Equals(method.LocalName, "X_GetFeatureList", StringComparison.OrdinalIgnoreCase))
                result = HandleXGetFeatureList();
            else if (string.Equals(method.LocalName, "X_SetBookmark", StringComparison.OrdinalIgnoreCase))
                result = HandleXSetBookmark(sparams, user);
            else if (string.Equals(method.LocalName, "Search", StringComparison.OrdinalIgnoreCase))
                result = HandleSearch(sparams, user, deviceId);
            else
                throw new ResourceNotFoundException("Unexpected control request name: " + method.LocalName);

            var response = env.CreateElement(String.Format("u:{0}Response", method.LocalName), method.NamespaceURI);
            rbody.AppendChild(response);

            foreach (var i in result)
            {
                var ri = env.CreateElement(i.Key);
                ri.InnerText = i.Value;
                response.AppendChild(ri);
            }

            var controlResponse = new ControlResponse
            {
                Xml = env.OuterXml,
                IsSuccessful = true
            };

            controlResponse.Headers.Add("EXT", string.Empty);

            return controlResponse;
        }