src/sync.c
author Volker Birk <vb@pep.foundation>
Sun, 31 Jul 2016 19:38:23 +0200
branchkeysync
changeset 951 dec407deb10e
parent 690 3ae86b68fdfe
child 976 75cbd583a894
permissions -rw-r--r--
...
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@572
    20
    return PEP_STATUS_OK;
vb@572
    21
}
vb@572
    22
vb@572
    23
DYNAMIC_API void unregister_sync_callbacks(PEP_SESSION session) {
vb@602
    24
    session->sync_obj = NULL;
vb@604
    25
    session->messageToSend = NULL;
vb@604
    26
    session->showHandshake = NULL;
vb@572
    27
}
vb@572
    28
vb@679
    29
DYNAMIC_API PEP_STATUS deliverHandshakeResult(
vb@609
    30
        PEP_SESSION session,
vb@609
    31
        sync_handshake_result result
vb@609
    32
    )
vb@609
    33
{
vb@609
    34
    assert(session);
vb@609
    35
    if (!session)
vb@609
    36
        return PEP_ILLEGAL_VALUE;
vb@609
    37
vb@609
    38
    switch (result) {
vb@609
    39
        case SYNC_HANDSHAKE_CANCEL:
vb@690
    40
            fsm_DeviceState_inject(session, Cancel, NULL, 0);
vb@609
    41
            break;
vb@609
    42
        case SYNC_HANDSHAKE_ACCEPTED:
vb@690
    43
            fsm_DeviceState_inject(session, HandshakeAccepted, NULL, 0);
vb@609
    44
            break;
vb@609
    45
        case SYNC_HANDSHAKE_REJECTED:
vb@690
    46
            fsm_DeviceState_inject(session, HandshakeRejected, NULL, 0);
vb@609
    47
            break;
vb@609
    48
        default:
vb@609
    49
            return PEP_ILLEGAL_VALUE;
vb@609
    50
    }
vb@609
    51
vb@609
    52
    return PEP_STATUS_OK;
vb@609
    53
}
vb@609
    54