The Free Software Media System - Server Backend & API
3.2.30.3
Luke Pulverenti0f23c7cfc137
diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.csindex 3454451022..a9d3247e65 100644--- a/Emby.Server.Implementations/ApplicationHost.cs+++ b/Emby.Server.Implementations/ApplicationHost.cs@@ -1614,7 +1614,7 @@ namespace Emby.Server.Implementations{try{- ServerManager.Start(GetUrlPrefixes());+ ServerManager.Start(GetUrlPrefixes().ToArray());return;}catch (Exception ex)@@ -1631,7 +1631,7 @@ namespace Emby.Server.Implementationstry{- ServerManager.Start(GetUrlPrefixes());+ ServerManager.Start(GetUrlPrefixes().ToArray());}catch (Exception ex){diff --git a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs b/Emby.Server.Implementations/HttpServer/HttpListenerHost.csindex f1fea2085b..9297362f9e 100644--- a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs+++ b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs@@ -10,7 +10,6 @@ using System.Reflection;using System.Text;using System.Threading;using System.Threading.Tasks;-using Emby.Server.Implementations.HttpServer;using Emby.Server.Implementations.HttpServer.SocketSharp;using Emby.Server.Implementations.Services;using MediaBrowser.Common.Net;@@ -34,7 +33,7 @@ namespace Emby.Server.Implementations.HttpServerprivate string DefaultRedirectPath { get; set; }private readonly ILogger _logger;- public IEnumerable<string> UrlPrefixes { get; private set; }+ public string[] UrlPrefixes { get; private set; }private readonly List<IService> _restServices = new List<IService>();@@ -62,8 +61,8 @@ namespace Emby.Server.Implementations.HttpServerprivate readonly Func<Type, Func<string, object>> _funcParseFn;private readonly bool _enableDualModeSockets;- public List<Action<IRequest, IResponse, object>> RequestFilters { get; set; }- public List<Action<IRequest, IResponse, object>> ResponseFilters { get; set; }+ public Action<IRequest, IResponse, object>[] RequestFilters { get; set; }+ public Action<IRequest, IResponse, object>[] ResponseFilters { get; set; }private readonly Dictionary<Type, Type> ServiceOperationsMap = new Dictionary<Type, Type>();public static HttpListenerHost Instance { get; protected set; }@@ -95,8 +94,8 @@ namespace Emby.Server.Implementations.HttpServer_logger = logger;- RequestFilters = new List<Action<IRequest, IResponse, object>>();- ResponseFilters = new List<Action<IRequest, IResponse, object>>();+ RequestFilters = new Action<IRequest, IResponse, object>[] { };+ ResponseFilters = new Action<IRequest, IResponse, object>[] { };}public string GlobalResponse { get; set; }@@ -135,7 +134,9 @@ namespace Emby.Server.Implementations.HttpServer//Exec all RequestFilter attributes with Priority < 0var attributes = GetRequestFilterAttributes(requestDto.GetType());var i = 0;- for (; i < attributes.Length && attributes[i].Priority < 0; i++)+ var count = attributes.Count;++ for (; i < count && attributes[i].Priority < 0; i++){var attribute = attributes[i];attribute.RequestFilter(req, res, requestDto);@@ -148,7 +149,7 @@ namespace Emby.Server.Implementations.HttpServer}//Exec remaining RequestFilter attributes with Priority >= 0- for (; i < attributes.Length && attributes[i].Priority >= 0; i++)+ for (; i < count && attributes[i].Priority >= 0; i++){var attribute = attributes[i];attribute.RequestFilter(req, res, requestDto);@@ -167,7 +168,7 @@ namespace Emby.Server.Implementations.HttpServerServiceOperationsMap[requestType] = serviceType;}- private IHasRequestFilter[] GetRequestFilterAttributes(Type requestDtoType)+ private List<IHasRequestFilter> GetRequestFilterAttributes(Type requestDtoType){var attributes = requestDtoType.GetTypeInfo().GetCustomAttributes(true).OfType<IHasRequestFilter>().ToList();@@ -179,24 +180,7 @@ namespace Emby.Server.Implementations.HttpServerattributes.Sort((x, y) => x.Priority - y.Priority);- return attributes.ToArray(attributes.Count);- }-- /// <summary>- /// Starts the Web Service- /// </summary>- private void StartListener()- {- WebSocketSharpRequest.HandlerFactoryPath = GetHandlerPathIfAny(UrlPrefixes.First());-- _listener = GetListener();-- _listener.WebSocketConnected = OnWebSocketConnected;- _listener.WebSocketConnecting = OnWebSocketConnecting;- _listener.ErrorHandler = ErrorHandler;- _listener.RequestHandler = RequestHandler;-- _listener.Start(UrlPrefixes);+ return attributes;}public static string GetHandlerPathIfAny(string listenerUrl)@@ -698,13 +682,18 @@ namespace Emby.Server.Implementations.HttpServerServiceController.Init(this, types);- var requestFilters = _appHost.GetExports<IRequestFilter>().ToList();- foreach (var filter in requestFilters)+ var list = new List<Action<IRequest, IResponse, object>>();+ foreach (var filter in _appHost.GetExports<IRequestFilter>()){- RequestFilters.Add(filter.Filter);+ list.Add(filter.Filter);}- ResponseFilters.Add(new ResponseFilter(_logger).FilterResponse);+ RequestFilters = list.ToArray();++ ResponseFilters = new Action<IRequest, IResponse, object>[]+ {+ new ResponseFilter(_logger).FilterResponse+ };}public RouteAttribute[] GetRouteAttributes(Type requestType)@@ -819,10 +808,20 @@ namespace Emby.Server.Implementations.HttpServerGC.SuppressFinalize(this);}- public void StartServer(IEnumerable<string> urlPrefixes)+ public void StartServer(string[] urlPrefixes){- UrlPrefixes = urlPrefixes.ToList();- StartListener();+ UrlPrefixes = urlPrefixes;++ WebSocketSharpRequest.HandlerFactoryPath = GetHandlerPathIfAny(UrlPrefixes[0]);++ _listener = GetListener();++ _listener.WebSocketConnected = OnWebSocketConnected;+ _listener.WebSocketConnecting = OnWebSocketConnecting;+ _listener.ErrorHandler = ErrorHandler;+ _listener.RequestHandler = RequestHandler;++ _listener.Start(UrlPrefixes);}}}\ No newline at end of filediff --git a/Emby.Server.Implementations/HttpServer/LoggerUtils.cs b/Emby.Server.Implementations/HttpServer/LoggerUtils.csindex de30dc30a8..46bb4c7f94 100644--- a/Emby.Server.Implementations/HttpServer/LoggerUtils.cs+++ b/Emby.Server.Implementations/HttpServer/LoggerUtils.cs@@ -1,10 +1,8 @@using MediaBrowser.Model.Logging;using System;using System.Globalization;-using System.Linq;using MediaBrowser.Model.Services;using SocketHttpListener.Net;-using MediaBrowser.Model.Extensions;namespace Emby.Server.Implementations.HttpServer{@@ -30,7 +28,20 @@ namespace Emby.Server.Implementations.HttpServer}else{- var headerText = string.Join(", ", headers.Select(i => i.Name + "=" + i.Value).ToArray(headers.Count));+ var headerText = string.Empty;+ var index = 0;++ foreach (var i in headers)+ {+ if (index > 0)+ {+ headerText += ", ";+ }++ headerText += i.Name + "=" + i.Value;++ index++;+ }logger.Info("HTTP {0} {1}. {2}", method, url, headerText);}@@ -49,7 +60,8 @@ namespace Emby.Server.Implementations.HttpServervar durationMs = duration.TotalMilliseconds;var logSuffix = durationMs >= 1000 && durationMs < 60000 ? "ms (slow)" : "ms";- var headerText = headers == null ? string.Empty : "Headers: " + string.Join(", ", headers.Where(i => i.Name.IndexOf("Access-", StringComparison.OrdinalIgnoreCase) == -1).Select(i => i.Name + "=" + i.Value).ToArray());+ //var headerText = headers == null ? string.Empty : "Headers: " + string.Join(", ", headers.Where(i => i.Name.IndexOf("Access-", StringComparison.OrdinalIgnoreCase) == -1).Select(i => i.Name + "=" + i.Value).ToArray());+ var headerText = string.Empty;logger.Info("HTTP Response {0} to {1}. Time: {2}{3}. {4} {5}", statusCode, endPoint, Convert.ToInt32(durationMs).ToString(CultureInfo.InvariantCulture), logSuffix, url, headerText);}}diff --git a/Emby.Server.Implementations/HttpServer/Security/AuthService.cs b/Emby.Server.Implementations/HttpServer/Security/AuthService.csindex 4d00c9b195..500bdc61eb 100644--- a/Emby.Server.Implementations/HttpServer/Security/AuthService.cs+++ b/Emby.Server.Implementations/HttpServer/Security/AuthService.cs@@ -7,7 +7,6 @@ using MediaBrowser.Controller.Net;using MediaBrowser.Controller.Security;using MediaBrowser.Controller.Session;using System;-using System.Collections.Generic;using System.Linq;namespace Emby.Server.Implementations.HttpServer.Security@@ -78,7 +77,7 @@ namespace Emby.Server.Implementations.HttpServer.Securityif (!IsExemptFromRoles(auth, authAttribtues, info)){- var roles = authAttribtues.GetRoles().ToList();+ var roles = authAttribtues.GetRoles();ValidateRoles(roles, user);}@@ -162,7 +161,7 @@ namespace Emby.Server.Implementations.HttpServer.Securityreturn false;}- private void ValidateRoles(List<string> roles, User user)+ private void ValidateRoles(string[] roles, User user){if (roles.Contains("admin", StringComparer.OrdinalIgnoreCase)){diff --git a/Emby.Server.Implementations/HttpServer/Security/AuthorizationContext.cs b/Emby.Server.Implementations/HttpServer/Security/AuthorizationContext.csindex ede85fb67d..f402777789 100644--- a/Emby.Server.Implementations/HttpServer/Security/AuthorizationContext.cs+++ b/Emby.Server.Implementations/HttpServer/Security/AuthorizationContext.cs@@ -3,8 +3,8 @@ using MediaBrowser.Controller.Net;using MediaBrowser.Controller.Security;using System;using System.Collections.Generic;-using System.Linq;using MediaBrowser.Model.Services;+using System.Linq;namespace Emby.Server.Implementations.HttpServer.Security{@@ -90,7 +90,7 @@ namespace Emby.Server.Implementations.HttpServer.SecurityAccessToken = token});- var tokenInfo = result.Items.FirstOrDefault();+ var tokenInfo = result.Items.Length > 0 ? result.Items[0] : null;if (tokenInfo != null){@@ -161,7 +161,7 @@ namespace Emby.Server.Implementations.HttpServer.Security// There should be at least to partsif (parts.Length != 2) return null;- var acceptedNames = new[] { "MediaBrowser", "Emby"};+ var acceptedNames = new[] { "MediaBrowser", "Emby" };// It has to be a digest requestif (!acceptedNames.Contains(parts[0] ?? string.Empty, StringComparer.OrdinalIgnoreCase))diff --git a/Emby.Server.Implementations/ServerManager/ServerManager.cs b/Emby.Server.Implementations/ServerManager/ServerManager.csindex 7cd94c5260..b267f928b6 100644--- a/Emby.Server.Implementations/ServerManager/ServerManager.cs+++ b/Emby.Server.Implementations/ServerManager/ServerManager.cs@@ -112,7 +112,7 @@ namespace Emby.Server.Implementations.ServerManager/// <summary>/// Starts this instance./// </summary>- public void Start(IEnumerable<string> urlPrefixes)+ public void Start(string[] urlPrefixes){ReloadHttpServer(urlPrefixes);}@@ -120,7 +120,7 @@ namespace Emby.Server.Implementations.ServerManager/// <summary>/// Restarts the Http Server, or starts it if not currently running/// </summary>- private void ReloadHttpServer(IEnumerable<string> urlPrefixes)+ private void ReloadHttpServer(string[] urlPrefixes){_logger.Info("Loading Http Server");diff --git a/Emby.Server.Implementations/Services/ServiceExec.cs b/Emby.Server.Implementations/Services/ServiceExec.csindex 4a2199c89d..fa9e26f28f 100644--- a/Emby.Server.Implementations/Services/ServiceExec.cs+++ b/Emby.Server.Implementations/Services/ServiceExec.cs@@ -24,19 +24,33 @@ namespace Emby.Server.Implementations.Services"POLL", "SUBSCRIBE", "UNSUBSCRIBE"});- public static IEnumerable<MethodInfo> GetActions(this Type serviceType)+ public static List<MethodInfo> GetActions(this Type serviceType){- foreach (var mi in serviceType.GetRuntimeMethods().Where(i => i.IsPublic && !i.IsStatic))+ var list = new List<MethodInfo>();++ foreach (var mi in serviceType.GetRuntimeMethods()){+ if (!mi.IsPublic)+ {+ continue;+ }++ if (mi.IsStatic)+ {+ continue;+ }+if (mi.GetParameters().Length != 1)continue;var actionName = mi.Name;- if (!AllVerbs.Contains(actionName, StringComparer.OrdinalIgnoreCase) && !string.Equals(actionName, ServiceMethod.AnyAction, StringComparison.OrdinalIgnoreCase))+ if (!AllVerbs.Contains(actionName, StringComparer.OrdinalIgnoreCase))continue;- yield return mi;+ list.Add(mi);}++ return list;}}@@ -59,8 +73,7 @@ namespace Emby.Server.Implementations.Servicesvar actionName = request.Verb ?? "POST";ServiceMethod actionContext;- if (ServiceExecGeneral.execMap.TryGetValue(ServiceMethod.Key(serviceType, actionName, requestName), out actionContext)- || ServiceExecGeneral.execMap.TryGetValue(ServiceMethod.AnyKey(serviceType, requestName), out actionContext))+ if (ServiceExecGeneral.execMap.TryGetValue(ServiceMethod.Key(serviceType, actionName, requestName), out actionContext)){if (actionContext.RequestFilters != null){diff --git a/Emby.Server.Implementations/Services/ServiceMethod.cs b/Emby.Server.Implementations/Services/ServiceMethod.csindex bcbc6fb572..fa2dd43d06 100644--- a/Emby.Server.Implementations/Services/ServiceMethod.cs+++ b/Emby.Server.Implementations/Services/ServiceMethod.cs@@ -4,8 +4,6 @@ namespace Emby.Server.Implementations.Services{public class ServiceMethod{- public const string AnyAction = "ANY";-public string Id { get; set; }public ActionInvokerFn ServiceAction { get; set; }@@ -15,10 +13,5 @@ namespace Emby.Server.Implementations.Services{return serviceType.FullName + " " + method.ToUpper() + " " + requestDtoName;}-- public static string AnyKey(Type serviceType, string requestDtoName)- {- return Key(serviceType, AnyAction, requestDtoName);- }}}\ No newline at end of filediff --git a/Emby.Server.Implementations/Services/StringMapTypeDeserializer.cs b/Emby.Server.Implementations/Services/StringMapTypeDeserializer.csindex fc1cf4ed99..2233bf918b 100644--- a/Emby.Server.Implementations/Services/StringMapTypeDeserializer.cs+++ b/Emby.Server.Implementations/Services/StringMapTypeDeserializer.cs@@ -1,6 +1,5 @@using System;using System.Collections.Generic;-using System.Linq;using System.Reflection;namespace Emby.Server.Implementations.Services@@ -64,11 +63,16 @@ namespace Emby.Server.Implementations.Servicesif (instance == null)instance = _CreateInstanceFn(type);- foreach (var pair in keyValuePairs.Where(x => !string.IsNullOrEmpty(x.Value)))+ foreach (var pair in keyValuePairs){propertyName = pair.Key;propertyTextValue = pair.Value;+ if (string.IsNullOrEmpty(propertyTextValue))+ {+ continue;+ }+if (!propertySetterMap.TryGetValue(propertyName, out propertySerializerEntry)){if (propertyName == "v")@@ -115,7 +119,7 @@ namespace Emby.Server.Implementations.Services{public static Action<object, object> GetSetPropertyMethod(Type type, PropertyInfo propertyInfo){- if (!propertyInfo.CanWrite || propertyInfo.GetIndexParameters().Any()) return null;+ if (!propertyInfo.CanWrite || propertyInfo.GetIndexParameters().Length > 0) return null;var setMethodInfo = propertyInfo.SetMethod;return (instance, value) => setMethodInfo.Invoke(instance, new[] { value });diff --git a/MediaBrowser.Api/Dlna/DlnaServerService.cs b/MediaBrowser.Api/Dlna/DlnaServerService.csindex 389244aa96..cbef6e5b3b 100644--- a/MediaBrowser.Api/Dlna/DlnaServerService.cs+++ b/MediaBrowser.Api/Dlna/DlnaServerService.cs@@ -70,24 +70,27 @@ namespace MediaBrowser.Api.Dlnapublic Stream RequestStream { get; set; }}- [Route("/Dlna/{UuId}/mediareceiverregistrar/events", Summary = "Processes an event subscription request")]+ [Route("/Dlna/{UuId}/mediareceiverregistrar/events", "SUBSCRIBE", Summary = "Processes an event subscription request")]+ [Route("/Dlna/{UuId}/mediareceiverregistrar/events", "UNSUBSCRIBE", Summary = "Processes an event subscription request")]public class ProcessMediaReceiverRegistrarEventRequest{- [ApiMember(Name = "UuId", Description = "Server UuId", IsRequired = false, DataType = "string", ParameterType = "path", Verb = "SUBSCRIBE,POST")]+ [ApiMember(Name = "UuId", Description = "Server UuId", IsRequired = false, DataType = "string", ParameterType = "path", Verb = "SUBSCRIBE,UNSUBSCRIBE")]public string UuId { get; set; }}- [Route("/Dlna/{UuId}/contentdirectory/events", Summary = "Processes an event subscription request")]+ [Route("/Dlna/{UuId}/contentdirectory/events", "SUBSCRIBE", Summary = "Processes an event subscription request")]+ [Route("/Dlna/{UuId}/contentdirectory/events", "UNSUBSCRIBE", Summary = "Processes an event subscription request")]public class ProcessContentDirectoryEventRequest{- [ApiMember(Name = "UuId", Description = "Server UuId", IsRequired = false, DataType = "string", ParameterType = "path", Verb = "SUBSCRIBE,POST")]+ [ApiMember(Name = "UuId", Description = "Server UuId", IsRequired = false, DataType = "string", ParameterType = "path", Verb = "SUBSCRIBE,UNSUBSCRIBE")]public string UuId { get; set; }}- [Route("/Dlna/{UuId}/connectionmanager/events", Summary = "Processes an event subscription request")]+ [Route("/Dlna/{UuId}/connectionmanager/events", "SUBSCRIBE", Summary = "Processes an event subscription request")]+ [Route("/Dlna/{UuId}/connectionmanager/events", "UNSUBSCRIBE", Summary = "Processes an event subscription request")]public class ProcessConnectionManagerEventRequest{- [ApiMember(Name = "UuId", Description = "Server UuId", IsRequired = false, DataType = "string", ParameterType = "path", Verb = "SUBSCRIBE,POST")]+ [ApiMember(Name = "UuId", Description = "Server UuId", IsRequired = false, DataType = "string", ParameterType = "path", Verb = "SUBSCRIBE,UNSUBSCRIBE")]public string UuId { get; set; }}@@ -200,17 +203,32 @@ namespace MediaBrowser.Api.Dlna}}- public object Any(ProcessContentDirectoryEventRequest request)+ public object Subscribe(ProcessContentDirectoryEventRequest request){return ProcessEventRequest(_contentDirectory);}- public object Any(ProcessConnectionManagerEventRequest request)+ public object Subscribe(ProcessConnectionManagerEventRequest request){return ProcessEventRequest(_connectionManager);}- public object Any(ProcessMediaReceiverRegistrarEventRequest request)+ public object Subscribe(ProcessMediaReceiverRegistrarEventRequest request)+ {+ return ProcessEventRequest(_mediaReceiverRegistrar);+ }++ public object Unsubscribe(ProcessContentDirectoryEventRequest request)+ {+ return ProcessEventRequest(_contentDirectory);+ }++ public object Unsubscribe(ProcessConnectionManagerEventRequest request)+ {+ return ProcessEventRequest(_connectionManager);+ }++ public object Unsubscribe(ProcessMediaReceiverRegistrarEventRequest request){return ProcessEventRequest(_mediaReceiverRegistrar);}diff --git a/MediaBrowser.Controller/Net/AuthenticatedAttribute.cs b/MediaBrowser.Controller/Net/AuthenticatedAttribute.csindex 81e294069f..6ded3761fc 100644--- a/MediaBrowser.Controller/Net/AuthenticatedAttribute.cs+++ b/MediaBrowser.Controller/Net/AuthenticatedAttribute.cs@@ -1,5 +1,4 @@using System;-using System.Collections.Generic;using MediaBrowser.Model.Services;namespace MediaBrowser.Controller.Net@@ -50,7 +49,7 @@ namespace MediaBrowser.Controller.Netget { return 0; }}- public IEnumerable<string> GetRoles()+ public string[] GetRoles(){return (Roles ?? string.Empty).Split(new []{ ',' }, StringSplitOptions.RemoveEmptyEntries);}@@ -61,6 +60,6 @@ namespace MediaBrowser.Controller.Netbool EscapeParentalControl { get; }bool AllowBeforeStartupWizard { get; }- IEnumerable<string> GetRoles();+ string[] GetRoles();}}diff --git a/MediaBrowser.Controller/Net/IHttpServer.cs b/MediaBrowser.Controller/Net/IHttpServer.csindex f319244dae..f41572b454 100644--- a/MediaBrowser.Controller/Net/IHttpServer.cs+++ b/MediaBrowser.Controller/Net/IHttpServer.cs@@ -13,13 +13,13 @@ namespace MediaBrowser.Controller.Net/// Gets the URL prefix./// </summary>/// <value>The URL prefix.</value>- IEnumerable<string> UrlPrefixes { get; }+ string[] UrlPrefixes { get; }/// <summary>/// Starts the specified server name./// </summary>/// <param name="urlPrefixes">The URL prefixes.</param>- void StartServer(IEnumerable<string> urlPrefixes);+ void StartServer(string[] urlPrefixes);/// <summary>/// Stops this instance.diff --git a/MediaBrowser.Controller/Net/IServerManager.cs b/MediaBrowser.Controller/Net/IServerManager.csindex 202df29824..a84c48c5b1 100644--- a/MediaBrowser.Controller/Net/IServerManager.cs+++ b/MediaBrowser.Controller/Net/IServerManager.cs@@ -15,7 +15,7 @@ namespace MediaBrowser.Controller.Net/// Starts this instance./// </summary>/// <param name="urlPrefixes">The URL prefixes.</param>- void Start(IEnumerable<string> urlPrefixes);+ void Start(string[] urlPrefixes);/// <summary>/// Sends a message to all clients currently connected via a web socketdiff --git a/SharedVersion.cs b/SharedVersion.csindex 2be59ce39b..22a7f2a838 100644--- a/SharedVersion.cs+++ b/SharedVersion.cs@@ -1,3 +1,3 @@using System.Reflection;-[assembly: AssemblyVersion("3.2.30.2")]+[assembly: AssemblyVersion("3.2.30.3")]