merge IOSAD-160
authorDirk Zimmermann <dz@pep.security>
Wed, 04 Dec 2019 08:10:31 +0100
changeset 1378bfe8a5677105
parent 1366 47fecdfa178f
parent 1377 4dc2ace8d158
child 1379 13b2d34e6ba9
merge IOSAD-160
     1.1 --- a/pEpObjCAdapter/PEPInternalSession.m	Fri Nov 29 14:42:14 2019 +0100
     1.2 +++ b/pEpObjCAdapter/PEPInternalSession.m	Wed Dec 04 08:10:31 2019 +0100
     1.3 @@ -535,10 +535,24 @@
     1.4      return array;
     1.5  }
     1.6  
     1.7 -- (BOOL)mySelf:(PEPIdentity * _Nonnull)identity error:(NSError * _Nullable * _Nullable)error
     1.8 +- (BOOL)mySelf:(PEPIdentity * _Nonnull)identity
     1.9 +         error:(NSError * _Nullable * _Nullable)error
    1.10  {
    1.11 +    // The default for pEpSyncEnabled is YES, that means the adapter
    1.12 +    // will not change the engine identity in that regard after new_identity
    1.13 +    // (called by PEP_identityToStruct).
    1.14 +    return [self mySelf:identity pEpSyncEnabled:YES error:error];
    1.15 +}
    1.16 +
    1.17 +- (BOOL)mySelf:(PEPIdentity * _Nonnull)identity
    1.18 +pEpSyncEnabled:(BOOL)pEpSyncEnabled
    1.19 +         error:(NSError * _Nullable * _Nullable)error {
    1.20      pEp_identity *ident = PEP_identityToStruct(identity);
    1.21  
    1.22 +    if (!pEpSyncEnabled) {
    1.23 +        ident->flags |= PEP_idf_not_for_sync;
    1.24 +    }
    1.25 +
    1.26      PEPStatus status = (PEPStatus) myself(_session, ident);
    1.27  
    1.28      if ([NSError setError:error fromPEPStatus:status]) {
    1.29 @@ -561,7 +575,7 @@
    1.30          pEp_identity *ident = PEP_identityToStruct(identity);
    1.31  
    1.32          PEPStatus status = (PEPStatus) update_identity(_session, ident);
    1.33 -        
    1.34 +
    1.35          if ([NSError setError:error fromPEPStatus:status]) {
    1.36              free_identity(ident);
    1.37              return NO;
     2.1 --- a/pEpObjCAdapter/PEPSession.m	Fri Nov 29 14:42:14 2019 +0100
     2.2 +++ b/pEpObjCAdapter/PEPSession.m	Wed Dec 04 08:10:31 2019 +0100
     2.3 @@ -172,13 +172,21 @@
     2.4              error:error];
     2.5  }
     2.6  
     2.7 -- (BOOL)mySelf:(PEPIdentity * _Nonnull)identity error:(NSError * _Nullable * _Nullable)error
     2.8 -{
     2.9 +- (BOOL)mySelf:(PEPIdentity * _Nonnull)identity
    2.10 +         error:(NSError * _Nullable * _Nullable)error {
    2.11      PEPInternalSession *session = [PEPSessionProvider session];
    2.12      RETURN_ON_ERROR(session, error, NO);
    2.13      return [session mySelf:identity error:error];
    2.14  }
    2.15  
    2.16 +- (BOOL)mySelf:(PEPIdentity * _Nonnull)identity
    2.17 +pEpSyncEnabled:(BOOL)pEpSyncEnabled
    2.18 +         error:(NSError * _Nullable * _Nullable)error {
    2.19 +    PEPInternalSession *session = [PEPSessionProvider session];
    2.20 +    RETURN_ON_ERROR(session, error, NO);
    2.21 +    return [session mySelf:identity pEpSyncEnabled:pEpSyncEnabled error:error];
    2.22 +}
    2.23 +
    2.24  - (BOOL)updateIdentity:(PEPIdentity * _Nonnull)identity
    2.25                   error:(NSError * _Nullable * _Nullable)error
    2.26  {
     3.1 --- a/pEpObjCAdapterFramework/PEPSessionProtocol.h	Fri Nov 29 14:42:14 2019 +0100
     3.2 +++ b/pEpObjCAdapterFramework/PEPSessionProtocol.h	Wed Dec 04 08:10:31 2019 +0100
     3.3 @@ -85,34 +85,45 @@
     3.4                                        shortened:(BOOL)shortened
     3.5                                            error:(NSError * _Nullable * _Nullable)error;
     3.6  
     3.7 -/**
     3.8 - Supply an account used by our user himself. The identity is supplemented with the missing parts
     3.9 +/// Marks an identity as an own identity, not changing its participation in pEp sync.
    3.10 +///
    3.11 +/// @return Returns YES on success, NO on error, setting `*error` accordingly if possible.
    3.12 +///
    3.13 +/// @note See the engine's myself function for details.
    3.14 +///
    3.15 +/// @param identity The identity to mark as own.
    3.16 +///
    3.17 +/// @param error Standard cocoa error handling.
    3.18 +- (BOOL)mySelf:(PEPIdentity * _Nonnull)identity
    3.19 +         error:(NSError * _Nullable * _Nullable)error;
    3.20  
    3.21 - An identity can have the following fields (all other keys are ignored).
    3.22 - It is not necessary to supply all fields; missing fields are supplemented by p≡p engine.
    3.23 +/// Marks an identity as an own identity, and decides about participation in pEp sync.
    3.24 +///
    3.25 +/// @return Returns YES on success, NO on error, setting `*error` accordingly if possible.
    3.26 +///
    3.27 +/// @note See the engine's myself function for details.
    3.28 +///
    3.29 +/// @param identity The identity to mark as own.
    3.30 +///
    3.31 +/// @param pEpSyncEnabled Whether to enable sync, or not. Will set PEP_idf_not_for_sync
    3.32 +/// accordingly.
    3.33 +///
    3.34 +/// @param error Standard cocoa error handling.
    3.35 +- (BOOL)mySelf:(PEPIdentity * _Nonnull)identity
    3.36 +pEpSyncEnabled:(BOOL)pEpSyncEnabled
    3.37 +         error:(NSError * _Nullable * _Nullable)error;
    3.38  
    3.39 - @"username": real name or nick name (if pseudonymous) of identity
    3.40 - @"address": URI or SMTP address
    3.41 - @"user_id": persistent unique ID for the *user* that belongs to the identity.
    3.42 -                A user can have multiple identities which all of them MUST use the same user_id.
    3.43 - @"lang": preferred languageID for communication with this ID (default: @"en")
    3.44 - @"fpr": fingerprint of key to use for communication with this ID
    3.45 - @"comm_type": communication type code (usually not needed)
    3.46 -
    3.47 - As an example:
    3.48 -
    3.49 - User has a mailbox. The mail address is "Dipul Khatri <dipul@inboxcube.com>". Then this would be:
    3.50 - username = @"Dipul Khatri"
    3.51 - address= @"dipul@inboxcube.com"
    3.52 - user_id" = 23"
    3.53 - */
    3.54 -- (BOOL)mySelf:(PEPIdentity * _Nonnull)identity error:(NSError * _Nullable * _Nullable)error;
    3.55 -
    3.56 -/**
    3.57 - Supplement missing information for an arbitrary identity (used for communication partners).
    3.58 - Will call the engine's myself() or update_identity() internally, depending on the given
    3.59 - identity.
    3.60 - */
    3.61 +/// Calls the engine's update_identity on the given identity.
    3.62 +///
    3.63 +/// @note Prior this was invoking myself if the identity was identified as being an own
    3.64 +/// identity, but this not the case anymore, since it cannot decide if the identity should
    3.65 +/// participate in pEp sync or not.
    3.66 +///
    3.67 +/// @return Returns YES on success, NO on error, setting `*error` accordingly if possible.
    3.68 +///
    3.69 +/// @param identity The identity for which to call update_identity.
    3.70 +/// 
    3.71 +/// @param error Standart cocoa error handling.
    3.72  - (BOOL)updateIdentity:(PEPIdentity * _Nonnull)identity
    3.73                   error:(NSError * _Nullable * _Nullable)error;
    3.74  
     4.1 --- a/pEpObjCTests/PEPSessionTest.m	Fri Nov 29 14:42:14 2019 +0100
     4.2 +++ b/pEpObjCTests/PEPSessionTest.m	Wed Dec 04 08:10:31 2019 +0100
     4.3 @@ -1228,9 +1228,7 @@
     4.4  
     4.5  #pragma mark - Sync
     4.6  
     4.7 -/**
     4.8 - Prove that mySelf triggers a message to be sent.
     4.9 - */
    4.10 +/// Prove that mySelf triggers a message to be sent.
    4.11  - (void)testBasicSendMessage
    4.12  {
    4.13      PEPSession *session = [PEPSession new];
    4.14 @@ -1266,6 +1264,33 @@
    4.15      }
    4.16  }
    4.17  
    4.18 +/// Test the disable of sync via myself.
    4.19 +- (void)testNoBeaconOnMyself
    4.20 +{
    4.21 +    PEPSession *session = [PEPSession new];
    4.22 +
    4.23 +    XCTAssertEqual(self.sendMessageDelegate.messages.count, 0);
    4.24 +    XCTAssertNil(self.sendMessageDelegate.lastMessage);
    4.25 +
    4.26 +    PEPIdentity *identMe = [[PEPIdentity alloc]
    4.27 +                            initWithAddress:@"me-myself-and-i@pep-project.org"
    4.28 +                            userID:@"me-myself-and-i"
    4.29 +                            userName:@"pEp Me"
    4.30 +                            isOwn:YES];
    4.31 +
    4.32 +    NSError *error = nil;
    4.33 +    XCTAssertTrue([session mySelf:identMe pEpSyncEnabled:NO error:&error]);
    4.34 +    XCTAssertNil(error);
    4.35 +
    4.36 +    [self startSync];
    4.37 +
    4.38 +    [NSThread sleepForTimeInterval:2];
    4.39 +    XCTAssertNil(self.sendMessageDelegate.lastMessage);
    4.40 +
    4.41 +    XCTAssertEqual(self.sendMessageDelegate.messages.count, 0);
    4.42 +    [self shutdownSync];
    4.43 +}
    4.44 +
    4.45  #pragma mark - key_reset_identity
    4.46  
    4.47  - (void)testKeyResetIdentity