src/sync.c
author Volker Birk <vb@pep.foundation>
Tue, 09 Aug 2016 00:28:53 +0200
branchkeysync
changeset 987 923fdc4de690
parent 986 8f85f70bdd75
child 1043 f786ee22e281
permissions -rw-r--r--
unregister on failure
     1 #include "pEp_internal.h"
     2 
     3 #include <memory.h>
     4 #include <assert.h>
     5 
     6 #include "../asn.1/DeviceGroup-Protocol.h"
     7 
     8 
     9 DYNAMIC_API PEP_STATUS register_sync_callbacks(
    10         PEP_SESSION session,
    11         void *obj,
    12         messageToSend_t messageToSend,
    13         showHandshake_t showHandshake
    14     )
    15 {
    16     session->sync_obj = obj;
    17     session->messageToSend = messageToSend;
    18     session->showHandshake = showHandshake;
    19 
    20     // start state machine
    21     session->sync_state = InitState;
    22     PEP_STATUS status = fsm_DeviceState_inject(session, Init, NULL, NULL);
    23     if (status != PEP_STATUS_OK)
    24         unregister_sync_callbacks(session);
    25 
    26     return status;
    27 }
    28 
    29 DYNAMIC_API void unregister_sync_callbacks(PEP_SESSION session) {
    30     // stop state machine
    31     session->sync_state = DeviceState_state_NONE;
    32 
    33     // unregister
    34     session->sync_obj = NULL;
    35     session->messageToSend = NULL;
    36     session->showHandshake = NULL;
    37 }
    38 
    39 DYNAMIC_API PEP_STATUS deliverHandshakeResult(
    40         PEP_SESSION session,
    41         sync_handshake_result result
    42     )
    43 {
    44     assert(session);
    45     if (!session)
    46         return PEP_ILLEGAL_VALUE;
    47 
    48     switch (result) {
    49         case SYNC_HANDSHAKE_CANCEL:
    50             fsm_DeviceState_inject(session, Cancel, NULL, 0);
    51             break;
    52         case SYNC_HANDSHAKE_ACCEPTED:
    53             fsm_DeviceState_inject(session, HandshakeAccepted, NULL, 0);
    54             break;
    55         case SYNC_HANDSHAKE_REJECTED:
    56             fsm_DeviceState_inject(session, HandshakeRejected, NULL, 0);
    57             break;
    58         default:
    59             return PEP_ILLEGAL_VALUE;
    60     }
    61 
    62     return PEP_STATUS_OK;
    63 }
    64