From 5a5b48feff3a0b0a660aaaa9bdfd04fd0fe711ed Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 23 Oct 2014 00:26:01 -0400 Subject: added new cabac value --- .../Configuration/ServerConfigurationManager.cs | 7 ++ .../Connect/ConnectManager.cs | 124 ++++++++++++++++----- .../Connect/Validator.cs | 34 ++++++ .../HttpServer/HttpListenerHost.cs | 4 +- .../Library/CoreResolutionIgnoreRule.cs | 1 - .../Library/LibraryManager.cs | 51 ++++----- .../Library/Resolvers/Movies/MovieResolver.cs | 15 +-- .../Localization/JavaScript/javascript.json | 7 +- .../Localization/Server/server.json | 3 +- .../MediaBrowser.Server.Implementations.csproj | 1 + .../Persistence/SqliteItemRepository.cs | 30 ++++- .../Persistence/SqliteMediaStreamsRepository.cs | 43 ++++++- .../Session/SessionManager.cs | 64 +++++++++++ 13 files changed, 313 insertions(+), 71 deletions(-) create mode 100644 MediaBrowser.Server.Implementations/Connect/Validator.cs (limited to 'MediaBrowser.Server.Implementations') diff --git a/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs b/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs index 1370b2bf2..4abe56aca 100644 --- a/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs +++ b/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs @@ -3,6 +3,8 @@ using MediaBrowser.Common.Events; using MediaBrowser.Common.Implementations.Configuration; using MediaBrowser.Controller; using MediaBrowser.Controller.Configuration; +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Model.Configuration; @@ -214,6 +216,11 @@ namespace MediaBrowser.Server.Implementations.Configuration DisableMetadataService(typeof(Movie), Configuration, service); DisableMetadataService(typeof(Episode), Configuration, service); DisableMetadataService(typeof(Series), Configuration, service); + DisableMetadataService(typeof(Season), Configuration, service); + DisableMetadataService(typeof(MusicArtist), Configuration, service); + DisableMetadataService(typeof(MusicAlbum), Configuration, service); + DisableMetadataService(typeof(MusicVideo), Configuration, service); + DisableMetadataService(typeof(Video), Configuration, service); } private void DisableMetadataService(Type type, ServerConfiguration config, string service) diff --git a/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs b/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs index 88f934d25..f468606ed 100644 --- a/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs +++ b/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs @@ -141,6 +141,8 @@ namespace MediaBrowser.Server.Implementations.Connect try { + var localAddress = _appHost.GetSystemInfo().LocalAddress; + var hasExistingRecord = !string.IsNullOrWhiteSpace(ConnectServerId) && !string.IsNullOrWhiteSpace(ConnectAccessKey); @@ -150,11 +152,12 @@ namespace MediaBrowser.Server.Implementations.Connect { try { - await UpdateServerRegistration(wanApiAddress).ConfigureAwait(false); + await UpdateServerRegistration(wanApiAddress, localAddress).ConfigureAwait(false); } catch (HttpException ex) { - if (!ex.StatusCode.HasValue || !new[] { HttpStatusCode.NotFound, HttpStatusCode.Unauthorized }.Contains(ex.StatusCode.Value)) + if (!ex.StatusCode.HasValue || + !new[] { HttpStatusCode.NotFound, HttpStatusCode.Unauthorized }.Contains(ex.StatusCode.Value)) { throw; } @@ -165,7 +168,7 @@ namespace MediaBrowser.Server.Implementations.Connect if (createNewRegistration) { - await CreateServerRegistration(wanApiAddress).ConfigureAwait(false); + await CreateServerRegistration(wanApiAddress, localAddress).ConfigureAwait(false); } await RefreshAuthorizationsInternal(true, CancellationToken.None).ConfigureAwait(false); @@ -176,7 +179,7 @@ namespace MediaBrowser.Server.Implementations.Connect } } - private async Task CreateServerRegistration(string wanApiAddress) + private async Task CreateServerRegistration(string wanApiAddress, string localAddress) { var url = "Servers"; url = GetConnectUrl(url); @@ -188,6 +191,11 @@ namespace MediaBrowser.Server.Implementations.Connect {"systemId", _appHost.SystemId} }; + if (!string.IsNullOrWhiteSpace(localAddress)) + { + postData["localAddress"] = localAddress; + } + using (var stream = await _httpClient.Post(url, postData, CancellationToken.None).ConfigureAwait(false)) { var data = _json.DeserializeFromStream(stream); @@ -199,24 +207,31 @@ namespace MediaBrowser.Server.Implementations.Connect } } - private async Task UpdateServerRegistration(string wanApiAddress) + private async Task UpdateServerRegistration(string wanApiAddress, string localAddress) { var url = "Servers"; url = GetConnectUrl(url); url += "?id=" + ConnectServerId; + var postData = new Dictionary + { + {"name", _appHost.FriendlyName}, + {"url", wanApiAddress}, + {"systemId", _appHost.SystemId} + }; + + if (!string.IsNullOrWhiteSpace(localAddress)) + { + postData["localAddress"] = localAddress; + } + var options = new HttpRequestOptions { Url = url, CancellationToken = CancellationToken.None }; - options.SetPostData(new Dictionary - { - {"name", _appHost.FriendlyName}, - {"url", wanApiAddress}, - {"systemId", _appHost.SystemId} - }); + options.SetPostData(postData); SetServerAccessToken(options); @@ -405,15 +420,46 @@ namespace MediaBrowser.Server.Implementations.Connect throw new ArgumentNullException("connectUsername"); } - var connectUser = await GetConnectUser(new ConnectUserQuery + string connectUserId = null; + var result = new UserLinkResult(); + + try { - Name = connectUsername + var connectUser = await GetConnectUser(new ConnectUserQuery + { + Name = connectUsername - }, CancellationToken.None).ConfigureAwait(false); + }, CancellationToken.None).ConfigureAwait(false); - if (!connectUser.IsActive) + if (!connectUser.IsActive) + { + throw new ArgumentException("The Media Browser account has been disabled."); + } + + connectUserId = connectUser.Id; + result.GuestDisplayName = connectUser.Name; + } + catch (HttpException ex) { - throw new ArgumentException("The Media Browser account has been disabled."); + if (!ex.StatusCode.HasValue || + ex.StatusCode.Value != HttpStatusCode.NotFound || + !Validator.EmailIsValid(connectUsername)) + { + throw; + } + } + + var sendingUser = GetUser(sendingUserId); + var requesterUserName = sendingUser.ConnectUserName; + + if (string.IsNullOrWhiteSpace(requesterUserName)) + { + requesterUserName = sendingUser.Name; + } + + if (string.IsNullOrWhiteSpace(connectUserId)) + { + return await SendNewUserInvitation(requesterUserName, connectUsername).ConfigureAwait(false); } var url = GetConnectUrl("ServerAuthorizations"); @@ -425,18 +471,11 @@ namespace MediaBrowser.Server.Implementations.Connect }; var accessToken = Guid.NewGuid().ToString("N"); - var sendingUser = GetUser(sendingUserId); - - var requesterUserName = sendingUser.ConnectUserName; - if (string.IsNullOrWhiteSpace(requesterUserName)) - { - requesterUserName = sendingUser.Name; - } var postData = new Dictionary { {"serverId", ConnectServerId}, - {"userId", connectUser.Id}, + {"userId", connectUserId}, {"userType", "Guest"}, {"accessToken", accessToken}, {"requesterUserName", requesterUserName} @@ -446,8 +485,6 @@ namespace MediaBrowser.Server.Implementations.Connect SetServerAccessToken(options); - var result = new UserLinkResult(); - // No need to examine the response using (var stream = (await _httpClient.Post(options).ConfigureAwait(false)).Content) { @@ -461,6 +498,36 @@ namespace MediaBrowser.Server.Implementations.Connect return result; } + private async Task SendNewUserInvitation(string fromName, string email) + { + var url = GetConnectUrl("users/invite"); + + var options = new HttpRequestOptions + { + Url = url, + CancellationToken = CancellationToken.None + }; + + var postData = new Dictionary + { + {"email", email}, + {"requesterUserName", fromName} + }; + + options.SetPostData(postData); + + // No need to examine the response + using (var stream = (await _httpClient.Post(options).ConfigureAwait(false)).Content) + { + } + + return new UserLinkResult + { + IsNewUserInvitation = true, + GuestDisplayName = email + }; + } + public Task RemoveConnect(string userId) { var user = GetUser(userId); @@ -586,6 +653,9 @@ namespace MediaBrowser.Server.Implementations.Connect if (connectEntry == null) { + var deleteUser = user.ConnectLinkType.HasValue && + user.ConnectLinkType.Value == UserLinkType.Guest; + user.ConnectUserId = null; user.ConnectAccessKey = null; user.ConnectUserName = null; @@ -593,7 +663,7 @@ namespace MediaBrowser.Server.Implementations.Connect await _userManager.UpdateUser(user).ConfigureAwait(false); - if (user.ConnectLinkType.HasValue && user.ConnectLinkType.Value == UserLinkType.Guest) + if (deleteUser) { _logger.Debug("Deleting guest user {0}", user.Name); await _userManager.DeleteUser(user).ConfigureAwait(false); diff --git a/MediaBrowser.Server.Implementations/Connect/Validator.cs b/MediaBrowser.Server.Implementations/Connect/Validator.cs new file mode 100644 index 000000000..b217da32a --- /dev/null +++ b/MediaBrowser.Server.Implementations/Connect/Validator.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; + +namespace MediaBrowser.Server.Implementations.Connect +{ + public static class Validator + { + static Regex ValidEmailRegex = CreateValidEmailRegex(); + + /// + /// Taken from http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx + /// + /// + private static Regex CreateValidEmailRegex() + { + string validEmailPattern = @"^(?!\.)(""([^""\r\\]|\\[""\r\\])*""|" + + @"([-a-z0-9!#$%&'*+/=?^_`{|}~]|(? - /// Resolves a path into a BaseItem - /// - /// The file info. - /// The directory service. - /// The parent. - /// BaseItem. - /// fileInfo - public BaseItem ResolvePath(FileSystemInfo fileInfo, IDirectoryService directoryService, Folder parent = null) + public BaseItem ResolvePath(FileSystemInfo fileInfo, IDirectoryService directoryService, Folder parent = null, string collectionType = null) { if (fileInfo == null) { @@ -554,7 +546,8 @@ namespace MediaBrowser.Server.Implementations.Library { Parent = parent, Path = fileInfo.FullName, - FileInfo = fileInfo + FileInfo = fileInfo, + CollectionType = collectionType }; // Return null if ignore rules deem that we should do so @@ -622,15 +615,7 @@ namespace MediaBrowser.Server.Implementations.Library return !args.ContainsFileSystemEntryByName(".ignore"); } - /// - /// Resolves a set of files into a list of BaseItem - /// - /// - /// The files. - /// The directory service. - /// The parent. - /// List{``0}. - public List ResolvePaths(IEnumerable files, IDirectoryService directoryService, Folder parent) + public List ResolvePaths(IEnumerable files, IDirectoryService directoryService, Folder parent, string collectionType = null) where T : BaseItem { var list = new List(); @@ -639,7 +624,7 @@ namespace MediaBrowser.Server.Implementations.Library { try { - var item = ResolvePath(f, directoryService, parent) as T; + var item = ResolvePath(f, directoryService, parent, collectionType) as T; if (item != null) { @@ -1190,6 +1175,20 @@ namespace MediaBrowser.Server.Implementations.Library return item; } + public BaseItem GetMemoryItemById(Guid id) + { + if (id == Guid.Empty) + { + throw new ArgumentNullException("id"); + } + + BaseItem item; + + LibraryItemsCache.TryGetValue(id, out item); + + return item; + } + /// /// Gets the intros. /// @@ -1497,14 +1496,10 @@ namespace MediaBrowser.Server.Implementations.Library return null; } - var collectionTypes = _userManager.Users - .Select(i => i.RootFolder) - .Distinct() - .SelectMany(i => i.Children) + var collectionTypes = GetUserRootFolder().Children .OfType() - .Where(i => string.Equals(i.Path, item.Path, StringComparison.OrdinalIgnoreCase) || i.PhysicalLocations.Contains(item.Path)) + .Where(i => !string.IsNullOrEmpty(i.CollectionType) && (string.Equals(i.Path, item.Path, StringComparison.OrdinalIgnoreCase) || i.PhysicalLocations.Contains(item.Path))) .Select(i => i.CollectionType) - .Where(i => !string.IsNullOrEmpty(i)) .Distinct() .ToList(); diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs index 7f15dce2d..231b807d8 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs @@ -82,29 +82,29 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies { if (string.Equals(collectionType, CollectionType.Trailers, StringComparison.OrdinalIgnoreCase)) { - return FindMovie(args.Path, args.Parent, args.FileSystemChildren.ToList(), args.DirectoryService, false, false); + return FindMovie(args.Path, args.Parent, args.FileSystemChildren.ToList(), args.DirectoryService, false, false, collectionType); } if (string.Equals(collectionType, CollectionType.MusicVideos, StringComparison.OrdinalIgnoreCase)) { - return FindMovie(args.Path, args.Parent, args.FileSystemChildren.ToList(), args.DirectoryService, false, false); + return FindMovie(args.Path, args.Parent, args.FileSystemChildren.ToList(), args.DirectoryService, false, false, collectionType); } if (string.Equals(collectionType, CollectionType.AdultVideos, StringComparison.OrdinalIgnoreCase)) { - return FindMovie