src/sync.h
author Volker Birk <vb@pep.foundation>
Sat, 20 Aug 2016 14:45:19 +0200
branchkeysync
changeset 1043 f786ee22e281
parent 1003 e5eef6e5b153
child 1116 c9a03f2423c1
permissions -rw-r--r--
empty address allowed for myself()
vb@572
     1
#pragma once
vb@572
     2
vb@572
     3
#include "message.h"
vb@690
     4
#include "sync_fsm.h"
vb@572
     5
vb@572
     6
vb@572
     7
// this module is for being used WITHOUT the Transport API in transport.h
vb@572
     8
// DO NOT USE IT WHEN USING Transport API!
vb@572
     9
vb@572
    10
vb@572
    11
#ifdef __cplusplus
vb@572
    12
extern "C" {
vb@572
    13
#endif
vb@572
    14
vb@1043
    15
// messageToSend() - send a message
vb@572
    16
//
vb@572
    17
//  parameters:
vb@599
    18
//      obj (in)        object handle (implementation defined)
vb@598
    19
//      msg (in)        message struct with message to send
vb@572
    20
//
vb@572
    21
//  return value:
vb@604
    22
//      PEP_STATUS_OK or any other value on error
vb@991
    23
//
vb@991
    24
//  caveat:
vb@991
    25
//      the ownership of msg goes to the callee
vb@572
    26
vb@991
    27
typedef PEP_STATUS (*messageToSend_t)(void *obj, message *msg);
vb@572
    28
vb@572
    29
vb@572
    30
typedef enum _sync_handshake_result {
vb@572
    31
    SYNC_HANDSHAKE_CANCEL = -1,
vb@572
    32
    SYNC_HANDSHAKE_ACCEPTED = 0,
vb@572
    33
    SYNC_HANDSHAKE_REJECTED = 1
vb@572
    34
} sync_handshake_result;
vb@572
    35
vb@609
    36
// showHandshake() - do a handshake by showing the handshake dialog
vb@572
    37
//
vb@572
    38
//  parameters:
vb@599
    39
//      obj (in)        object handle (implementation defined)
vb@1003
    40
//      me (in)         own identity
vb@572
    41
//      partner (in)    identity of partner
vb@572
    42
//
vb@572
    43
//  return value:
vb@604
    44
//      PEP_STATUS_OK or any other value on error
vb@991
    45
//
vb@991
    46
//  caveat:
vb@991
    47
//      ownership of self and partner go to the callee
vb@572
    48
vb@604
    49
typedef PEP_STATUS (*showHandshake_t)(
vb@599
    50
        void *obj,
vb@1003
    51
        pEp_identity *me,
vb@991
    52
        pEp_identity *partner
vb@609
    53
    );
vb@609
    54
vb@609
    55
vb@609
    56
// deliverHandshakeResult() - give the result of the handshake dialog
vb@609
    57
//
vb@609
    58
//  parameters:
vb@1043
    59
//      session (in)        session handle
vb@1043
    60
//      result (in)         handshake result
vb@609
    61
vb@679
    62
DYNAMIC_API PEP_STATUS deliverHandshakeResult(
vb@609
    63
        PEP_SESSION session,
vb@609
    64
        sync_handshake_result result
vb@572
    65
    );
vb@572
    66
vb@572
    67
vb@1043
    68
// inject_sync_msg - inject sync protocol message
vb@1043
    69
//
vb@1043
    70
//  parameters:
vb@1043
    71
//      msg (in)            message to inject
vb@1043
    72
//      management (in)     application defined
vb@1043
    73
//
vb@1043
    74
//  return value:
vb@1043
    75
//      0 if msg could be stored successfully or nonzero otherwise
vb@1043
    76
vb@1043
    77
typedef int (*inject_sync_msg_t)(void *msg, void *management);
vb@1043
    78
vb@1043
    79
vb@1043
    80
// retrieve_next_sync_msg - receive next sync message
vb@1043
    81
//
vb@1043
    82
//  parameters:
vb@1043
    83
//      management (in)     application defined
vb@1043
    84
//
vb@1043
    85
//  return value:
vb@1043
    86
//      next message or NULL for termination
vb@1043
    87
vb@1043
    88
typedef void *(*retrieve_next_sync_msg_t)(void *management);
vb@1043
    89
vb@1043
    90
vb@572
    91
// register_sync_callbacks() - register adapter's callbacks
vb@572
    92
//
vb@572
    93
//  parameters:
vb@599
    94
//      session (in)                session where to store obj handle
vb@599
    95
//      obj (in)                    object handle (implementation defined)
vb@599
    96
//      messageToSend (in)          callback for sending message
vb@572
    97
//      showHandshake (in)          callback for doing the handshake
vb@1043
    98
//      retrieve_next_sync_msg (in) callback for receiving sync messages
vb@572
    99
//
vb@572
   100
//  return value:
vb@572
   101
//      PEP_STATUS_OK or any other value on errror
vb@573
   102
//
vb@573
   103
//  caveat:
vb@573
   104
//      call that BEFORE you're using any other part of the engine
vb@572
   105
vb@572
   106
DYNAMIC_API PEP_STATUS register_sync_callbacks(
vb@599
   107
        PEP_SESSION session,
vb@599
   108
        void *obj,
vb@597
   109
        messageToSend_t messageToSend,
vb@1043
   110
        showHandshake_t showHandshake,
vb@1043
   111
        inject_sync_msg_t inject_sync_msg,
vb@1043
   112
        retrieve_next_sync_msg_t retrieve_next_sync_msg
vb@572
   113
    );
vb@572
   114
vb@572
   115
vb@572
   116
// unregister_sync_callbacks() - unregister adapter's callbacks
vb@602
   117
//
vb@602
   118
//  parameters:
vb@602
   119
//      session (in)                session where to store obj handle
vb@572
   120
vb@602
   121
DYNAMIC_API void unregister_sync_callbacks(PEP_SESSION session);
vb@572
   122
vb@572
   123
vb@1043
   124
// do_sync_protocol - function to be run on an extra thread
vb@1043
   125
//
vb@1043
   126
//  parameters:
vb@1043
   127
//      session                 pEp session to use
vb@1043
   128
//      retrieve_next_sync_msg  pointer to retrieve_next_identity() callback
vb@1043
   129
//                              which returns at least a valid address field in
vb@1043
   130
//                              the identity struct
vb@1043
   131
//      management              management data to give to keymanagement
vb@1043
   132
//                              (implementation defined)
vb@1043
   133
//
vb@1043
   134
//  return value:
vb@1043
   135
//      PEP_STATUS_OK if thread has to terminate successfully or any other
vb@1043
   136
//      value on failure
vb@1043
   137
//
vb@1043
   138
//  caveat:
vb@1043
   139
//      to ensure proper working of this library, a thread has to be started
vb@1043
   140
//      with this function immediately after initialization
vb@1043
   141
//      do_keymanagement() calls retrieve_next_identity(management)
vb@1043
   142
vb@1043
   143
DYNAMIC_API PEP_STATUS do_sync_protocol(
vb@1043
   144
        PEP_SESSION session,
vb@1043
   145
        void *management
vb@1043
   146
    );
vb@1043
   147
vb@1043
   148
vb@572
   149
#ifdef __cplusplus
vb@572
   150
}
vb@572
   151
#endif
vb@572
   152