From 2d06095447b972c8c7239277428e2c67c8b7ca86 Mon Sep 17 00:00:00 2001 From: LukePulverenti Date: Mon, 25 Feb 2013 22:43:04 -0500 Subject: plugin security fixes and other abstractions --- MediaBrowser.Common/Kernel/BaseKernel.cs | 60 +++----------------------- MediaBrowser.Common/Kernel/IApplicationHost.cs | 42 ++++++------------ MediaBrowser.Common/Kernel/IKernel.cs | 18 -------- MediaBrowser.Common/Kernel/TcpManager.cs | 6 +-- 4 files changed, 21 insertions(+), 105 deletions(-) (limited to 'MediaBrowser.Common/Kernel') diff --git a/MediaBrowser.Common/Kernel/BaseKernel.cs b/MediaBrowser.Common/Kernel/BaseKernel.cs index eb5381e206..5b8da5d094 100644 --- a/MediaBrowser.Common/Kernel/BaseKernel.cs +++ b/MediaBrowser.Common/Kernel/BaseKernel.cs @@ -40,9 +40,6 @@ namespace MediaBrowser.Common.Kernel internal void OnConfigurationUpdated() { EventHelper.QueueEventIfNotNull(ConfigurationUpdated, this, EventArgs.Empty, Logger); - - // Notify connected clients - TcpManager.SendWebSocketMessage("ConfigurationUpdated", Configuration); } #endregion @@ -140,12 +137,6 @@ namespace MediaBrowser.Common.Kernel } } - /// - /// Gets a value indicating whether this instance is first run. - /// - /// true if this instance is first run; otherwise, false. - public bool IsFirstRun { get; private set; } - /// /// Gets or sets a value indicating whether this instance has changes that require the entire application to restart. /// @@ -176,12 +167,6 @@ namespace MediaBrowser.Common.Kernel /// The TCP manager. public TcpManager TcpManager { get; private set; } - /// - /// Gets the rest services. - /// - /// The rest services. - public IEnumerable RestServices { get; private set; } - /// /// Gets the UDP server port number. /// This can't be configurable because then the user would have to configure their client to discover the server. @@ -280,19 +265,7 @@ namespace MediaBrowser.Common.Kernel /// Initializes the Kernel /// /// Task. - public Task Init() - { - IsFirstRun = !File.Exists(ApplicationPaths.SystemConfigurationFilePath); - - // Performs initializations that can be reloaded at anytime - return Reload(); - } - - /// - /// Performs initializations that can be reloaded at anytime - /// - /// Task. - public async Task Reload() + public async Task Init() { OnReloadBeginning(); @@ -312,8 +285,6 @@ namespace MediaBrowser.Common.Kernel // Set these to null so that they can be lazy loaded again Configuration = null; - Logger.Info("Version {0} initializing", ApplicationVersion); - await OnConfigurationLoaded().ConfigureAwait(false); FindParts(); @@ -348,7 +319,6 @@ namespace MediaBrowser.Common.Kernel /// protected virtual void FindParts() { - RestServices = ApplicationHost.GetExports(); WebSocketListeners = ApplicationHost.GetExports(); Plugins = ApplicationHost.GetExports(); } @@ -425,18 +395,6 @@ namespace MediaBrowser.Common.Kernel } } - /// - /// Gets the current application version - /// - /// The application version. - public Version ApplicationVersion - { - get - { - return GetType().Assembly.GetName().Version; - } - } - /// /// Performs the pending restart. /// @@ -445,7 +403,9 @@ namespace MediaBrowser.Common.Kernel { if (HasPendingRestart) { - RestartApplication(); + Logger.Info("Restarting the application"); + + ApplicationHost.Restart(); } else { @@ -453,16 +413,6 @@ namespace MediaBrowser.Common.Kernel } } - /// - /// Restarts the application. - /// - protected void RestartApplication() - { - Logger.Info("Restarting the application"); - - ApplicationHost.Restart(); - } - /// /// Gets the system status. /// @@ -472,7 +422,7 @@ namespace MediaBrowser.Common.Kernel return new SystemInfo { HasPendingRestart = HasPendingRestart, - Version = ApplicationVersion.ToString(), + Version = ApplicationHost.ApplicationVersion.ToString(), IsNetworkDeployed = ApplicationHost.CanSelfUpdate, WebSocketPortNumber = TcpManager.WebSocketPortNumber, SupportsNativeWebSocket = TcpManager.SupportsNativeWebSocket, diff --git a/MediaBrowser.Common/Kernel/IApplicationHost.cs b/MediaBrowser.Common/Kernel/IApplicationHost.cs index 4b564581b4..af9b039bc0 100644 --- a/MediaBrowser.Common/Kernel/IApplicationHost.cs +++ b/MediaBrowser.Common/Kernel/IApplicationHost.cs @@ -21,6 +21,12 @@ namespace MediaBrowser.Common.Kernel /// void ReloadLogger(); + /// + /// Gets the application version. + /// + /// The application version. + Version ApplicationVersion { get; } + /// /// Gets the log file path. /// @@ -33,11 +39,17 @@ namespace MediaBrowser.Common.Kernel /// true if this instance can self update; otherwise, false. bool CanSelfUpdate { get; } + /// + /// Gets a value indicating whether this instance is first run. + /// + /// true if this instance is first run; otherwise, false. + bool IsFirstRun { get; } + /// /// Gets the failed assemblies. /// /// The failed assemblies. - IEnumerable FailedAssemblies { get; } + List FailedAssemblies { get; } /// /// Gets all concrete types. @@ -72,34 +84,6 @@ namespace MediaBrowser.Common.Kernel /// System.Object. object CreateInstance(Type type); - /// - /// Registers a service that other classes can use as a dependancy. - /// - /// - /// The obj. - void RegisterSingleInstance(T obj) where T : class; - - /// - /// Registers the single instance. - /// - /// - /// The func. - void RegisterSingleInstance(Func func) where T : class; - - /// - /// Registers the specified func. - /// - /// - /// The func. - void Register(Func func) where T : class; - - /// - /// Registers the specified service type. - /// - /// Type of the service. - /// Type of the implementation. - void Register(Type serviceType, Type implementation); - /// /// Resolves this instance. /// diff --git a/MediaBrowser.Common/Kernel/IKernel.cs b/MediaBrowser.Common/Kernel/IKernel.cs index fb629a24df..06c2e7b64c 100644 --- a/MediaBrowser.Common/Kernel/IKernel.cs +++ b/MediaBrowser.Common/Kernel/IKernel.cs @@ -37,12 +37,6 @@ namespace MediaBrowser.Common.Kernel /// Task. Task Init(); - /// - /// Reloads this instance. - /// - /// Task. - Task Reload(); - /// /// Gets or sets a value indicating whether this instance has pending kernel reload. /// @@ -106,12 +100,6 @@ namespace MediaBrowser.Common.Kernel /// The HTTP server URL prefix. string HttpServerUrlPrefix { get; } - /// - /// Gets a value indicating whether this instance is first run. - /// - /// true if this instance is first run; otherwise, false. - bool IsFirstRun { get; } - /// /// Gets the TCP manager. /// @@ -139,12 +127,6 @@ namespace MediaBrowser.Common.Kernel /// event EventHandler ConfigurationUpdated; - /// - /// Gets the rest services. - /// - /// The rest services. - IEnumerable RestServices { get; } - /// /// Notifies the pending restart. /// diff --git a/MediaBrowser.Common/Kernel/TcpManager.cs b/MediaBrowser.Common/Kernel/TcpManager.cs index 1c76b42f96..2dfed501af 100644 --- a/MediaBrowser.Common/Kernel/TcpManager.cs +++ b/MediaBrowser.Common/Kernel/TcpManager.cs @@ -39,7 +39,7 @@ namespace MediaBrowser.Common.Kernel /// /// The json serializer. private readonly IJsonSerializer _jsonSerializer; - + /// /// This subscribes to HttpListener requests and finds the appropriate BaseHandler to process it /// @@ -133,7 +133,7 @@ namespace MediaBrowser.Common.Kernel _applicationHost = applicationHost; _networkManager = networkManager; - if (kernel.IsFirstRun) + if (applicationHost.IsFirstRun) { RegisterServerWithAdministratorAccess(); } @@ -215,7 +215,7 @@ namespace MediaBrowser.Common.Kernel /// The instance containing the event data. void HttpServer_WebSocketConnected(object sender, WebSocketConnectEventArgs e) { - var connection = new WebSocketConnection(e.WebSocket, e.Endpoint, ProcessWebSocketMessageReceived, _jsonSerializer, _logger); + var connection = new WebSocketConnection(e.WebSocket, e.Endpoint, _jsonSerializer, _logger) { OnReceive = ProcessWebSocketMessageReceived }; _webSocketConnections.Add(connection); } -- cgit v1.2.3