VLCLocalNetworkServiceBrowserDSM.m 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*****************************************************************************
  2. * VLCLocalNetworkServiceBrowserDSM.m
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2015 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Authors: Tobias Conradi <videolan # tobias-conradi.de>
  9. *
  10. * Refer to the COPYING file of the official project for license.
  11. *****************************************************************************/
  12. #import "VLCLocalNetworkServiceBrowserDSM.h"
  13. #import "VLCNetworkServerLoginInformation.h"
  14. @implementation VLCLocalNetworkServiceBrowserDSM
  15. - (instancetype)init {
  16. return [super initWithName:NSLocalizedString(@"SMB_CIFS_FILE_SERVERS", nil)
  17. serviceServiceName:@"dsm"];
  18. }
  19. - (id<VLCLocalNetworkService>)networkServiceForIndex:(NSUInteger)index {
  20. VLCMedia *media = [self.mediaDiscoverer.discoveredMedia mediaAtIndex:index];
  21. return [[VLCLocalNetworkServiceDSM alloc] initWithMediaItem:media];
  22. }
  23. @end
  24. NSString *const VLCNetworkServerProtocolIdentifierSMB = @"smb";
  25. @implementation VLCLocalNetworkServiceDSM
  26. - (UIImage *)icon {
  27. return [UIImage imageNamed:@"serverIcon"];
  28. }
  29. - (VLCNetworkServerLoginInformation *)loginInformation {
  30. VLCMedia *media = self.mediaItem;
  31. if (media.mediaType != VLCMediaTypeDirectory)
  32. return nil;
  33. VLCNetworkServerLoginInformation *login = [[VLCNetworkServerLoginInformation alloc] init];
  34. login.address = self.mediaItem.url.host;
  35. login.protocolIdentifier = VLCNetworkServerProtocolIdentifierSMB;
  36. return login;
  37. }
  38. @end
  39. @implementation VLCNetworkServerBrowserVLCMedia (SMB)
  40. + (instancetype)SMBNetworkServerBrowserWithLogin:(VLCNetworkServerLoginInformation *)login
  41. {
  42. NSURLComponents *components = [[NSURLComponents alloc] init];
  43. components.scheme = @"smb";
  44. components.host = login.address;
  45. components.port = login.port;
  46. NSURL *url = components.URL;
  47. return [self SMBNetworkServerBrowserWithURL:url
  48. username:login.username
  49. password:login.password
  50. workgroup:nil];
  51. }
  52. + (instancetype)SMBNetworkServerBrowserWithURL:(NSURL *)url username:(NSString *)username password:(NSString *)password workgroup:(NSString *)workgroup {
  53. VLCMedia *media = [VLCMedia mediaWithURL:url];
  54. NSDictionary *mediaOptions = @{@"smb-user" : username ?: @"",
  55. @"smb-pwd" : password ?: @"",
  56. @"smb-domain" : workgroup?: @"WORKGROUP"};
  57. [media addOptions:mediaOptions];
  58. return [[self alloc] initWithMedia:media options:mediaOptions];
  59. }
  60. @end