IOSAD-61 pEp_identity <-> PEPIdentity IOSAD-61
authorDirk Zimmermann <dirk@pep-project.org>
Mon, 30 Oct 2017 13:01:27 +0100
branchIOSAD-61
changeset 3053e0a52fec0ec
parent 304 869358d007d8
child 306 7b3f01d1a047
IOSAD-61 pEp_identity <-> PEPIdentity
pEpObjCAdapter/PEPIdentity.h
pEpObjCAdapter/PEPIdentity.m
pEpObjCAdapter/PEPInternalSession.m
pEpObjCAdapter/PEPMessage.m
pEpObjCAdapter/PEPSession.m
pEpObjCAdapter/PEPSessionProtocol.h
     1.1 --- a/pEpObjCAdapter/PEPIdentity.h	Mon Oct 30 12:35:49 2017 +0100
     1.2 +++ b/pEpObjCAdapter/PEPIdentity.h	Mon Oct 30 13:01:27 2017 +0100
     1.3 @@ -16,16 +16,42 @@
     1.4  @property (nonatomic, nonnull) NSString *address;
     1.5  
     1.6  /**
     1.7 + The (optional) user ID.
     1.8 + */
     1.9 +@property (nonatomic, nullable) NSString *userID;
    1.10 +
    1.11 +/**
    1.12   The (optional) user name.
    1.13   */
    1.14  @property (nonatomic, nullable) NSString *userName;
    1.15  
    1.16  /**
    1.17 + The (optional) fingerprint.
    1.18 + */
    1.19 +@property (nonatomic, nullable) NSString *fingerPrint;
    1.20 +
    1.21 +/**
    1.22 + The (optional) language that this identity uses.
    1.23 + */
    1.24 +@property (nonatomic, nullable) NSString *language;
    1.25 +
    1.26 +/**
    1.27 + The comm type of this identity.
    1.28 + */
    1.29 +@property NSInteger commType;
    1.30 +
    1.31 +/**
    1.32   Is this one of our own identities?
    1.33   */
    1.34  @property BOOL isOwn;
    1.35  
    1.36 -- (id)initWithAddress:(NSString * _Nonnull)address userName:(NSString * _Nullable)userName;
    1.37 -- (id)initWithAddress:(NSString * _Nonnull)address;
    1.38 +- (nonnull instancetype)initWithAddress:(NSString * _Nonnull)address
    1.39 +                                 userID:(NSString * _Nullable)userID
    1.40 +                               userName:(NSString * _Nullable)userName
    1.41 +                            fingerPrint:(NSString * _Nullable)fingerPrint
    1.42 +                               commType:(NSInteger)commType
    1.43 +                               language:(NSString * _Nullable)language;
    1.44 +
    1.45 +- (nonnull instancetype)initWithAddress:(NSString * _Nonnull)address;
    1.46  
    1.47  @end
     2.1 --- a/pEpObjCAdapter/PEPIdentity.m	Mon Oct 30 12:35:49 2017 +0100
     2.2 +++ b/pEpObjCAdapter/PEPIdentity.m	Mon Oct 30 13:01:27 2017 +0100
     2.3 @@ -8,20 +8,31 @@
     2.4  
     2.5  #import "PEPIdentity.h"
     2.6  
     2.7 +#import "pEpEngine.h"
     2.8 +
     2.9  @implementation PEPIdentity
    2.10  
    2.11 -- (id)initWithAddress:(NSString * _Nonnull)address userName:(NSString * _Nullable)userName
    2.12 -{
    2.13 +- (nonnull instancetype)initWithAddress:(NSString * _Nonnull)address
    2.14 +                                 userID:(NSString * _Nullable)userID
    2.15 +                               userName:(NSString * _Nullable)userName
    2.16 +                            fingerPrint:(NSString * _Nullable)fingerPrint
    2.17 +                               commType:(NSInteger)commType
    2.18 +                               language:(NSString * _Nullable)language {
    2.19      if (self = [super init]) {
    2.20          self.address = address;
    2.21 +        self.userID = userID;
    2.22          self.userName = userName;
    2.23 +        self.fingerPrint = fingerPrint;
    2.24 +        self.commType = commType;
    2.25 +        self.language = language;
    2.26      }
    2.27      return self;
    2.28  }
    2.29  
    2.30 -- (id)initWithAddress:(NSString * _Nonnull)address
    2.31 +- (nonnull instancetype)initWithAddress:(NSString * _Nonnull)address
    2.32  {
    2.33 -    return [self initWithAddress:address userName:nil];
    2.34 +    return [self initWithAddress:address userID:nil userName:nil fingerPrint:nil
    2.35 +                        commType:PEP_ct_unknown language:nil];
    2.36  }
    2.37  
    2.38  - (BOOL)isEqual:(id)other
     3.1 --- a/pEpObjCAdapter/PEPInternalSession.m	Mon Oct 30 12:35:49 2017 +0100
     3.2 +++ b/pEpObjCAdapter/PEPInternalSession.m	Mon Oct 30 13:01:27 2017 +0100
     3.3 @@ -283,7 +283,7 @@
     3.4      free_identity(ident);
     3.5  }
     3.6  
     3.7 -- (void)updateIdentity:(PEPMutableDict *)identity
     3.8 +- (void)updateIdentity:(PEPIdentity *)identity
     3.9  {
    3.10      pEp_identity *ident = PEP_identityDictToStruct(identity);
    3.11  
     4.1 --- a/pEpObjCAdapter/PEPMessage.m	Mon Oct 30 12:35:49 2017 +0100
     4.2 +++ b/pEpObjCAdapter/PEPMessage.m	Mon Oct 30 13:01:27 2017 +0100
     4.3 @@ -7,6 +7,7 @@
     4.4  //
     4.5  
     4.6  #import "PEPMessage.h"
     4.7 +#import "PEPIdentity.h"
     4.8  
     4.9  #pragma mark -- Constants
    4.10  
    4.11 @@ -196,37 +197,101 @@
    4.12      return dict;
    4.13  }
    4.14  
    4.15 +PEPIdentity *PEP_identityFromStruct(pEp_identity *ident)
    4.16 +{
    4.17 +    if (ident) {
    4.18 +        PEPIdentity *identity = nil;
    4.19 +        if (ident->address && ident->address[0]) {
    4.20 +            identity = [[PEPIdentity alloc]
    4.21 +                        initWithAddress:[NSString stringWithUTF8String:ident->address]];
    4.22 +        }
    4.23 +
    4.24 +        if (ident->fpr && ident->fpr[0]) {
    4.25 +            identity.fingerPrint = [NSString stringWithUTF8String:ident->fpr];
    4.26 +        }
    4.27 +
    4.28 +        if (ident->user_id && ident->user_id[0]) {
    4.29 +            identity.userID = [NSString stringWithUTF8String:ident->user_id];
    4.30 +        }
    4.31 +
    4.32 +        if (ident->username && ident->username[0]) {
    4.33 +            identity.userName = [NSString stringWithUTF8String:ident->username];
    4.34 +        }
    4.35 +
    4.36 +        if (ident->lang[0]) {
    4.37 +            identity.language = [NSString stringWithUTF8String:ident->lang];
    4.38 +        }
    4.39 +
    4.40 +        identity.commType = ident->comm_type;
    4.41 +
    4.42 +        return identity;
    4.43 +    }
    4.44 +    return nil;
    4.45 +}
    4.46 +
    4.47 +pEp_identity *PEP_identityToStruct(PEPIdentity *identity)
    4.48 +{
    4.49 +    pEp_identity *ident = new_identity(NULL, NULL, NULL, NULL);
    4.50 +
    4.51 +    ident->address = strdup([[identity.address
    4.52 +                              precomposedStringWithCanonicalMapping] UTF8String]);
    4.53 +
    4.54 +    if (identity.userID) {
    4.55 +        ident->user_id = strdup([[identity.userID
    4.56 +                              precomposedStringWithCanonicalMapping] UTF8String]);
    4.57 +    }
    4.58 +
    4.59 +    if (identity.userName) {
    4.60 +        ident->username = strdup([[identity.userName
    4.61 +                              precomposedStringWithCanonicalMapping] UTF8String]);
    4.62 +    }
    4.63 +
    4.64 +    if (identity.fingerPrint) {
    4.65 +        ident->fpr = strdup([[identity.fingerPrint
    4.66 +                              precomposedStringWithCanonicalMapping] UTF8String]);
    4.67 +    }
    4.68 +
    4.69 +    if (identity.language) {
    4.70 +        strncpy(ident->lang, [[identity.language
    4.71 +                               precomposedStringWithCanonicalMapping] UTF8String], 2);
    4.72 +    }
    4.73 +
    4.74 +    ident->comm_type = identity.commType;
    4.75 +    
    4.76 +    return ident;
    4.77 +}
    4.78 +
    4.79  pEp_identity *PEP_identityDictToStruct(NSDictionary *dict)
    4.80  {
    4.81      pEp_identity *ident = new_identity(NULL, NULL, NULL, NULL);
    4.82 -    
    4.83 +
    4.84      if (dict && ident) {
    4.85          if ([dict objectForKey:kPepAddress])
    4.86              ident->address = strdup([[[dict objectForKey:kPepAddress]
    4.87                                        precomposedStringWithCanonicalMapping] UTF8String]);
    4.88 -        
    4.89 +
    4.90          if ([dict objectForKey:kPepFingerprint]) {
    4.91              ident->fpr = strdup([[[dict objectForKey:kPepFingerprint]
    4.92                                    precomposedStringWithCanonicalMapping] UTF8String]);
    4.93          }
    4.94 -        
    4.95 +
    4.96          if ([dict objectForKey:kPepUserID]) {
    4.97              ident->user_id = strdup([[[dict objectForKey:kPepUserID]
    4.98                                        precomposedStringWithCanonicalMapping] UTF8String]);
    4.99          }
   4.100 -        
   4.101 +
   4.102          if ([dict objectForKey:kPepUsername])
   4.103              ident->username = strdup([[[dict objectForKey:kPepUsername]
   4.104                                         precomposedStringWithCanonicalMapping] UTF8String]);
   4.105 -        
   4.106 +
   4.107          if ([dict objectForKey:@"lang"])
   4.108              strncpy(ident->fpr, [[[dict objectForKey:@"lang"]
   4.109                                    precomposedStringWithCanonicalMapping] UTF8String], 2);
   4.110 -        
   4.111 +
   4.112          if ([dict objectForKey:kPepCommType])
   4.113              ident->comm_type = [[dict objectForKey:kPepCommType] intValue];
   4.114      }
   4.115 -    
   4.116 +
   4.117      return ident;
   4.118  }
   4.119  
     5.1 --- a/pEpObjCAdapter/PEPSession.m	Mon Oct 30 12:35:49 2017 +0100
     5.2 +++ b/pEpObjCAdapter/PEPSession.m	Mon Oct 30 13:01:27 2017 +0100
     5.3 @@ -10,6 +10,7 @@
     5.4  
     5.5  #import "PEPInternalSession.h"
     5.6  #import "PEPSessionProvider.h"
     5.7 +#import "PEPIdentity.h"
     5.8  
     5.9  @implementation PEPSession
    5.10  
    5.11 @@ -63,7 +64,7 @@
    5.12      return [PEPSession trustwords:fpr forLanguage:languageID shortened:shortened];
    5.13  }
    5.14  
    5.15 -- (void)mySelf:(nonnull PEPMutableDict *)identity
    5.16 +- (void)mySelf:(nonnull PEPIdentity*)identity
    5.17  {
    5.18      [PEPSession mySelf:identity];
    5.19  }
    5.20 @@ -203,7 +204,7 @@
    5.21      [session mySelf:identity];
    5.22  }
    5.23  
    5.24 -+ (void)updateIdentity:(nonnull PEPMutableDict *)identity
    5.25 ++ (void)updateIdentity:(nonnull PEPIdentity *)identity
    5.26  {
    5.27      PEPInternalSession *session = [PEPSessionProvider session];
    5.28      [session updateIdentity:identity];
     6.1 --- a/pEpObjCAdapter/PEPSessionProtocol.h	Mon Oct 30 12:35:49 2017 +0100
     6.2 +++ b/pEpObjCAdapter/PEPSessionProtocol.h	Mon Oct 30 13:01:27 2017 +0100
     6.3 @@ -15,6 +15,7 @@
     6.4  typedef NSArray<NSString *> PEPStringList;
     6.5  
     6.6  @class PEPLanguage;
     6.7 +@class PEPIdentity;
     6.8  
     6.9  @protocol PEPSessionProtocol <NSObject>
    6.10  
    6.11 @@ -69,7 +70,7 @@
    6.12   @"23", @"user_id", nil];
    6.13  
    6.14   */
    6.15 -- (void)mySelf:(nonnull PEPMutableDict *)identity;
    6.16 +- (void)mySelf:(nonnull PEPIdentity *)identity;
    6.17  
    6.18  /**
    6.19   Supplement missing information for an arbitrary identity (used for communication partners).