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
vb@572
     1
#include "pEp_internal.h"
vb@572
     2
vb@572
     3
#include <memory.h>
vb@572
     4
#include <assert.h>
vb@572
     5
vb@951
     6
#include "../asn.1/DeviceGroup-Protocol.h"
vb@951
     7
vb@572
     8
vb@572
     9
DYNAMIC_API PEP_STATUS register_sync_callbacks(
vb@599
    10
        PEP_SESSION session,
vb@599
    11
        void *obj,
vb@597
    12
        messageToSend_t messageToSend,
vb@572
    13
        showHandshake_t showHandshake
vb@572
    14
    )
vb@572
    15
{
vb@599
    16
    session->sync_obj = obj;
vb@604
    17
    session->messageToSend = messageToSend;
vb@604
    18
    session->showHandshake = showHandshake;
vb@572
    19
vb@976
    20
    // start state machine
vb@976
    21
    session->sync_state = InitState;
vb@976
    22
    PEP_STATUS status = fsm_DeviceState_inject(session, Init, NULL, NULL);
vb@987
    23
    if (status != PEP_STATUS_OK)
vb@987
    24
        unregister_sync_callbacks(session);
vb@976
    25
vb@976
    26
    return status;
vb@572
    27
}
vb@572
    28
vb@572
    29
DYNAMIC_API void unregister_sync_callbacks(PEP_SESSION session) {
vb@986
    30
    // stop state machine
vb@986
    31
    session->sync_state = DeviceState_state_NONE;
vb@986
    32
vb@986
    33
    // unregister
vb@602
    34
    session->sync_obj = NULL;
vb@604
    35
    session->messageToSend = NULL;
vb@604
    36
    session->showHandshake = NULL;
vb@572
    37
}
vb@572
    38
vb@679
    39
DYNAMIC_API PEP_STATUS deliverHandshakeResult(
vb@609
    40
        PEP_SESSION session,
vb@609
    41
        sync_handshake_result result
vb@609
    42
    )
vb@609
    43
{
vb@609
    44
    assert(session);
vb@609
    45
    if (!session)
vb@609
    46
        return PEP_ILLEGAL_VALUE;
vb@609
    47
vb@609
    48
    switch (result) {
vb@609
    49
        case SYNC_HANDSHAKE_CANCEL:
vb@690
    50
            fsm_DeviceState_inject(session, Cancel, NULL, 0);
vb@609
    51
            break;
vb@609
    52
        case SYNC_HANDSHAKE_ACCEPTED:
vb@690
    53
            fsm_DeviceState_inject(session, HandshakeAccepted, NULL, 0);
vb@609
    54
            break;
vb@609
    55
        case SYNC_HANDSHAKE_REJECTED:
vb@690
    56
            fsm_DeviceState_inject(session, HandshakeRejected, NULL, 0);
vb@609
    57
            break;
vb@609
    58
        default:
vb@609
    59
            return PEP_ILLEGAL_VALUE;
vb@609
    60
    }
vb@609
    61
vb@609
    62
    return PEP_STATUS_OK;
vb@609
    63
}
vb@609
    64