using MediaBrowser.Dlna.Common; using MediaBrowser.Model.Dlna; using System.Collections.Generic; using System.Security; using System.Text; namespace MediaBrowser.Dlna.Server { public class ContentDirectoryXmlBuilder { private readonly DeviceProfile _profile; public ContentDirectoryXmlBuilder(DeviceProfile profile) { _profile = profile; } public string GetXml() { var builder = new StringBuilder(); builder.Append(""); builder.Append("scpd xmlns=\"urn:schemas-upnp-org:service-1-0\""); builder.Append(""); builder.Append("1"); builder.Append("0"); builder.Append(""); AppendActionList(builder); AppendServiceStateTable(builder); builder.Append(""); return builder.ToString(); } private void AppendActionList(StringBuilder builder) { builder.Append(""); foreach (var item in new ServiceActionListBuilder().GetActions()) { builder.Append(""); builder.Append("" + SecurityElement.Escape(item.Name ?? string.Empty) + ""); builder.Append(""); foreach (var argument in item.ArgumentList) { builder.Append(""); builder.Append("" + SecurityElement.Escape(argument.Name ?? string.Empty) + ""); builder.Append("" + SecurityElement.Escape(argument.Direction ?? string.Empty) + ""); builder.Append("" + SecurityElement.Escape(argument.RelatedStateVariable ?? string.Empty) + ""); builder.Append(""); } builder.Append(""); builder.Append(""); } builder.Append(""); } private void AppendServiceStateTable(StringBuilder builder) { builder.Append(""); foreach (var item in GetStateVariables()) { var sendEvents = item.SendsEvents ? "yes" : "no"; builder.Append(""); builder.Append("" + SecurityElement.Escape(item.Name ?? string.Empty) + ""); builder.Append("" + SecurityElement.Escape(item.DataType ?? string.Empty) + ""); if (item.AllowedValues.Count > 0) { builder.Append(""); foreach (var allowedValue in item.AllowedValues) { builder.Append("" + SecurityElement.Escape(allowedValue) + ""); } builder.Append(""); } builder.Append(""); } builder.Append(""); } private IEnumerable GetStateVariables() { var list = new List(); list.Add(new StateVariable { Name = "A_ARG_TYPE_SortCriteria", DataType = "string", SendsEvents = false }); list.Add(new StateVariable { Name = "A_ARG_TYPE_UpdateID", DataType = "ui4", SendsEvents = false }); list.Add(new StateVariable { Name = "A_ARG_TYPE_SearchCriteria", DataType = "string", SendsEvents = false }); list.Add(new StateVariable { Name = "A_ARG_TYPE_Filter", DataType = "string", SendsEvents = false }); list.Add(new StateVariable { Name = "A_ARG_TYPE_Result", DataType = "string", SendsEvents = false }); list.Add(new StateVariable { Name = "A_ARG_TYPE_Index", DataType = "ui4", SendsEvents = false }); list.Add(new StateVariable { Name = "A_ARG_TYPE_ObjectID", DataType = "string", SendsEvents = false }); list.Add(new StateVariable { Name = "SortCapabilities", DataType = "string", SendsEvents = false }); list.Add(new StateVariable { Name = "SearchCapabilities", DataType = "string", SendsEvents = false }); list.Add(new StateVariable { Name = "A_ARG_TYPE_Count", DataType = "ui4", SendsEvents = false }); list.Add(new StateVariable { Name = "A_ARG_TYPE_BrowseFlag", DataType = "string", SendsEvents = false, AllowedValues = new List { "BrowseMetadata", "BrowseDirectChildren" } }); list.Add(new StateVariable { Name = "SystemUpdateID", DataType = "ui4", SendsEvents = true }); list.Add(new StateVariable { Name = "A_ARG_TYPE_BrowseLetter", DataType = "string", SendsEvents = false }); list.Add(new StateVariable { Name = "A_ARG_TYPE_CategoryType", DataType = "ui4", SendsEvents = false }); list.Add(new StateVariable { Name = "A_ARG_TYPE_RID", DataType = "ui4", SendsEvents = false }); list.Add(new StateVariable { Name = "A_ARG_TYPE_PosSec", DataType = "ui4", SendsEvents = false }); list.Add(new StateVariable { Name = "A_ARG_TYPE_Featurelist", DataType = "string", SendsEvents = false }); return list; } public override string ToString() { return GetXml(); } } }