Commit f7c024d9 authored by Tobias's avatar Tobias

restructure server browsing to shared sources

split everything by service so services are more easily to disable/enable
parent a28df897
/*****************************************************************************
* VLCLocalNetworkServiceBrowserFTP.h
* VLC for iOS
*****************************************************************************
* Copyright (c) 2015 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Tobias Conradi <videolan # tobias-conradi.de>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#import "VLCLocalNetworkServiceBrowserNetService.h"
#import "VLCLocalNetworkServiceNetService.h"
NS_ASSUME_NONNULL_BEGIN
@interface VLCLocalNetworkServiceBrowserFTP : VLCLocalNetworkServiceBrowserNetService
- (instancetype)initWithName:(NSString *)name serviceType:(NSString *)serviceType domain:(NSString *)domain NS_UNAVAILABLE;
- (instancetype)init NS_DESIGNATED_INITIALIZER;
@end
extern NSString *const VLCNetworkServerProtocolIdentifierFTP;
@interface VLCLocalNetworkServiceFTP : VLCLocalNetworkServiceNetService
@end
NS_ASSUME_NONNULL_END
/*****************************************************************************
* VLCLocalNetworkServiceBrowserFTP.m
* VLC for iOS
*****************************************************************************
* Copyright (c) 2015 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Tobias Conradi <videolan # tobias-conradi.de>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#import "VLCLocalNetworkServiceBrowserFTP.h"
#import "VLCNetworkServerLoginInformation.h"
@implementation VLCLocalNetworkServiceBrowserFTP
- (instancetype)init {
return [super initWithName:@"File Transfer Protocol (FTP)"
serviceType:@"_ftp._tcp."
domain:@""];
}
- (VLCLocalNetworkServiceNetService *)localServiceForNetService:(NSNetService *)netService {
return [[VLCLocalNetworkServiceFTP alloc] initWithNetService:netService];
}
@end
NSString *const VLCNetworkServerProtocolIdentifierFTP = @"ftp";
@implementation VLCLocalNetworkServiceFTP
- (UIImage *)icon {
return [UIImage imageNamed:@"serverIcon"];
}
- (nullable id<VLCNetworkServerLoginInformation>)loginInformation
{
VLCNetworkServerLoginInformation *login = [[VLCNetworkServerLoginInformation alloc] init];
login.address = self.netService.hostName;
login.protocolIdentifier = VLCNetworkServerProtocolIdentifierFTP;
return login;
}
@end
\ No newline at end of file
......@@ -13,14 +13,7 @@
#import "VLCLocalNetworkServiceBrowser-Protocol.h"
@interface VLCLocalNetworkServiceBrowserMediaDiscoverer : NSObject <VLCLocalNetworkServiceBrowser>
@property (nonatomic, readonly) VLCMediaDiscoverer* mediaDiscoverer;
- (instancetype)initWithName:(NSString *)name serviceServiceName:(NSString *)serviceName NS_DESIGNATED_INITIALIZER;
@end
@interface VLCLocalNetworkServiceBrowserSAP : VLCLocalNetworkServiceBrowserMediaDiscoverer
- (instancetype)init;
@end
@interface VLCLocalNetworkServiceBrowserDSM : VLCLocalNetworkServiceBrowserMediaDiscoverer
- (instancetype)init;
@end
\ No newline at end of file
......@@ -12,6 +12,7 @@
#import "VLCLocalNetworkServiceBrowserMediaDiscoverer.h"
#import "VLCLocalNetworkServiceVLCMedia.h"
@interface VLCLocalNetworkServiceBrowserMediaDiscoverer () <VLCMediaListDelegate>
@property (nonatomic, readonly) NSString *serviceName;
......@@ -75,33 +76,3 @@
}
@end
#pragma mark - service specific subclasses
@implementation VLCLocalNetworkServiceBrowserSAP
- (instancetype)init {
return [super initWithName:@"SAP"
serviceServiceName:@"sap"];
}
- (id<VLCLocalNetworkService>)networkServiceForIndex:(NSUInteger)index {
VLCMedia *media = [self.mediaDiscoverer.discoveredMedia mediaAtIndex:index];
return [[VLCLocalNetworkServiceSAP alloc] initWithMediaItem:media];
}
@end
@implementation VLCLocalNetworkServiceBrowserDSM
- (instancetype)init {
return [super initWithName:NSLocalizedString(@"SMB_CIFS_FILE_SERVERS", nil)
serviceServiceName:@"dsm"];
}
- (id<VLCLocalNetworkService>)networkServiceForIndex:(NSUInteger)index {
VLCMedia *media = [self.mediaDiscoverer.discoveredMedia mediaAtIndex:index];
return [[VLCLocalNetworkServiceDSM alloc] initWithMediaItem:media];
}
@end
......@@ -12,6 +12,7 @@
#import <Foundation/Foundation.h>
#import "VLCLocalNetworkServiceBrowser-Protocol.h"
#import "VLCLocalNetworkServiceNetService.h"
@interface VLCLocalNetworkServiceBrowserNetService : NSObject <VLCLocalNetworkServiceBrowser>
- (instancetype)initWithName:(NSString *)name serviceType:(NSString *)serviceType domain:(NSString *)domain NS_DESIGNATED_INITIALIZER;
......@@ -35,19 +36,3 @@
- (VLCLocalNetworkServiceNetService *)localServiceForNetService:(NSNetService *)netService;
- (void)netServiceDidResolveAddress:(NSNetService *)sender;
@end
#pragma mark - service specific subclasses
@interface VLCLocalNetworkServiceBrowserFTP : VLCLocalNetworkServiceBrowserNetService
- (instancetype)initWithName:(NSString *)name serviceType:(NSString *)serviceType domain:(NSString *)domain NS_UNAVAILABLE;
- (instancetype)init NS_DESIGNATED_INITIALIZER;
@end
@interface VLCLocalNetworkServiceBrowserPlex : VLCLocalNetworkServiceBrowserNetService
- (instancetype)initWithName:(NSString *)name serviceType:(NSString *)serviceType domain:(NSString *)domain NS_UNAVAILABLE;
- (instancetype)init NS_DESIGNATED_INITIALIZER;
@end
@interface VLCLocalNetworkServiceBrowserHTTP : VLCLocalNetworkServiceBrowserNetService
- (instancetype)initWithName:(NSString *)name serviceType:(NSString *)serviceType domain:(NSString *)domain NS_UNAVAILABLE;
- (instancetype)init NS_DESIGNATED_INITIALIZER;
@end
......@@ -118,72 +118,3 @@
[self.delegate localNetworkServiceBrowserDidUpdateServices:self];
}
@end
#pragma mark - service specific subclasses
@implementation VLCLocalNetworkServiceBrowserFTP
- (instancetype)init {
return [super initWithName:@"File Transfer Protocol (FTP)"
serviceType:@"_ftp._tcp."
domain:@""];
}
- (VLCLocalNetworkServiceNetService *)localServiceForNetService:(NSNetService *)netService {
return [[VLCLocalNetworkServiceFTP alloc] initWithNetService:netService];
}
@end
@implementation VLCLocalNetworkServiceBrowserPlex
- (instancetype)init {
return [super initWithName:@"Plex Media Server (via Bonjour)"
serviceType:@"_plexmediasvr._tcp."
domain:@""];
}
- (VLCLocalNetworkServiceNetService *)localServiceForNetService:(NSNetService *)netService {
return [[VLCLocalNetworkServicePlex alloc] initWithNetService:netService];
}
@end
#import "VLCSharedLibraryParser.h"
#import "VLCHTTPUploaderController.h"
@interface VLCLocalNetworkServiceBrowserHTTP()
@property (nonatomic) VLCSharedLibraryParser *httpParser;
@end
@implementation VLCLocalNetworkServiceBrowserHTTP
- (instancetype)init {
return [super initWithName:NSLocalizedString(@"SHARED_VLC_IOS_LIBRARY", nil)
serviceType:@"_http._tcp."
domain:@""];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (VLCSharedLibraryParser *)httpParser {
if (!_httpParser) {
_httpParser = [[VLCSharedLibraryParser alloc] init];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(sharedLibraryFound:)
name:VLCSharedLibraryParserDeterminedNetserviceAsVLCInstance
object:_httpParser];
}
return _httpParser;
}
- (void)netServiceDidResolveAddress:(NSNetService *)sender {
NSString *ownHostname = [[VLCHTTPUploaderController sharedInstance] hostname];
if ([[sender hostName] rangeOfString:ownHostname].location != NSNotFound) {
return;
}
[self.httpParser checkNetserviceForVLCService:sender];
}
- (void)sharedLibraryFound:(NSNotification *)aNotification {
NSNetService *netService = [aNotification.userInfo objectForKey:@"aNetService"];
[self addResolvedLocalNetworkService:[self localServiceForNetService:netService]];
}
- (VLCLocalNetworkServiceNetService *)localServiceForNetService:(NSNetService *)netService {
return [[VLCLocalNetworkServiceHTTP alloc] initWithNetService:netService];
}
@end
/*****************************************************************************
* VLCLocalNetworkServiceNetService.h
* VLC for iOS
*****************************************************************************
* Copyright (c) 2015 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Tobias Conradi <videolan # tobias-conradi.de>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#import "VLCLocalNetworkService-Protocol.h"
NS_ASSUME_NONNULL_BEGIN
#pragma mark - NetService based services
@interface VLCLocalNetworkServiceNetService : NSObject <VLCLocalNetworkService>
@property (nonatomic, readonly, strong) NSNetService *netService;
- (instancetype)initWithNetService:(NSNetService *)service;
@end
NS_ASSUME_NONNULL_END
/*****************************************************************************
* VLCLocalNetworkServiceNetService.m
* VLC for iOS
*****************************************************************************
* Copyright (c) 2015 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Tobias Conradi <videolan # tobias-conradi.de>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#import "VLCLocalNetworkServiceNetService.h"
#pragma mark - NetService based services
@interface VLCLocalNetworkServiceNetService()
@property (nonatomic, strong) NSNetService *netService;
@end
@implementation VLCLocalNetworkServiceNetService
- (instancetype)initWithNetService:(NSNetService *)service
{
self = [super init];
if (self) {
_netService = service;
}
return self;
}
- (NSString *)title {
return self.netService.name;
}
- (UIImage *)icon {
return nil;
}
- (id<VLCNetworkServerBrowser>)serverBrowser {
return nil;
}
@end
/*****************************************************************************
* VLCLocalNetworkServiceVLCMedia.h
* VLC for iOS
*****************************************************************************
* Copyright (c) 2015 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Tobias Conradi <videolan # tobias-conradi.de>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#import "VLCLocalNetworkService-Protocol.h"
NS_ASSUME_NONNULL_BEGIN
@interface VLCLocalNetworkServiceVLCMedia : NSObject <VLCLocalNetworkService>
- (instancetype)initWithMediaItem:(VLCMedia *)mediaItem;
@property (nonatomic, readonly) VLCMedia *mediaItem;
@end
NS_ASSUME_NONNULL_END
/*****************************************************************************
* VLCLocalNetworkServiceVLCMedia.m
* VLC for iOS
*****************************************************************************
* Copyright (c) 2015 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Tobias Conradi <videolan # tobias-conradi.de>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#import "VLCLocalNetworkServiceVLCMedia.h"
@interface VLCLocalNetworkServiceVLCMedia()
@property (nonatomic) VLCMedia *mediaItem;
@end
@implementation VLCLocalNetworkServiceVLCMedia
- (instancetype)initWithMediaItem:(VLCMedia *)mediaItem
{
self = [super init];
if (self) {
_mediaItem = mediaItem;
}
return self;
}
- (NSString *)title {
return [self.mediaItem metadataForKey:VLCMetaInformationTitle];
}
- (UIImage *)icon {
return nil;
}
@end
......@@ -18,17 +18,8 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)init NS_UNAVAILABLE;
@end
@interface VLCNetworkServerBrowserItemVLCMedia : NSObject <VLCNetworkServerBrowserItem>
- (instancetype)initWithMedia:(VLCMedia *)media options:(NSDictionary *)mediaOptions;
@end
@interface VLCNetworkServerBrowserVLCMedia (SMB)
+ (instancetype)SMBNetworkServerBrowserWithURL:(NSURL *)url
username:(nullable NSString *)username
password:(nullable NSString *)password
workgroup:(nullable NSString *)workgroup;
@end
NS_ASSUME_NONNULL_END
\ No newline at end of file
......@@ -146,16 +146,3 @@
}
@end
@implementation VLCNetworkServerBrowserVLCMedia (SMB)
+ (instancetype)SMBNetworkServerBrowserWithURL:(NSURL *)url username:(NSString *)username password:(NSString *)password workgroup:(NSString *)workgroup {
VLCMedia *media = [VLCMedia mediaWithURL:url];
NSDictionary *mediaOptions = @{@"smb-user" : username ?: @"",
@"smb-pwd" : password ?: @"",
@"smb-domain" : workgroup?: @"WORKGROUP"};
[media addOptions:mediaOptions];
return [[self alloc] initWithMedia:media options:mediaOptions];
}
@end
/*****************************************************************************
* VLCNetworkServerLoginInformation.h
* VLC for iOS
*****************************************************************************
* Copyright (c) 2015 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Tobias Conradi <videolan # tobias-conradi.de>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#import <Foundation/Foundation.h>
#import "VLCLocalNetworkService-Protocol.h"
NS_ASSUME_NONNULL_BEGIN
@interface VLCNetworkServerLoginInformation : NSObject <VLCNetworkServerLoginInformation>
@property (nonatomic) NSString *username;
@property (nonatomic) NSString *password;
@property (nonatomic) NSString *address;
@property (nonatomic) NSNumber *port;
@property (nonatomic) NSString *protocolIdentifier;
@end
NS_ASSUME_NONNULL_END
/*****************************************************************************
* VLCNetworkServerLoginInformation.m
* VLC for iOS
*****************************************************************************
* Copyright (c) 2015 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Tobias Conradi <videolan # tobias-conradi.de>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#import "VLCNetworkServerLoginInformation.h"
@implementation VLCNetworkServerLoginInformation
@end
\ No newline at end of file
/*****************************************************************************
* VLCLocalNetworkServiceBrowserHTTP.h
* VLC for iOS
*****************************************************************************
* Copyright (c) 2015 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Tobias Conradi <videolan # tobias-conradi.de>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#import "VLCLocalNetworkServiceBrowserNetService.h"
#import "VLCLocalNetworkServiceNetService.h"
NS_ASSUME_NONNULL_BEGIN
@interface VLCLocalNetworkServiceBrowserHTTP : VLCLocalNetworkServiceBrowserNetService
- (instancetype)initWithName:(NSString *)name serviceType:(NSString *)serviceType domain:(NSString *)domain NS_UNAVAILABLE;
- (instancetype)init NS_DESIGNATED_INITIALIZER;
@end
@interface VLCLocalNetworkServiceHTTP : VLCLocalNetworkServiceNetService
@end
NS_ASSUME_NONNULL_END
\ No newline at end of file
/*****************************************************************************
* VLCLocalNetworkServiceBrowserHTTP.m
* VLC for iOS
*****************************************************************************
* Copyright (c) 2015 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Tobias Conradi <videolan # tobias-conradi.de>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#import "VLCLocalNetworkServiceBrowserHTTP.h"
#import "VLCSharedLibraryParser.h"
#import "VLCHTTPUploaderController.h"
#import "VLCNetworkServerBrowserSharedLibrary.h"
@interface VLCLocalNetworkServiceBrowserHTTP()
@property (nonatomic) VLCSharedLibraryParser *httpParser;
@end
@implementation VLCLocalNetworkServiceBrowserHTTP
- (instancetype)init {
return [super initWithName:NSLocalizedString(@"SHARED_VLC_IOS_LIBRARY", nil)
serviceType:@"_http._tcp."
domain:@""];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (VLCSharedLibraryParser *)httpParser {
if (!_httpParser) {
_httpParser = [[VLCSharedLibraryParser alloc] init];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(sharedLibraryFound:)
name:VLCSharedLibraryParserDeterminedNetserviceAsVLCInstance
object:_httpParser];
}
return _httpParser;
}
- (void)netServiceDidResolveAddress:(NSNetService *)sender {
NSString *ownHostname = [[VLCHTTPUploaderController sharedInstance] hostname];
if ([[sender hostName] rangeOfString:ownHostname].location != NSNotFound) {
return;
}
[self.httpParser checkNetserviceForVLCService:sender];
}
- (void)sharedLibraryFound:(NSNotification *)aNotification {
NSNetService *netService = [aNotification.userInfo objectForKey:@"aNetService"];
[self addResolvedLocalNetworkService:[self localServiceForNetService:netService]];
}
- (VLCLocalNetworkServiceNetService *)localServiceForNetService:(NSNetService *)netService {
return [[VLCLocalNetworkServiceHTTP alloc] initWithNetService:netService];
}
@end
@implementation VLCLocalNetworkServiceHTTP
- (UIImage *)icon {
return [UIImage imageNamed:@"menuCone"];
}
- (id<VLCNetworkServerBrowser>)serverBrowser {
NSNetService *service = self.netService;
if (service.hostName == nil || service.port == 0) {
return nil;
}
NSString *name = service.name;
NSString *hostName = service.hostName;
NSUInteger portNum = service.port;
VLCNetworkServerBrowserSharedLibrary *serverBrowser = [[VLCNetworkServerBrowserSharedLibrary alloc] initWithName:name host:hostName portNumber:portNum];
return serverBrowser;
}
@end
\ No newline at end of file
......@@ -12,6 +12,15 @@
#import "VLCLocalNetworkServiceBrowser-Protocol.h"
NS_ASSUME_NONNULL_BEGIN
@interface VLCLocalNetworkServiceBrowserManualConnect : NSObject <VLCLocalNetworkServiceBrowser>
- (instancetype)init;
@end
@interface VLCLocalNetworkServiceItemLogin : NSObject <VLCLocalNetworkService>
- (instancetype)init;
@end
NS_ASSUME_NONNULL_END
......@@ -11,7 +11,7 @@
*****************************************************************************/
#import "VLCLocalNetworkServiceBrowserManualConnect.h"
#import "VLCLocalNetworkService.h"
#import "VLCNetworkServerLoginInformation.h"
@interface VLCLocalNetworkServiceBrowserManualConnect ()
@property (nonatomic, readonly) VLCLocalNetworkServiceItemLogin *loginItem;
......@@ -43,3 +43,37 @@
return self.loginItem;
}
@end
@interface VLCLocalNetworkServiceItemLogin ()
@property (nonatomic, strong) NSString *title;
@property (nonatomic, strong, nullable) UIImage *icon;
@end
@implementation VLCLocalNetworkServiceItemLogin
- (instancetype)initWithTile:(NSString *)title icon:(UIImage *)icon
{
self = [super init];
if (self) {
_title = title;
_icon = icon;
}
return self;
}
- (instancetype)init
{
self = [self initWithTile:NSLocalizedString(@"CONNECT_TO_SERVER", nil)
icon:[UIImage imageNamed:@"menuCone"]];
if (self) {
}
return self;
}
- (VLCNetworkServerLoginInformation *)loginInformation
{
return [[VLCNetworkServerLoginInformation alloc] init];
}
@end
/*****************************************************************************
* VLCLocalNetworkServiceBrowserPlex.h
* VLC for iOS
*****************************************************************************
* Copyright (c) 2015 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Tobias Conradi <videolan # tobias-conradi.de>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#import "VLCLocalNetworkServiceBrowserNetService.h"
NS_ASSUME_NONNULL_BEGIN
@interface VLCLocalNetworkServiceBrowserPlex : VLCLocalNetworkServiceBrowserNetService
- (instancetype)initWithName:(NSString *)name serviceType:(NSString *)serviceType domain:(NSString *)domain NS_UNAVAILABLE;
- (instancetype)init NS_DESIGNATED_INITIALIZER;
@end
extern NSString *const VLCNetworkServerProtocolIdentifierPlex;
@interface VLCLocalNetworkServicePlex : VLCLocalNetworkServiceNetService
@end
NS_ASSUME_NONNULL_END
\ No newline at end of file
/*****************************************************************************
* VLCLocalNetworkServiceBrowserPlex.m
* VLC for iOS
*****************************************************************************
* Copyright (c) 2015 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Tobias Conradi <videolan # tobias-conradi.de>
*
* Refer to the COPYING file of the official project for license.