src/sync.c
author Volker Birk <vb@pep.foundation>
Fri, 05 Aug 2016 13:22:55 +0200
branchkeysync
changeset 976 75cbd583a894
parent 951 dec407deb10e
child 986 8f85f70bdd75
permissions -rw-r--r--
start state machine on register
     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         // stop state machine
    25         session->sync_state = DeviceState_state_NONE;
    26     }
    27 
    28     return status;
    29 }
    30 
    31 DYNAMIC_API void unregister_sync_callbacks(PEP_SESSION session) {
    32     session->sync_obj = NULL;
    33     session->messageToSend = NULL;
    34     session->showHandshake = NULL;
    35 }
    36 
    37 DYNAMIC_API PEP_STATUS deliverHandshakeResult(
    38         PEP_SESSION session,
    39         sync_handshake_result result
    40     )
    41 {
    42     assert(session);
    43     if (!session)
    44         return PEP_ILLEGAL_VALUE;
    45 
    46     switch (result) {
    47         case SYNC_HANDSHAKE_CANCEL:
    48             fsm_DeviceState_inject(session, Cancel, NULL, 0);
    49             break;
    50         case SYNC_HANDSHAKE_ACCEPTED:
    51             fsm_DeviceState_inject(session, HandshakeAccepted, NULL, 0);
    52             break;
    53         case SYNC_HANDSHAKE_REJECTED:
    54             fsm_DeviceState_inject(session, HandshakeRejected, NULL, 0);
    55             break;
    56         default:
    57             return PEP_ILLEGAL_VALUE;
    58     }
    59 
    60     return PEP_STATUS_OK;
    61 }
    62