src/sync_actions.c
author Volker Birk <vb@pep-project.org>
Fri, 29 Jul 2016 10:45:13 +0200
branchkeysync
changeset 939 ed7dfdae3031
parent 907 8f5cca5bfa2d
child 951 dec407deb10e
permissions -rw-r--r--
changing message_api: adding flags to encrypt_message()
vb@623
     1
// Actions for DeviceState state machine
vb@623
     2
vb@623
     3
#include <assert.h>
vb@690
     4
#include "pEp_internal.h"
vb@690
     5
#include "message.h"
vb@623
     6
#include "sync_fsm.h"
vb@623
     7
vb@650
     8
vb@884
     9
// showHandshake() - trigger the handshake dialog of the application
vb@623
    10
//
vb@623
    11
//  params:
vb@627
    12
//      session (in)        session handle
vb@690
    13
//      state (in)          state the state machine is in
vb@807
    14
//      partner (in)        partner to communicate with
vb@623
    15
//
vb@623
    16
//  returns:
vb@623
    17
//      PEP_STATUS_OK or any other value on error
vb@623
    18
vb@690
    19
PEP_STATUS showHandshake(
vb@690
    20
        PEP_SESSION session,
vb@690
    21
        DeviceState_state state,
vb@939
    22
        Identity partner,
vb@939
    23
        void *extra
vb@690
    24
    )
vb@623
    25
{
vb@623
    26
    PEP_STATUS status = PEP_STATUS_OK;
vb@939
    27
vb@650
    28
    assert(session);
vb@665
    29
    assert(partner);
vb@939
    30
    assert(extra == NULL);
vb@939
    31
vb@665
    32
    if (!(session && partner))
vb@665
    33
        return PEP_ILLEGAL_VALUE;
vb@939
    34
vb@907
    35
    assert(session->showHandshake);
vb@884
    36
    if (!session->showHandshake)
vb@884
    37
        return PEP_SYNC_NO_TRUSTWORDS_CALLBACK;
vb@623
    38
vb@884
    39
    pEp_identity *me = NULL;
vb@884
    40
    status = get_identity(session, partner->address, PEP_OWN_USERID, &me);
vb@884
    41
    if (status != PEP_STATUS_OK)
vb@884
    42
        goto error;
vb@884
    43
    
vb@884
    44
    status = session->showHandshake(session, me, partner);
vb@884
    45
    if (status != PEP_STATUS_OK)
vb@884
    46
        goto error;
vb@623
    47
vb@884
    48
    free_identity(me);
vb@623
    49
    return status;
vb@650
    50
vb@650
    51
enomem:
vb@650
    52
    status = PEP_OUT_OF_MEMORY;
vb@650
    53
error:
vb@884
    54
    free_identity(me);
vb@650
    55
    return status;
vb@623
    56
}
vb@623
    57
vb@650
    58
vb@907
    59
// reject() - stores rejection of partner
vb@623
    60
//
vb@623
    61
//  params:
vb@627
    62
//      session (in)        session handle
vb@690
    63
//      state (in)          state the state machine is in
vb@807
    64
//      partner (in)        partner to communicate with
vb@623
    65
//
vb@623
    66
//  returns:
vb@623
    67
//      PEP_STATUS_OK or any other value on error
vb@623
    68
vb@690
    69
PEP_STATUS reject(
vb@690
    70
        PEP_SESSION session,
vb@690
    71
        DeviceState_state state,
vb@939
    72
        Identity partner,
vb@939
    73
        void *extra
vb@690
    74
    )
vb@623
    75
{
vb@623
    76
    PEP_STATUS status = PEP_STATUS_OK;
vb@623
    77
vb@650
    78
    assert(session);
vb@665
    79
    assert(partner);
vb@939
    80
    assert(extra == NULL);
vb@665
    81
    if (!(session && partner))
vb@665
    82
        return PEP_ILLEGAL_VALUE;
vb@623
    83
vb@939
    84
    status = set_identity_flags(session, partner,
vb@939
    85
            partner->flags | PEP_idf_not_for_sync);
vb@623
    86
vb@623
    87
    return status;
vb@650
    88
vb@650
    89
enomem:
vb@650
    90
    status = PEP_OUT_OF_MEMORY;
vb@650
    91
error:
vb@650
    92
    // free...
vb@650
    93
    return status;
vb@623
    94
}
vb@623
    95
vb@650
    96
vb@657
    97
// storeGroupKeys() - 
vb@623
    98
//
vb@623
    99
//  params:
vb@627
   100
//      session (in)        session handle
vb@690
   101
//      state (in)          state the state machine is in
vb@807
   102
//      partner (in)        partner to communicate with
vb@939
   103
//      _group_keys (in)    group keys received from partner
vb@623
   104
//
vb@623
   105
//  returns:
vb@623
   106
//      PEP_STATUS_OK or any other value on error
vb@623
   107
vb@690
   108
PEP_STATUS storeGroupKeys(
vb@690
   109
        PEP_SESSION session,
vb@690
   110
        DeviceState_state state,
vb@939
   111
        Identity partner,
vb@939
   112
        void *_group_keys
vb@690
   113
    )
vb@623
   114
{
vb@623
   115
    PEP_STATUS status = PEP_STATUS_OK;
vb@623
   116
vb@650
   117
    assert(session);
vb@665
   118
    assert(partner);
vb@939
   119
    assert(_group_keys);
vb@939
   120
    if (!(session && partner && _group_keys))
vb@665
   121
        return PEP_ILLEGAL_VALUE;
vb@623
   122
vb@939
   123
    Stringlist group_keys = (Stringlist) _group_keys;
vb@623
   124
vb@623
   125
vb@623
   126
    return status;
vb@650
   127
vb@650
   128
enomem:
vb@650
   129
    status = PEP_OUT_OF_MEMORY;
vb@650
   130
error:
vb@650
   131
    // free...
vb@650
   132
    return status;
vb@623
   133
}
vb@623
   134