VLCLocalNetworkServiceBrowserFTP.m 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*****************************************************************************
  2. * VLCLocalNetworkServiceBrowserFTP.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 "VLCLocalNetworkServiceBrowserFTP.h"
  13. #import "VLCNetworkServerLoginInformation.h"
  14. #import "SSKeychain.h"
  15. @implementation VLCLocalNetworkServiceBrowserFTP
  16. - (instancetype)init {
  17. #if TARGET_OS_TV
  18. NSString *name = NSLocalizedString(@"FTP_SHORT",nil);
  19. #else
  20. NSString *name = NSLocalizedString(@"FTP_LONG",nil);
  21. #endif
  22. return [super initWithName:name
  23. serviceType:@"_ftp._tcp."
  24. domain:@""];
  25. }
  26. - (VLCLocalNetworkServiceNetService *)localServiceForNetService:(NSNetService *)netService {
  27. return [[VLCLocalNetworkServiceFTP alloc] initWithNetService:netService];
  28. }
  29. @end
  30. NSString *const VLCNetworkServerProtocolIdentifierFTP = @"ftp";
  31. @implementation VLCLocalNetworkServiceFTP
  32. - (UIImage *)icon {
  33. return [UIImage imageNamed:@"serverIcon"];
  34. }
  35. - (nullable id<VLCNetworkServerLoginInformation>)loginInformation
  36. {
  37. VLCNetworkServerLoginInformation *login = [[VLCNetworkServerLoginInformation alloc] init];
  38. login.address = self.netService.hostName;
  39. login.port = [NSNumber numberWithInteger:self.netService.port];
  40. login.protocolIdentifier = VLCNetworkServerProtocolIdentifierFTP;
  41. NSString *serviceString = [NSString stringWithFormat:@"ftp://%@", login.address];
  42. NSArray *accounts = [SSKeychain accountsForService:serviceString];
  43. if (!accounts) {
  44. login.username = login.password = @"";
  45. return login;
  46. }
  47. NSDictionary *account = [accounts firstObject];
  48. NSString *username = [account objectForKey:@"acct"];
  49. login.username = username;
  50. login.password = [SSKeychain passwordForService:serviceString account:username];
  51. return login;
  52. }
  53. @end