IOSAD-61 clean up API IOSAD-61
authorDirk Zimmermann <dirk@pep-project.org>
Mon, 30 Oct 2017 13:09:23 +0100
branchIOSAD-61
changeset 30708b35bfa8d65
parent 306 7b3f01d1a047
child 308 34b89403175f
IOSAD-61 clean up API
pEpObjCAdapter/PEPInternalSession.m
pEpObjCAdapter/PEPMessage.h
pEpObjCAdapter/PEPMessage.m
     1.1 --- a/pEpObjCAdapter/PEPInternalSession.m	Mon Oct 30 13:03:05 2017 +0100
     1.2 +++ b/pEpObjCAdapter/PEPInternalSession.m	Mon Oct 30 13:09:23 2017 +0100
     1.3 @@ -14,6 +14,7 @@
     1.4  #import "PEPCSVScanner.h"
     1.5  #import "NSArray+Extension.h"
     1.6  #import "NSDictionary+Extension.h"
     1.7 +#import "PEPIdentity.h"
     1.8  
     1.9  @implementation PEPInternalSession
    1.10  
    1.11 @@ -269,11 +270,11 @@
    1.12      return array;
    1.13  }
    1.14  
    1.15 -- (void)mySelf:(PEPMutableDict *)identity
    1.16 +- (void)mySelf:(PEPIdentity *)identity
    1.17  {
    1.18 -    [identity removeObjectForKey:kPepUserID];
    1.19 +    identity.userID = nil;
    1.20  
    1.21 -    pEp_identity *ident = PEP_identityDictToStruct(identity);
    1.22 +    pEp_identity *ident = PEP_identityToStruct(identity);
    1.23  
    1.24      @synchronized(self) {
    1.25          myself(_session, ident);
     2.1 --- a/pEpObjCAdapter/PEPMessage.h	Mon Oct 30 13:03:05 2017 +0100
     2.2 +++ b/pEpObjCAdapter/PEPMessage.h	Mon Oct 30 13:09:23 2017 +0100
     2.3 @@ -10,9 +10,14 @@
     2.4  
     2.5  #include "message_api.h"
     2.6  
     2.7 +@class PEPIdentity;
     2.8 +
     2.9  NSArray * _Nonnull PEP_arrayFromStringlist(stringlist_t * _Nonnull sl);
    2.10  stringlist_t * _Nullable PEP_arrayToStringlist(NSArray * _Nullable array);
    2.11  
    2.12 +pEp_identity * _Nonnull PEP_identityToStruct(PEPIdentity * _Nonnull identity);
    2.13 +PEPIdentity * _Nonnull PEP_identityFromStruct(pEp_identity * _Nonnull ident);
    2.14 +
    2.15  pEp_identity * _Nullable PEP_identityDictToStruct(NSDictionary * _Nullable dict);
    2.16  NSDictionary * _Nonnull PEP_identityDictFromStruct(pEp_identity * _Nullable ident);
    2.17  
     3.1 --- a/pEpObjCAdapter/PEPMessage.m	Mon Oct 30 13:03:05 2017 +0100
     3.2 +++ b/pEpObjCAdapter/PEPMessage.m	Mon Oct 30 13:09:23 2017 +0100
     3.3 @@ -171,96 +171,6 @@
     3.4      return _bl;
     3.5  }
     3.6  
     3.7 -NSDictionary *PEP_identityDictFromStruct(pEp_identity *ident)
     3.8 -{
     3.9 -    NSMutableDictionary *dict = [NSMutableDictionary new];
    3.10 -
    3.11 -    if (ident) {
    3.12 -        if (ident->address && ident->address[0])
    3.13 -            [dict setObject:[NSString stringWithUTF8String:ident->address] forKey:kPepAddress];
    3.14 -        
    3.15 -        if (ident->fpr && ident->fpr[0])
    3.16 -            [dict setObject:[NSString stringWithUTF8String:ident->fpr] forKey:kPepFingerprint];
    3.17 -        
    3.18 -        if (ident->user_id && ident->user_id[0])
    3.19 -            [dict setObject:[NSString stringWithUTF8String:ident->user_id] forKey:kPepUserID];
    3.20 -        
    3.21 -        if (ident->username && ident->username[0])
    3.22 -            [dict setObject:[NSString stringWithUTF8String:ident->username] forKey:kPepUsername];
    3.23 -        
    3.24 -        if (ident->lang[0])
    3.25 -            [dict setObject:[NSString stringWithUTF8String:ident->lang] forKey:@"lang"];
    3.26 -        
    3.27 -        [dict setObject:[NSNumber numberWithInt: ident->comm_type] forKey:kPepCommType];
    3.28 -        
    3.29 -    }
    3.30 -    return dict;
    3.31 -}
    3.32 -
    3.33 -PEPIdentity *PEP_identityFromStruct(pEp_identity *ident)
    3.34 -{
    3.35 -    if (ident) {
    3.36 -        PEPIdentity *identity = nil;
    3.37 -        if (ident->address && ident->address[0]) {
    3.38 -            identity = [[PEPIdentity alloc]
    3.39 -                        initWithAddress:[NSString stringWithUTF8String:ident->address]];
    3.40 -        }
    3.41 -
    3.42 -        if (ident->fpr && ident->fpr[0]) {
    3.43 -            identity.fingerPrint = [NSString stringWithUTF8String:ident->fpr];
    3.44 -        }
    3.45 -
    3.46 -        if (ident->user_id && ident->user_id[0]) {
    3.47 -            identity.userID = [NSString stringWithUTF8String:ident->user_id];
    3.48 -        }
    3.49 -
    3.50 -        if (ident->username && ident->username[0]) {
    3.51 -            identity.userName = [NSString stringWithUTF8String:ident->username];
    3.52 -        }
    3.53 -
    3.54 -        if (ident->lang[0]) {
    3.55 -            identity.language = [NSString stringWithUTF8String:ident->lang];
    3.56 -        }
    3.57 -
    3.58 -        identity.commType = ident->comm_type;
    3.59 -
    3.60 -        return identity;
    3.61 -    }
    3.62 -    return nil;
    3.63 -}
    3.64 -
    3.65 -pEp_identity *PEP_identityToStruct(PEPIdentity *identity)
    3.66 -{
    3.67 -    pEp_identity *ident = new_identity(NULL, NULL, NULL, NULL);
    3.68 -
    3.69 -    ident->address = strdup([[identity.address
    3.70 -                              precomposedStringWithCanonicalMapping] UTF8String]);
    3.71 -
    3.72 -    if (identity.userID) {
    3.73 -        ident->user_id = strdup([[identity.userID
    3.74 -                              precomposedStringWithCanonicalMapping] UTF8String]);
    3.75 -    }
    3.76 -
    3.77 -    if (identity.userName) {
    3.78 -        ident->username = strdup([[identity.userName
    3.79 -                              precomposedStringWithCanonicalMapping] UTF8String]);
    3.80 -    }
    3.81 -
    3.82 -    if (identity.fingerPrint) {
    3.83 -        ident->fpr = strdup([[identity.fingerPrint
    3.84 -                              precomposedStringWithCanonicalMapping] UTF8String]);
    3.85 -    }
    3.86 -
    3.87 -    if (identity.language) {
    3.88 -        strncpy(ident->lang, [[identity.language
    3.89 -                               precomposedStringWithCanonicalMapping] UTF8String], 2);
    3.90 -    }
    3.91 -
    3.92 -    ident->comm_type = identity.commType;
    3.93 -    
    3.94 -    return ident;
    3.95 -}
    3.96 -
    3.97  pEp_identity *PEP_identityDictToStruct(NSDictionary *dict)
    3.98  {
    3.99      pEp_identity *ident = new_identity(NULL, NULL, NULL, NULL);
   3.100 @@ -295,6 +205,93 @@
   3.101      return ident;
   3.102  }
   3.103  
   3.104 +NSDictionary *PEP_identityDictFromStruct(pEp_identity *ident)
   3.105 +{
   3.106 +    NSMutableDictionary *dict = [NSMutableDictionary new];
   3.107 +
   3.108 +    if (ident) {
   3.109 +        if (ident->address && ident->address[0])
   3.110 +            [dict setObject:[NSString stringWithUTF8String:ident->address] forKey:kPepAddress];
   3.111 +        
   3.112 +        if (ident->fpr && ident->fpr[0])
   3.113 +            [dict setObject:[NSString stringWithUTF8String:ident->fpr] forKey:kPepFingerprint];
   3.114 +        
   3.115 +        if (ident->user_id && ident->user_id[0])
   3.116 +            [dict setObject:[NSString stringWithUTF8String:ident->user_id] forKey:kPepUserID];
   3.117 +        
   3.118 +        if (ident->username && ident->username[0])
   3.119 +            [dict setObject:[NSString stringWithUTF8String:ident->username] forKey:kPepUsername];
   3.120 +        
   3.121 +        if (ident->lang[0])
   3.122 +            [dict setObject:[NSString stringWithUTF8String:ident->lang] forKey:@"lang"];
   3.123 +        
   3.124 +        [dict setObject:[NSNumber numberWithInt: ident->comm_type] forKey:kPepCommType];
   3.125 +        
   3.126 +    }
   3.127 +    return dict;
   3.128 +}
   3.129 +
   3.130 +pEp_identity *PEP_identityToStruct(PEPIdentity *identity)
   3.131 +{
   3.132 +    pEp_identity *ident = new_identity(NULL, NULL, NULL, NULL);
   3.133 +
   3.134 +    ident->address = strdup([[identity.address
   3.135 +                              precomposedStringWithCanonicalMapping] UTF8String]);
   3.136 +
   3.137 +    if (identity.userID) {
   3.138 +        ident->user_id = strdup([[identity.userID
   3.139 +                                  precomposedStringWithCanonicalMapping] UTF8String]);
   3.140 +    }
   3.141 +
   3.142 +    if (identity.userName) {
   3.143 +        ident->username = strdup([[identity.userName
   3.144 +                                   precomposedStringWithCanonicalMapping] UTF8String]);
   3.145 +    }
   3.146 +
   3.147 +    if (identity.fingerPrint) {
   3.148 +        ident->fpr = strdup([[identity.fingerPrint
   3.149 +                              precomposedStringWithCanonicalMapping] UTF8String]);
   3.150 +    }
   3.151 +
   3.152 +    if (identity.language) {
   3.153 +        strncpy(ident->lang, [[identity.language
   3.154 +                               precomposedStringWithCanonicalMapping] UTF8String], 2);
   3.155 +    }
   3.156 +
   3.157 +    ident->comm_type = (PEP_comm_type) identity.commType;
   3.158 +
   3.159 +    return ident;
   3.160 +}
   3.161 +
   3.162 +PEPIdentity *PEP_identityFromStruct(pEp_identity *ident)
   3.163 +{
   3.164 +    PEPIdentity *identity = nil;
   3.165 +    if (ident->address && ident->address[0]) {
   3.166 +        identity = [[PEPIdentity alloc]
   3.167 +                    initWithAddress:[NSString stringWithUTF8String:ident->address]];
   3.168 +    }
   3.169 +
   3.170 +    if (ident->fpr && ident->fpr[0]) {
   3.171 +        identity.fingerPrint = [NSString stringWithUTF8String:ident->fpr];
   3.172 +    }
   3.173 +
   3.174 +    if (ident->user_id && ident->user_id[0]) {
   3.175 +        identity.userID = [NSString stringWithUTF8String:ident->user_id];
   3.176 +    }
   3.177 +
   3.178 +    if (ident->username && ident->username[0]) {
   3.179 +        identity.userName = [NSString stringWithUTF8String:ident->username];
   3.180 +    }
   3.181 +
   3.182 +    if (ident->lang[0]) {
   3.183 +        identity.language = [NSString stringWithUTF8String:ident->lang];
   3.184 +    }
   3.185 +
   3.186 +    identity.commType = ident->comm_type;
   3.187 +
   3.188 +    return identity;
   3.189 +}
   3.190 +
   3.191  NSArray *PEP_arrayFromIdentityList(identity_list *il)
   3.192  {
   3.193      NSMutableArray *array = [NSMutableArray array];