src/sync_api.h
author us@chu.huenfield.org
Tue, 25 Dec 2018 14:46:45 +0100
branchsync
changeset 3209 c15b4ca2b52a
parent 3108 f6f11b35af07
child 3383 da42a8ac645f
permissions -rw-r--r--
Replace use of Sequoia's backend with a custom key store.

- Sequoia's key store doesn't meet pep's needs (in particular, the
ability to search on a key's user id) and trying to shoehorn pep's
needs onto Sequoia's key store abstractions is just introducing
overhead with no appreciable gain in functionality.

- This patch changes the Sequoia backend to use a local sqlite
database to store the public keys.
krista@2271
     1
// This file is under GNU General Public License 3.0
krista@2271
     2
// see LICENSE.txt
krista@2271
     3
krista@2271
     4
#pragma once
krista@2271
     5
vb@2839
     6
krista@2271
     7
#include "message.h"
vb@2839
     8
krista@2271
     9
krista@2271
    10
#ifdef __cplusplus
krista@2271
    11
extern "C" {
krista@2271
    12
#endif
krista@2271
    13
vb@2836
    14
vb@2830
    15
typedef enum _sync_handshake_signal {
vb@2830
    16
    SYNC_NOTIFY_UNDEFINED = 0,
vb@2830
    17
vb@2830
    18
    // request show handshake dialog
vb@2830
    19
    SYNC_NOTIFY_INIT_ADD_OUR_DEVICE,
vb@2830
    20
    SYNC_NOTIFY_INIT_ADD_OTHER_DEVICE,
vb@2830
    21
    SYNC_NOTIFY_INIT_FORM_GROUP,
vb@2830
    22
    SYNC_NOTIFY_INIT_MOVE_OUR_DEVICE,
vb@2830
    23
vb@2830
    24
    // handshake process timed out
vb@2830
    25
    SYNC_NOTIFY_TIMEOUT,
vb@2830
    26
vb@2830
    27
    // handshake accepted by user
vb@2830
    28
    SYNC_NOTIFY_ACCEPTED_DEVICE_ADDED,
vb@2830
    29
    SYNC_NOTIFY_ACCEPTED_GROUP_CREATED,
vb@2830
    30
    SYNC_NOTIFY_ACCEPTED_DEVICE_MOVED,
vb@2830
    31
vb@2830
    32
    // handshake dialog must be closed
vb@2830
    33
    SYNC_NOTIFY_OVERTAKEN
vb@2830
    34
} sync_handshake_signal;
vb@2830
    35
krista@2271
    36
krista@2271
    37
// notifyHandshake() - notify UI about sync handshaking process
krista@2271
    38
//
krista@2271
    39
//  parameters:
krista@2271
    40
//      obj (in)        object handle (implementation defined)
krista@2271
    41
//      me (in)         own identity
krista@2271
    42
//      partner (in)    identity of partner
krista@2271
    43
//      signal (in)     reason of the notification
krista@2271
    44
//
krista@2271
    45
//  return value:
krista@2271
    46
//      PEP_STATUS_OK or any other value on error
krista@2271
    47
//
krista@2271
    48
//  caveat:
krista@2271
    49
//      ownership of self and partner go to the callee
krista@2271
    50
krista@2271
    51
typedef PEP_STATUS (*notifyHandshake_t)(
krista@2271
    52
        pEp_identity *me,
krista@2271
    53
        pEp_identity *partner,
krista@2271
    54
        sync_handshake_signal signal
krista@2271
    55
    );
krista@2271
    56
krista@2271
    57
typedef enum _sync_handshake_result {
krista@2271
    58
    SYNC_HANDSHAKE_CANCEL = -1,
krista@2271
    59
    SYNC_HANDSHAKE_ACCEPTED = 0,
krista@2271
    60
    SYNC_HANDSHAKE_REJECTED = 1
krista@2271
    61
} sync_handshake_result;
krista@2271
    62
krista@2271
    63
// deliverHandshakeResult() - give the result of the handshake dialog
krista@2271
    64
//
krista@2271
    65
//  parameters:
krista@2271
    66
//      session (in)        session handle
krista@2271
    67
//      result (in)         handshake result
krista@2271
    68
krista@2271
    69
DYNAMIC_API PEP_STATUS deliverHandshakeResult(
krista@2271
    70
        PEP_SESSION session,
vb@2830
    71
        pEp_identity *partner,
krista@2271
    72
        sync_handshake_result result
krista@2271
    73
    );
krista@2271
    74
krista@2271
    75
vb@2839
    76
// retrieve_next_sync_event - receive next sync event
krista@2271
    77
//
krista@2271
    78
//  parameters:
vb@2850
    79
//      management (in)     application defined; usually a locked queue
vb@2909
    80
//      threshold (in)      threshold in seconds for timeout
krista@2271
    81
//
krista@2271
    82
//  return value:
vb@2839
    83
//      next event
vb@2912
    84
//
vb@2912
    85
//  caveat:
vb@2912
    86
//      an implementation of retrieve_next_sync_event must return
vb@2912
    87
//      new_sync_timeout_event() in case of timeout
krista@2271
    88
vb@2909
    89
typedef SYNC_EVENT (*retrieve_next_sync_event_t)(void *management,
vb@3108
    90
        unsigned threshold);
krista@2271
    91
krista@2271
    92
krista@2271
    93
// register_sync_callbacks() - register adapter's callbacks
krista@2271
    94
//
krista@2271
    95
//  parameters:
vb@2839
    96
//      session (in)                    session where to store obj handle
vb@2850
    97
//      management (in)                 application defined; usually a locked queue
vb@2839
    98
//      notifyHandshake (in)            callback for doing the handshake
vb@2839
    99
//      retrieve_next_sync_event (in)   callback for receiving sync event
krista@2271
   100
//
krista@2271
   101
//  return value:
krista@2271
   102
//      PEP_STATUS_OK or any other value on errror
krista@2271
   103
//
krista@2271
   104
//  caveat:
krista@2271
   105
//      call that BEFORE you're using any other part of the engine
krista@2271
   106
krista@2271
   107
DYNAMIC_API PEP_STATUS register_sync_callbacks(
krista@2271
   108
        PEP_SESSION session,
krista@2271
   109
        void *management,
krista@2271
   110
        notifyHandshake_t notifyHandshake,
vb@2839
   111
        retrieve_next_sync_event_t retrieve_next_sync_event
krista@2271
   112
    );
krista@2271
   113
krista@2271
   114
DYNAMIC_API void unregister_sync_callbacks(PEP_SESSION session);
krista@2271
   115
vb@2839
   116
krista@2271
   117
// do_sync_protocol() - function to be run on an extra thread
krista@2271
   118
//
krista@2271
   119
//  parameters:
krista@2271
   120
//      session                 pEp session to use
krista@2271
   121
//      retrieve_next_sync_msg  pointer to retrieve_next_identity() callback
krista@2271
   122
//                              which returns at least a valid address field in
krista@2271
   123
//                              the identity struct
krista@2271
   124
//      obj                     application defined sync object
krista@2271
   125
//
krista@2271
   126
//  return value:
krista@2271
   127
//      PEP_STATUS_OK if thread has to terminate successfully or any other
krista@2271
   128
//      value on failure
krista@2271
   129
krista@2271
   130
DYNAMIC_API PEP_STATUS do_sync_protocol(
krista@2271
   131
        PEP_SESSION session,
krista@2271
   132
        void *obj
krista@2271
   133
    );
krista@2271
   134
krista@2271
   135
vb@2899
   136
// do_sync_protocol_step() - function for single threaded implementations
vb@2899
   137
//
vb@2899
   138
//  parameters:
vb@2899
   139
//      session                 pEp session to use
vb@2899
   140
//      retrieve_next_sync_msg  pointer to retrieve_next_identity() callback
vb@2899
   141
//                              which returns at least a valid address field in
vb@2899
   142
//                              the identity struct
vb@2899
   143
//      obj                     application defined sync object
vb@2899
   144
//      event                   Sync event to process
vb@2899
   145
vb@2899
   146
DYNAMIC_API PEP_STATUS do_sync_protocol_step(
vb@2899
   147
        PEP_SESSION session,
vb@2899
   148
        void *obj,
vb@2899
   149
        SYNC_EVENT event
vb@2899
   150
    );
vb@2899
   151
vb@2899
   152
vb@2899
   153
// is_sync_thread() - determine if this is sync thread's session
vb@2899
   154
//
vb@2899
   155
//  paramters:
vb@2899
   156
//      session                 pEp session to test
vb@2899
   157
//
vb@2899
   158
//  return value:
vb@2899
   159
//      true if this is sync thread's session, false otherwise
vb@2899
   160
vb@2899
   161
DYNAMIC_API bool is_sync_thread(PEP_SESSION session);
vb@2899
   162
vb@2899
   163
vb@2911
   164
// new_sync_timeout_event() - create a Sync timeout event
vb@2911
   165
//
vb@2911
   166
//  return value:
vb@2911
   167
//      returns a new Sync timeout event, or NULL on failure
vb@2911
   168
vb@2911
   169
DYNAMIC_API SYNC_EVENT new_sync_timeout_event();
vb@2911
   170
vb@2911
   171
krista@2271
   172
#ifdef __cplusplus
krista@2271
   173
}
krista@2271
   174
#endif
krista@2271
   175