|
@ -25,8 +25,9 @@ namespace pEp { |
|
|
) |
|
|
) |
|
|
{ |
|
|
{ |
|
|
assert(messageToSend); |
|
|
assert(messageToSend); |
|
|
if (!messageToSend) |
|
|
if (!messageToSend) { |
|
|
throw std::invalid_argument("messageToSend must be set"); |
|
|
throw std::invalid_argument("messageToSend must be set"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
targets.push_back({messageToSend, notifyHandshake, on_startup, shutdown}); |
|
|
targets.push_back({messageToSend, notifyHandshake, on_startup, shutdown}); |
|
|
} |
|
|
} |
|
@ -34,8 +35,9 @@ namespace pEp { |
|
|
void CallbackDispatcher::remove(::messageToSend_t messageToSend) |
|
|
void CallbackDispatcher::remove(::messageToSend_t messageToSend) |
|
|
{ |
|
|
{ |
|
|
assert(messageToSend); |
|
|
assert(messageToSend); |
|
|
if (!messageToSend) |
|
|
if (!messageToSend) { |
|
|
throw std::invalid_argument("messageToSend argument needed"); |
|
|
throw std::invalid_argument("messageToSend argument needed"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
for (auto target = targets.begin(); target != targets.end(); ++target) { |
|
|
for (auto target = targets.begin(); target != targets.end(); ++target) { |
|
|
if (target->messageToSend == messageToSend) { |
|
|
if (target->messageToSend == messageToSend) { |
|
@ -43,23 +45,27 @@ namespace pEp { |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if (targets.empty()) |
|
|
|
|
|
|
|
|
if (targets.empty()) { |
|
|
stop_sync(); |
|
|
stop_sync(); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void CallbackDispatcher::on_startup() |
|
|
void CallbackDispatcher::on_startup() |
|
|
{ |
|
|
{ |
|
|
for (auto target : targets) { |
|
|
for (auto target : targets) { |
|
|
if (target.on_startup) |
|
|
if (target.on_startup) { |
|
|
target.on_startup(); |
|
|
target.on_startup(); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void CallbackDispatcher::on_shutdown() |
|
|
void CallbackDispatcher::on_shutdown() |
|
|
{ |
|
|
{ |
|
|
for (auto target : targets) { |
|
|
for (auto target : targets) { |
|
|
if (target.on_shutdown) |
|
|
if (target.on_shutdown) { |
|
|
target.on_shutdown(); |
|
|
target.on_shutdown(); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -73,8 +79,9 @@ namespace pEp { |
|
|
&CallbackDispatcher::on_shutdown); |
|
|
&CallbackDispatcher::on_shutdown); |
|
|
|
|
|
|
|
|
for (auto target : callback_dispatcher.targets) { |
|
|
for (auto target : callback_dispatcher.targets) { |
|
|
if (target.notifyHandshake) |
|
|
if (target.notifyHandshake) { |
|
|
target.notifyHandshake(nullptr, nullptr, SYNC_NOTIFY_START); |
|
|
target.notifyHandshake(nullptr, nullptr, SYNC_NOTIFY_START); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -85,8 +92,9 @@ namespace pEp { |
|
|
callback_dispatcher.semaphore.go(); |
|
|
callback_dispatcher.semaphore.go(); |
|
|
|
|
|
|
|
|
for (auto target : callback_dispatcher.targets) { |
|
|
for (auto target : callback_dispatcher.targets) { |
|
|
if (target.notifyHandshake) |
|
|
if (target.notifyHandshake) { |
|
|
target.notifyHandshake(nullptr, nullptr, SYNC_NOTIFY_STOP); |
|
|
target.notifyHandshake(nullptr, nullptr, SYNC_NOTIFY_STOP); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -95,14 +103,16 @@ namespace pEp { |
|
|
if (Adapter::on_sync_thread() && !msg) { |
|
|
if (Adapter::on_sync_thread() && !msg) { |
|
|
semaphore.try_wait(); |
|
|
semaphore.try_wait(); |
|
|
|
|
|
|
|
|
if (Adapter::in_shutdown()) |
|
|
if (Adapter::in_shutdown()) { |
|
|
return PEP_SYNC_NO_CHANNEL; |
|
|
return PEP_SYNC_NO_CHANNEL; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
PEP_STATUS status = PassphraseCache::config_next_passphrase(); |
|
|
PEP_STATUS status = PassphraseCache::config_next_passphrase(); |
|
|
|
|
|
|
|
|
// if the cache has no valid passphrase ask the app
|
|
|
// if the cache has no valid passphrase ask the app
|
|
|
if (status == PEP_PASSPHRASE_REQUIRED || status == PEP_WRONG_PASSPHRASE) |
|
|
if (status == PEP_PASSPHRASE_REQUIRED || status == PEP_WRONG_PASSPHRASE) { |
|
|
semaphore.stop(); |
|
|
semaphore.stop(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// the pEp engine must try again
|
|
|
// the pEp engine must try again
|
|
|
return status; |
|
|
return status; |
|
@ -117,8 +127,9 @@ namespace pEp { |
|
|
::message *_msg = nullptr; |
|
|
::message *_msg = nullptr; |
|
|
if (msg) { |
|
|
if (msg) { |
|
|
_msg = ::message_dup(msg); |
|
|
_msg = ::message_dup(msg); |
|
|
if (!_msg) |
|
|
if (!_msg) { |
|
|
return PEP_OUT_OF_MEMORY; |
|
|
return PEP_OUT_OF_MEMORY; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
assert(target.messageToSend); |
|
|
assert(target.messageToSend); |
|
|
target.messageToSend(_msg); |
|
|
target.messageToSend(_msg); |
|
@ -135,8 +146,9 @@ namespace pEp { |
|
|
::pEp_identity *_me = nullptr; |
|
|
::pEp_identity *_me = nullptr; |
|
|
if (me) { |
|
|
if (me) { |
|
|
_me = ::identity_dup(me); |
|
|
_me = ::identity_dup(me); |
|
|
if (!_me) |
|
|
if (!_me) { |
|
|
return PEP_OUT_OF_MEMORY; |
|
|
return PEP_OUT_OF_MEMORY; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
::pEp_identity *_partner = nullptr; |
|
|
::pEp_identity *_partner = nullptr; |
|
|
if (partner) { |
|
|
if (partner) { |
|
|