src/sync.c
author Volker Birk <vb@pep.foundation>
Tue, 09 Aug 2016 00:08:08 +0200
branchkeysync
changeset 986 8f85f70bdd75
parent 976 75cbd583a894
child 987 923fdc4de690
permissions -rw-r--r--
auto stop keysync on release() of session
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@976
    23
    if (status != PEP_STATUS_OK) {
vb@976
    24
        // stop state machine
vb@976
    25
        session->sync_state = DeviceState_state_NONE;
vb@976
    26
    }
vb@976
    27
vb@976
    28
    return status;
vb@572
    29
}
vb@572
    30
vb@572
    31
DYNAMIC_API void unregister_sync_callbacks(PEP_SESSION session) {
vb@986
    32
    // stop state machine
vb@986
    33
    session->sync_state = DeviceState_state_NONE;
vb@986
    34
vb@986
    35
    // unregister
vb@602
    36
    session->sync_obj = NULL;
vb@604
    37
    session->messageToSend = NULL;
vb@604
    38
    session->showHandshake = NULL;
vb@572
    39
}
vb@572
    40
vb@679
    41
DYNAMIC_API PEP_STATUS deliverHandshakeResult(
vb@609
    42
        PEP_SESSION session,
vb@609
    43
        sync_handshake_result result
vb@609
    44
    )
vb@609
    45
{
vb@609
    46
    assert(session);
vb@609
    47
    if (!session)
vb@609
    48
        return PEP_ILLEGAL_VALUE;
vb@609
    49
vb@609
    50
    switch (result) {
vb@609
    51
        case SYNC_HANDSHAKE_CANCEL:
vb@690
    52
            fsm_DeviceState_inject(session, Cancel, NULL, 0);
vb@609
    53
            break;
vb@609
    54
        case SYNC_HANDSHAKE_ACCEPTED:
vb@690
    55
            fsm_DeviceState_inject(session, HandshakeAccepted, NULL, 0);
vb@609
    56
            break;
vb@609
    57
        case SYNC_HANDSHAKE_REJECTED:
vb@690
    58
            fsm_DeviceState_inject(session, HandshakeRejected, NULL, 0);
vb@609
    59
            break;
vb@609
    60
        default:
vb@609
    61
            return PEP_ILLEGAL_VALUE;
vb@609
    62
    }
vb@609
    63
vb@609
    64
    return PEP_STATUS_OK;
vb@609
    65
}
vb@609
    66