VLCNetworkServerLoginInformation.m 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*****************************************************************************
  2. * VLCNetworkServerLoginInformation.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 "VLCNetworkServerLoginInformation.h"
  13. @implementation VLCNetworkServerLoginInformationField
  14. - (instancetype)initWithType:(VLCNetworkServerLoginInformationFieldType)type identifier:(NSString *)identifier label:(NSString *)localizedLabel textValue:(NSString *)initialValue
  15. {
  16. self = [super init];
  17. if (self) {
  18. _type = type;
  19. _identifier = [identifier copy];
  20. _localizedLabel = [localizedLabel copy];
  21. _textValue = [initialValue copy];
  22. }
  23. return self;
  24. }
  25. - (id)copyWithZone:(NSZone *)zone
  26. {
  27. return [[[self class] allocWithZone:zone] initWithType:self.type identifier:self.identifier label:self.localizedLabel textValue:self.textValue];
  28. }
  29. @end
  30. @implementation VLCNetworkServerLoginInformation
  31. - (id)copyWithZone:(NSZone *)zone
  32. {
  33. VLCNetworkServerLoginInformation *other = [[[self class] allocWithZone:zone] init];
  34. other.username = self.username;
  35. other.password = self.password;
  36. other.address = self.address;
  37. other.port = self.port;
  38. other.protocolIdentifier = self.protocolIdentifier;
  39. other.additionalFields = [[NSMutableArray alloc] initWithArray:self.additionalFields copyItems:YES];
  40. return other;
  41. }
  42. static NSMutableDictionary<NSString *, VLCNetworkServerLoginInformation *> *VLCNetworkServerLoginInformationRegistry = nil;
  43. + (void)initialize
  44. {
  45. [super initialize];
  46. VLCNetworkServerLoginInformationRegistry = [[NSMutableDictionary alloc] init];
  47. }
  48. + (void)registerTemplateLoginInformation:(VLCNetworkServerLoginInformation *)loginInformation
  49. {
  50. VLCNetworkServerLoginInformationRegistry[loginInformation.protocolIdentifier] = [loginInformation copy];
  51. }
  52. + (instancetype)newLoginInformationForProtocol:(NSString *)protocolIdentifier
  53. {
  54. VLCNetworkServerLoginInformation *loginInformation = [VLCNetworkServerLoginInformationRegistry[protocolIdentifier] copy];
  55. if (!loginInformation) {
  56. loginInformation = [[VLCNetworkServerLoginInformation alloc] init];
  57. loginInformation.protocolIdentifier = protocolIdentifier;
  58. }
  59. return loginInformation;
  60. }
  61. @end