IOSAD-121 Better macro. IOSAD-121
authorDirk Zimmermann <dz@pep.security>
Thu, 25 Jul 2019 10:47:04 +0200
branchIOSAD-121
changeset 11074283084b59e2
parent 1106 fb23fbc7b4d6
child 1108 b61cf4d87e40
IOSAD-121 Better macro.
pEpObjCAdapter/PEPSession.m
     1.1 --- a/pEpObjCAdapter/PEPSession.m	Thu Jul 25 10:47:04 2019 +0200
     1.2 +++ b/pEpObjCAdapter/PEPSession.m	Thu Jul 25 10:47:04 2019 +0200
     1.3 @@ -18,13 +18,13 @@
     1.4  
     1.5  @implementation PEPSession
     1.6  
     1.7 -#define RETURN_NIL_ON_ERROR(session, error)\
     1.8 - if (session == nil) { \
     1.9 -   if (error != nil) { \
    1.10 -     *error = [NSError errorWithPEPStatusInternal:PEP_UNKNOWN_ERROR]; \
    1.11 -     return nil; \
    1.12 -   } \
    1.13 - }
    1.14 +#define RETURN_ON_ERROR(session, error, what)\
    1.15 +  if (session == nil) { \
    1.16 +    if (error != nil) { \
    1.17 +      *error = [NSError errorWithPEPStatusInternal:PEP_UNKNOWN_ERROR]; \
    1.18 +      return what; \
    1.19 +    } \
    1.20 +  }
    1.21  
    1.22  #pragma mark - Public API
    1.23  
    1.24 @@ -41,7 +41,7 @@
    1.25                                      error:(NSError * _Nullable * _Nullable)error
    1.26  {
    1.27      PEPInternalSession *session = [PEPSessionProvider session];
    1.28 -    RETURN_NIL_ON_ERROR(session, error);
    1.29 +    RETURN_ON_ERROR(session, error, nil);
    1.30      return [session
    1.31              decryptMessageDict:messageDict
    1.32              flags:flags
    1.33 @@ -59,7 +59,7 @@
    1.34                                     error:(NSError * _Nullable * _Nullable)error
    1.35  {
    1.36      PEPInternalSession *session = [PEPSessionProvider session];
    1.37 -    RETURN_NIL_ON_ERROR(session, error);
    1.38 +    RETURN_ON_ERROR(session, error, nil);
    1.39      return [session
    1.40              decryptMessage:message
    1.41              flags:flags
    1.42 @@ -104,7 +104,7 @@
    1.43                                      error:(NSError * _Nullable * _Nullable)error
    1.44  {
    1.45      PEPInternalSession *session = [PEPSessionProvider session];
    1.46 -    RETURN_NIL_ON_ERROR(session, error);
    1.47 +    RETURN_ON_ERROR(session, error, nil);
    1.48      return [session
    1.49              encryptMessageDict:messageDict
    1.50              extraKeys:extraKeys
    1.51 @@ -120,7 +120,7 @@
    1.52                                     error:(NSError * _Nullable * _Nullable)error
    1.53  {
    1.54      PEPInternalSession *session = [PEPSessionProvider session];
    1.55 -    RETURN_NIL_ON_ERROR(session, error);
    1.56 +    RETURN_ON_ERROR(session, error, nil);
    1.57      return [session
    1.58              encryptMessage:message
    1.59              extraKeys:extraKeys
    1.60 @@ -135,7 +135,7 @@
    1.61                                     error:(NSError * _Nullable * _Nullable)error
    1.62  {
    1.63      PEPInternalSession *session = [PEPSessionProvider session];
    1.64 -    RETURN_NIL_ON_ERROR(session, error);
    1.65 +    RETURN_ON_ERROR(session, error, nil);
    1.66      return [session encryptMessage:message extraKeys:extraKeys status:status error:error];
    1.67  }
    1.68  
    1.69 @@ -146,7 +146,7 @@
    1.70                                      error:(NSError * _Nullable * _Nullable)error
    1.71  {
    1.72      PEPInternalSession *session = [PEPSessionProvider session];
    1.73 -    RETURN_NIL_ON_ERROR(session, error);
    1.74 +    RETURN_ON_ERROR(session, error, nil);
    1.75      return [session
    1.76              encryptMessageDict:messageDict
    1.77              forSelf:ownIdentity
    1.78 @@ -162,7 +162,7 @@
    1.79                                     error:(NSError * _Nullable * _Nullable)error
    1.80  {
    1.81      PEPInternalSession *session = [PEPSessionProvider session];
    1.82 -    RETURN_NIL_ON_ERROR(session, error);
    1.83 +    RETURN_ON_ERROR(session, error, nil);
    1.84      return [session
    1.85              encryptMessage:message
    1.86              forSelf:ownIdentity
    1.87 @@ -179,7 +179,7 @@
    1.88                                      error:(NSError * _Nullable * _Nullable)error __deprecated
    1.89  {
    1.90      PEPInternalSession *session = [PEPSessionProvider session];
    1.91 -    RETURN_NIL_ON_ERROR(session, error);
    1.92 +    RETURN_ON_ERROR(session, error, nil);
    1.93      return [session
    1.94              encryptMessageDict:messageDict
    1.95              toFpr:toFpr
    1.96 @@ -197,7 +197,7 @@
    1.97                                     error:(NSError * _Nullable * _Nullable)error
    1.98  {
    1.99      PEPInternalSession *session = [PEPSessionProvider session];
   1.100 -    RETURN_NIL_ON_ERROR(session, error);
   1.101 +    RETURN_ON_ERROR(session, error, nil);
   1.102      return [session
   1.103              encryptMessage:message
   1.104              toFpr:toFpr
   1.105 @@ -211,7 +211,7 @@
   1.106                                             error:(NSError * _Nullable * _Nullable)error
   1.107  {
   1.108      PEPInternalSession *session = [PEPSessionProvider session];
   1.109 -    RETURN_NIL_ON_ERROR(session, error);
   1.110 +    RETURN_ON_ERROR(session, error, nil);
   1.111      return [session outgoingRatingForMessage:theMessage error:error];
   1.112  }
   1.113  
   1.114 @@ -219,7 +219,7 @@
   1.115                                                    error:(NSError * _Nullable * _Nullable)error
   1.116  {
   1.117      PEPInternalSession *session = [PEPSessionProvider session];
   1.118 -    RETURN_NIL_ON_ERROR(session, error);
   1.119 +    RETURN_ON_ERROR(session, error, nil);
   1.120      return [session outgoingRatingPreviewForMessage:theMessage error:error];
   1.121  }
   1.122  
   1.123 @@ -227,7 +227,7 @@
   1.124                                      error:(NSError * _Nullable * _Nullable)error
   1.125  {
   1.126      PEPInternalSession *session = [PEPSessionProvider session];
   1.127 -    RETURN_NIL_ON_ERROR(session, error);
   1.128 +    RETURN_ON_ERROR(session, error, nil);
   1.129      return [session ratingForIdentity:identity error:error];
   1.130  }
   1.131  
   1.132 @@ -237,7 +237,7 @@
   1.133                                            error:(NSError * _Nullable * _Nullable)error
   1.134  {
   1.135      PEPInternalSession *session = [PEPSessionProvider session];
   1.136 -    RETURN_NIL_ON_ERROR(session, error);
   1.137 +    RETURN_ON_ERROR(session, error, nil);
   1.138      return [session
   1.139              trustwordsForFingerprint:fingerprint
   1.140              languageID:languageID
   1.141 @@ -285,7 +285,7 @@
   1.142                             error:(NSError * _Nullable * _Nullable)error
   1.143  {
   1.144      PEPInternalSession *session = [PEPSessionProvider session];
   1.145 -    RETURN_NIL_ON_ERROR(session, error);
   1.146 +    RETURN_ON_ERROR(session, error, nil);
   1.147      return [session importKey:keydata error:error];
   1.148  }
   1.149  
   1.150 @@ -307,7 +307,7 @@
   1.151  - (NSString * _Nullable)getLogWithError:(NSError * _Nullable * _Nullable)error
   1.152  {
   1.153      PEPInternalSession *session = [PEPSessionProvider session];
   1.154 -    RETURN_NIL_ON_ERROR(session, error);
   1.155 +    RETURN_ON_ERROR(session, error, nil);
   1.156      return [session getLogWithError:error];
   1.157  }
   1.158  
   1.159 @@ -318,7 +318,7 @@
   1.160                                           error:(NSError * _Nullable * _Nullable)error
   1.161  {
   1.162      PEPInternalSession *session = [PEPSessionProvider session];
   1.163 -    RETURN_NIL_ON_ERROR(session, error);
   1.164 +    RETURN_ON_ERROR(session, error, nil);
   1.165      return [session getTrustwordsIdentity1:identity1
   1.166                                   identity2:identity2
   1.167                                    language:language
   1.168 @@ -333,14 +333,14 @@
   1.169                                      error:(NSError * _Nullable * _Nullable)error
   1.170  {
   1.171      PEPInternalSession *session = [PEPSessionProvider session];
   1.172 -    RETURN_NIL_ON_ERROR(session, error);
   1.173 +    RETURN_ON_ERROR(session, error, nil);
   1.174      return [session getTrustwordsFpr1:fpr1 fpr2:fpr2 language:language full:full error:error];
   1.175  }
   1.176  
   1.177  - (NSArray<PEPLanguage *> * _Nullable)languageListWithError:(NSError * _Nullable * _Nullable)error
   1.178  {
   1.179      PEPInternalSession *session = [PEPSessionProvider session];
   1.180 -    RETURN_NIL_ON_ERROR(session, error);
   1.181 +    RETURN_ON_ERROR(session, error, nil);
   1.182      return [session languageListWithError:error];
   1.183  }
   1.184  
   1.185 @@ -360,7 +360,7 @@
   1.186                              error:(NSError * _Nullable * _Nullable)error
   1.187  {
   1.188      PEPInternalSession *session = [PEPSessionProvider session];
   1.189 -    RETURN_NIL_ON_ERROR(session, error);
   1.190 +    RETURN_ON_ERROR(session, error, nil);
   1.191      return [session isPEPUser:identity error:error];
   1.192  }
   1.193