IOSAD-172 Skeleton for handling messageToSend IOSAD-172
authorDirk Zimmermann <dz@pep.security>
Tue, 30 Jun 2020 11:21:24 +0200
branchIOSAD-172
changeset 1558d2070fae7157
parent 1557 797cf3b33dc1
child 1559 44a86b424af3
IOSAD-172 Skeleton for handling messageToSend
pEpObjCAdapter/PEPSync.m
     1.1 --- a/pEpObjCAdapter/PEPSync.m	Tue Jun 30 09:39:00 2020 +0200
     1.2 +++ b/pEpObjCAdapter/PEPSync.m	Tue Jun 30 11:21:24 2020 +0200
     1.3 @@ -27,7 +27,7 @@
     1.4  
     1.5  static os_log_t s_logger;
     1.6  
     1.7 -typedef PEP_STATUS (* t_messageToSendCallback)(struct _message *msg);
     1.8 +typedef PEP_STATUS (* t_messageToSendCallback)(struct _message * _Nullable msg);
     1.9  typedef int (* t_injectSyncCallback)(SYNC_EVENT ev, void *management);
    1.10  
    1.11  @interface PEPSync ()
    1.12 @@ -48,7 +48,7 @@
    1.13   */
    1.14  + (t_injectSyncCallback)injectSyncCallback;
    1.15  
    1.16 -- (PEP_STATUS)messageToSend:(struct _message *)msg;
    1.17 +- (PEP_STATUS)messageToSend:(struct _message * _Nullable)msg;
    1.18  
    1.19  - (int)injectSyncEvent:(SYNC_EVENT)event isFromShutdown:(BOOL)isFromShutdown;
    1.20  
    1.21 @@ -62,7 +62,7 @@
    1.22  
    1.23  // MARK: - Callbacks called by the engine, used in session init
    1.24  
    1.25 -static PEP_STATUS s_messageToSendObjc(struct _message *msg)
    1.26 +static PEP_STATUS s_messageToSendObjc(struct _message * _Nullable msg)
    1.27  {
    1.28      PEPSync *pEpSync = [PEPSync instance];
    1.29  
    1.30 @@ -238,13 +238,20 @@
    1.31      [self.conditionLockForJoiningSyncThread unlockWithCondition:YES];
    1.32  }
    1.33  
    1.34 -- (PEP_STATUS)messageToSend:(struct _message *)msg
    1.35 +- (PEP_STATUS)messageToSend:(struct _message * _Nullable)msg
    1.36  {
    1.37 -    if (self.sendMessageDelegate) {
    1.38 -        PEPMessage *theMessage = pEpMessageFromStruct(msg);
    1.39 -        return (PEP_STATUS) [self.sendMessageDelegate sendMessage:theMessage];
    1.40 +    if (msg == NULL && [NSThread currentThread] == self.syncThread) {
    1.41 +        // TODO: Handle password management
    1.42 +        return PEP_PASSPHRASE_REQUIRED;
    1.43 +    } else if (msg != NULL) {
    1.44 +        if (self.sendMessageDelegate) {
    1.45 +            PEPMessage *theMessage = pEpMessageFromStruct(msg);
    1.46 +            return (PEP_STATUS) [self.sendMessageDelegate sendMessage:theMessage];
    1.47 +        } else {
    1.48 +            return PEP_SYNC_NO_MESSAGE_SEND_CALLBACK;
    1.49 +        }
    1.50      } else {
    1.51 -        return PEP_SYNC_NO_MESSAGE_SEND_CALLBACK;
    1.52 +        return PEP_SYNC_ILLEGAL_MESSAGE;
    1.53      }
    1.54  }
    1.55