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
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@602
    32
    session->sync_obj = NULL;
vb@604
    33
    session->messageToSend = NULL;
vb@604
    34
    session->showHandshake = NULL;
vb@572
    35
}
vb@572
    36
vb@679
    37
DYNAMIC_API PEP_STATUS deliverHandshakeResult(
vb@609
    38
        PEP_SESSION session,
vb@609
    39
        sync_handshake_result result
vb@609
    40
    )
vb@609
    41
{
vb@609
    42
    assert(session);
vb@609
    43
    if (!session)
vb@609
    44
        return PEP_ILLEGAL_VALUE;
vb@609
    45
vb@609
    46
    switch (result) {
vb@609
    47
        case SYNC_HANDSHAKE_CANCEL:
vb@690
    48
            fsm_DeviceState_inject(session, Cancel, NULL, 0);
vb@609
    49
            break;
vb@609
    50
        case SYNC_HANDSHAKE_ACCEPTED:
vb@690
    51
            fsm_DeviceState_inject(session, HandshakeAccepted, NULL, 0);
vb@609
    52
            break;
vb@609
    53
        case SYNC_HANDSHAKE_REJECTED:
vb@690
    54
            fsm_DeviceState_inject(session, HandshakeRejected, NULL, 0);
vb@609
    55
            break;
vb@609
    56
        default:
vb@609
    57
            return PEP_ILLEGAL_VALUE;
vb@609
    58
    }
vb@609
    59
vb@609
    60
    return PEP_STATUS_OK;
vb@609
    61
}
vb@609
    62