adapt to NULL callbacks

ENGINE-974
positron 1 year ago
parent a04183a5f4
commit e598c2bc85

@ -260,6 +260,16 @@ PEP_STATUS try_base_prepare_message(
message **result
)
{
/* Special case: if messageToSend is not defined there is no way to handle
passphrases: in that case just exit with PEP_SYNC_NO_CHANNEL. This is
required for pEp4Thunderbird (P4TB-413) with the most recent
libpEpAdapter (master) and JSONServerAdapter (master) as of 2021-11-05:
JSONServerAdapter performs a temporary incomplete initialisation by
supplying some NULL callbacks, and initialises in a complete way only
later. */
if (session->messageToSend == NULL)
return PEP_SYNC_NO_CHANNEL;
PEP_STATUS status = PEP_STATUS_OK;
assert(session && session->messageToSend && session->notifyHandshake);

@ -12,6 +12,28 @@
#include "KeySync_fsm.h"
/* A dummy function performing no useful work, usable as a notifyHandshake
function. Notice that this destroys its heap-allocated arguments, since the
callback function is supposed to take ownership of them. */
static PEP_STATUS notifyHandshake_dummy(
pEp_identity *me,
pEp_identity *partner,
sync_handshake_signal signal
)
{
free_identity(me);
free_identity(partner);
}
/* Like notifyHandshake_dummy , but for retrieve_next_sync_event_t . */
static SYNC_EVENT retrieve_next_sync_event_dummy(void *management,
unsigned threshold)
{
/* Do nothing. */
}
DYNAMIC_API PEP_STATUS register_sync_callbacks(
PEP_SESSION session,
void *management,
@ -19,6 +41,14 @@ DYNAMIC_API PEP_STATUS register_sync_callbacks(
retrieve_next_sync_event_t retrieve_next_sync_event
)
{
/* In case the callbacks are null pointers, replace them with dummy
functions. This makes the code more robust elsewhere and handles object
ownership in a reasonable way. */
if (notifyHandshake == NULL)
notifyHandshake = notifyHandshake_dummy;
if (retrieve_next_sync_event == NULL)
retrieve_next_sync_event = retrieve_next_sync_event_dummy;
assert(session && notifyHandshake && retrieve_next_sync_event);
if (!(session && notifyHandshake && retrieve_next_sync_event))
return PEP_ILLEGAL_VALUE;
@ -46,8 +76,8 @@ DYNAMIC_API void unregister_sync_callbacks(PEP_SESSION session) {
// unregister
session->sync_management = NULL;
session->notifyHandshake = NULL;
session->retrieve_next_sync_event = NULL;
session->notifyHandshake = notifyHandshake_dummy;
session->retrieve_next_sync_event = retrieve_next_sync_event_dummy;
}
DYNAMIC_API PEP_STATUS deliverHandshakeResult(

Loading…
Cancel
Save