Skip to content

Commit 064802c

Browse files
authoredApr 23, 2018
Merge pull request #3243 from MediaBrowser/dev
move subdb to plugin
2 parents 5888e02 + a169be2 commit 064802c

File tree

25 files changed

+221
-276
lines changed

25 files changed

+221
-276
lines changed
 

‎Emby.Server.Implementations/ApplicationHost.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,7 @@ protected void RegisterResources()
10621062
RegisterSingleInstance<IAuthorizationContext>(authContext);
10631063
RegisterSingleInstance<ISessionContext>(new SessionContext(UserManager, authContext, SessionManager));
10641064

1065-
AuthService = new AuthService(UserManager, authContext, ServerConfigurationManager, ConnectManager, SessionManager, DeviceManager, NetworkManager);
1065+
AuthService = new AuthService(UserManager, authContext, ServerConfigurationManager, ConnectManager, SessionManager, NetworkManager);
10661066
RegisterSingleInstance<IAuthService>(AuthService);
10671067

10681068
SubtitleEncoder = new SubtitleEncoder(LibraryManager, LogManager.GetLogger("SubtitleEncoder"), ApplicationPaths, FileSystemManager, MediaEncoder, JsonSerializer, HttpClient, MediaSourceManager, MemoryStreamFactory, ProcessFactory, textEncoding);

‎Emby.Server.Implementations/HttpServer/HttpListenerHost.cs

+15-10
Original file line numberDiff line numberDiff line change
@@ -264,16 +264,20 @@ private int GetStatusCode(Exception ex)
264264
return statusCode;
265265
}
266266

267-
private void ErrorHandler(Exception ex, IRequest httpReq, bool logException = true)
267+
private void ErrorHandler(Exception ex, IRequest httpReq, bool logExceptionStackTrace, bool logExceptionMessage)
268268
{
269269
try
270270
{
271271
ex = GetActualException(ex);
272272

273-
if (logException)
273+
if (logExceptionStackTrace)
274274
{
275275
_logger.ErrorException("Error processing request", ex);
276276
}
277+
else if (logExceptionMessage)
278+
{
279+
_logger.Error(ex.Message);
280+
}
277281

278282
var httpRes = httpReq.Response;
279283

@@ -646,33 +650,34 @@ protected async Task RequestHandler(IHttpRequest httpReq, string urlString, stri
646650
}
647651
else
648652
{
649-
ErrorHandler(new FileNotFoundException(), httpReq, false);
653+
ErrorHandler(new FileNotFoundException(), httpReq, false, false);
650654
}
651655
}
652656
catch (OperationCanceledException ex)
653657
{
654-
ErrorHandler(ex, httpReq, false);
658+
ErrorHandler(ex, httpReq, false, false);
655659
}
656660

657661
catch (IOException ex)
658662
{
659-
var logException = false;
660-
661-
ErrorHandler(ex, httpReq, logException);
663+
ErrorHandler(ex, httpReq, false, false);
662664
}
663665

664666
catch (SocketException ex)
665667
{
666-
var logException = false;
668+
ErrorHandler(ex, httpReq, false, false);
669+
}
667670

668-
ErrorHandler(ex, httpReq, logException);
671+
catch (SecurityException ex)
672+
{
673+
ErrorHandler(ex, httpReq, false, true);
669674
}
670675

671676
catch (Exception ex)
672677
{
673678
var logException = !string.Equals(ex.GetType().Name, "SocketException", StringComparison.OrdinalIgnoreCase);
674679

675-
ErrorHandler(ex, httpReq, logException);
680+
ErrorHandler(ex, httpReq, logException, false);
676681
}
677682
finally
678683
{

‎Emby.Server.Implementations/HttpServer/IHttpListener.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public interface IHttpListener : IDisposable
1313
/// Gets or sets the error handler.
1414
/// </summary>
1515
/// <value>The error handler.</value>
16-
Action<Exception, IRequest, bool> ErrorHandler { get; set; }
16+
Action<Exception, IRequest, bool, bool> ErrorHandler { get; set; }
1717

1818
/// <summary>
1919
/// Gets or sets the request handler.

‎Emby.Server.Implementations/HttpServer/Security/AuthService.cs

+2-20
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@ public class AuthService : IAuthService
1717
{
1818
private readonly IServerConfigurationManager _config;
1919

20-
public AuthService(IUserManager userManager, IAuthorizationContext authorizationContext, IServerConfigurationManager config, IConnectManager connectManager, ISessionManager sessionManager, IDeviceManager deviceManager, INetworkManager networkManager)
20+
public AuthService(IUserManager userManager, IAuthorizationContext authorizationContext, IServerConfigurationManager config, IConnectManager connectManager, ISessionManager sessionManager, INetworkManager networkManager)
2121
{
2222
AuthorizationContext = authorizationContext;
2323
_config = config;
24-
DeviceManager = deviceManager;
2524
SessionManager = sessionManager;
2625
ConnectManager = connectManager;
2726
UserManager = userManager;
@@ -32,7 +31,6 @@ public AuthService(IUserManager userManager, IAuthorizationContext authorization
3231
public IAuthorizationContext AuthorizationContext { get; private set; }
3332
public IConnectManager ConnectManager { get; private set; }
3433
public ISessionManager SessionManager { get; private set; }
35-
public IDeviceManager DeviceManager { get; private set; }
3634
public INetworkManager NetworkManager { get; private set; }
3735

3836
/// <summary>
@@ -130,17 +128,6 @@ private void ValidateUserAccess(User user, IRequest request,
130128
SecurityExceptionType = SecurityExceptionType.ParentalControl
131129
};
132130
}
133-
134-
if (!string.IsNullOrEmpty(auth.DeviceId))
135-
{
136-
if (!DeviceManager.CanAccessDevice(user, auth.DeviceId))
137-
{
138-
throw new SecurityException("User is not allowed access from this device.")
139-
{
140-
SecurityExceptionType = SecurityExceptionType.ParentalControl
141-
};
142-
}
143-
}
144131
}
145132

146133
private bool IsExemptFromAuthenticationToken(AuthorizationInfo auth, IAuthenticationAttributes authAttribtues, IRequest request)
@@ -243,16 +230,11 @@ private void ValidateSecurityToken(IRequest request, string token)
243230

244231
var info = GetTokenInfo(request);
245232

246-
if (info == null)
233+
if (info == null || !info.IsActive)
247234
{
248235
throw new SecurityException("Access token is invalid or expired.");
249236
}
250237

251-
if (!info.IsActive)
252-
{
253-
throw new SecurityException("Access token has expired.");
254-
}
255-
256238
//if (!string.IsNullOrEmpty(info.UserId))
257239
//{
258240
// var user = _userManager.GetUserById(info.UserId);

‎Emby.Server.Implementations/HttpServer/SocketSharp/WebSocketSharpListener.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public WebSocketSharpListener(ILogger logger, X509Certificate certificate, IMemo
5252
_disposeCancellationToken = _disposeCancellationTokenSource.Token;
5353
}
5454

55-
public Action<Exception, IRequest, bool> ErrorHandler { get; set; }
55+
public Action<Exception, IRequest, bool, bool> ErrorHandler { get; set; }
5656
public Func<IHttpRequest, string, string, string, CancellationToken, Task> RequestHandler { get; set; }
5757

5858
public Action<WebSocketConnectingEventArgs> WebSocketConnecting { get; set; }
@@ -110,7 +110,7 @@ private Task InitTask(HttpListenerContext context, CancellationToken cancellatio
110110
_logger.ErrorException("Error processing request", ex);
111111

112112
httpReq = httpReq ?? GetRequest(context);
113-
ErrorHandler(ex, httpReq, true);
113+
ErrorHandler(ex, httpReq, true, true);
114114
return Task.FromResult(true);
115115
}
116116

‎Emby.Server.Implementations/HttpServer/SocketSharp/WebSocketSharpResponse.cs

+14-21
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
using MediaBrowser.Model.IO;
99
using MediaBrowser.Model.Logging;
1010
using MediaBrowser.Model.Services;
11-
using SocketHttpListener.Net;
1211
using HttpListenerResponse = SocketHttpListener.Net.HttpListenerResponse;
1312
using IHttpResponse = MediaBrowser.Model.Services.IHttpResponse;
1413
using IRequest = MediaBrowser.Model.Services.IRequest;
14+
using System.Net.Sockets;
1515

1616
namespace Emby.Server.Implementations.HttpServer.SocketSharp
1717
{
@@ -97,33 +97,26 @@ public void Close()
9797

9898
try
9999
{
100-
CloseOutputStream(this._response);
100+
var response = this._response;
101+
102+
var outputStream = response.OutputStream;
103+
104+
// This is needed with compression
105+
outputStream.Flush();
106+
outputStream.Dispose();
107+
108+
response.Close();
109+
}
110+
catch (SocketException)
111+
{
101112
}
102113
catch (Exception ex)
103114
{
104-
_logger.ErrorException("Error closing HttpListener output stream", ex);
115+
_logger.ErrorException("Error in HttpListenerResponseWrapper: " + ex.Message, ex);
105116
}
106117
}
107118
}
108119

109-
public void CloseOutputStream(HttpListenerResponse response)
110-
{
111-
try
112-
{
113-
var outputStream = response.OutputStream;
114-
115-
// This is needed with compression
116-
outputStream.Flush();
117-
outputStream.Dispose();
118-
119-
response.Close();
120-
}
121-
catch (Exception ex)
122-
{
123-
_logger.ErrorException("Error in HttpListenerResponseWrapper: " + ex.Message, ex);
124-
}
125-
}
126-
127120
public bool IsClosed
128121
{
129122
get;

‎Emby.Server.Implementations/Library/UserManager.cs

+56
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
using MediaBrowser.Model.Cryptography;
3030
using MediaBrowser.Model.IO;
3131
using MediaBrowser.Controller.Authentication;
32+
using MediaBrowser.Controller.Security;
33+
using MediaBrowser.Controller.Devices;
34+
using MediaBrowser.Controller.Session;
35+
using MediaBrowser.Controller.Plugins;
3236

3337
namespace Emby.Server.Implementations.Library
3438
{
@@ -1219,4 +1223,56 @@ private void UpdateConfiguration(User user, UserConfiguration config, bool fireE
12191223
}
12201224
}
12211225
}
1226+
1227+
public class DeviceAccessEntryPoint : IServerEntryPoint
1228+
{
1229+
private IUserManager _userManager;
1230+
private IAuthenticationRepository _authRepo;
1231+
private IDeviceManager _deviceManager;
1232+
private ISessionManager _sessionManager;
1233+
1234+
public DeviceAccessEntryPoint(IUserManager userManager, IAuthenticationRepository authRepo, IDeviceManager deviceManager, ISessionManager sessionManager)
1235+
{
1236+
_userManager = userManager;
1237+
_authRepo = authRepo;
1238+
_deviceManager = deviceManager;
1239+
_sessionManager = sessionManager;
1240+
}
1241+
1242+
public void Run()
1243+
{
1244+
_userManager.UserPolicyUpdated += _userManager_UserPolicyUpdated;
1245+
}
1246+
1247+
private void _userManager_UserPolicyUpdated(object sender, GenericEventArgs<User> e)
1248+
{
1249+
var user = e.Argument;
1250+
if (!user.Policy.EnableAllDevices)
1251+
{
1252+
UpdateDeviceAccess(user);
1253+
}
1254+
}
1255+
1256+
private void UpdateDeviceAccess(User user)
1257+
{
1258+
var existing = _authRepo.Get(new AuthenticationInfoQuery
1259+
{
1260+
UserId = user.Id.ToString("N")
1261+
1262+
}).Items;
1263+
1264+
foreach (var authInfo in existing)
1265+
{
1266+
if (!string.IsNullOrEmpty(authInfo.DeviceId) && !_deviceManager.CanAccessDevice(user, authInfo.DeviceId))
1267+
{
1268+
_sessionManager.Logout(authInfo.AccessToken);
1269+
}
1270+
}
1271+
}
1272+
1273+
public void Dispose()
1274+
{
1275+
1276+
}
1277+
}
12221278
}

‎MediaBrowser.Controller/Entities/BaseItem.cs

+7-3
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ protected BaseItem()
6868
/// The supported image extensions
6969
/// </summary>
7070
public static readonly string[] SupportedImageExtensions = { ".png", ".jpg", ".jpeg", ".tbn", ".gif" };
71-
7271
public static readonly List<string> SupportedImageExtensionsList = SupportedImageExtensions.ToList();
7372

7473
/// <summary>
@@ -501,6 +500,11 @@ public bool IsMetadataFetcherEnabled(LibraryOptions libraryOptions, string name)
501500

502501
public bool IsImageFetcherEnabled(LibraryOptions libraryOptions, string name)
503502
{
503+
if (this is Channel)
504+
{
505+
// hack alert
506+
return true;
507+
}
504508
if (SourceType == SourceType.Channel)
505509
{
506510
// hack alert
@@ -662,7 +666,7 @@ public virtual string[] PhysicalLocations
662666
{
663667
if (!IsFileProtocol)
664668
{
665-
return new string[] {};
669+
return new string[] { };
666670
}
667671

668672
return new[] { Path };
@@ -1443,7 +1447,7 @@ public async Task<ItemUpdateType> RefreshMetadata(MetadataRefreshOptions options
14431447
[IgnoreDataMember]
14441448
protected virtual bool SupportsOwnedItems
14451449
{
1446-
get { return IsFolder || !ParentId.Equals(Guid.Empty); }
1450+
get { return !ParentId.Equals(Guid.Empty) && IsFileProtocol; }
14471451
}
14481452

14491453
[IgnoreDataMember]

‎MediaBrowser.Model/Configuration/LibraryOptions.cs

+38
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using MediaBrowser.Model.Entities;
23

34
namespace MediaBrowser.Model.Configuration
45
{
@@ -94,13 +95,50 @@ public class TypeOptions
9495

9596
public string[] ImageFetchers { get; set; }
9697
public string[] ImageFetcherOrder { get; set; }
98+
public ImageOption[] ImageOptions { get; set; }
99+
100+
public int GetLimit(ImageType type)
101+
{
102+
ImageOption option = null;
103+
foreach (ImageOption i in ImageOptions)
104+
{
105+
if (i.Type == type)
106+
{
107+
option = i;
108+
break;
109+
}
110+
}
111+
112+
return option == null ? 1 : option.Limit;
113+
}
114+
115+
public int GetMinWidth(ImageType type)
116+
{
117+
ImageOption option = null;
118+
foreach (ImageOption i in ImageOptions)
119+
{
120+
if (i.Type == type)
121+
{
122+
option = i;
123+
break;
124+
}
125+
}
126+
127+
return option == null ? 0 : option.MinWidth;
128+
}
129+
130+
public bool IsEnabled(ImageType type)
131+
{
132+
return GetLimit(type) > 0;
133+
}
97134

98135
public TypeOptions()
99136
{
100137
MetadataFetchers = new string[] {};
101138
MetadataFetcherOrder = new string[] {};
102139
ImageFetchers = new string[] {};
103140
ImageFetcherOrder = new string[] {};
141+
ImageOptions = new ImageOption[] {};
104142
}
105143
}
106144
}

0 commit comments

Comments
 (0)