Merge branch 'Release_2.1' - we (fdik and i) deifned the version numbers of libpEpAdapter to be totally independent of anything else.

Branch "Release_2.1" will be patch only release branch for Release_2.1
Branch "master" can now be main branch and the next libpEpAdapter release will be Release_3.0.0
We are deliberately doing a major release bump, to make it clear that the version numbers are decoupled from now on.
pull/8/head Release_3.0-RC0
heck 2 years ago
commit b8004d624e

39
.gitignore vendored

@ -0,0 +1,39 @@
*.o
*.a
*.d
*.swp
ws
test_adapter
.gnupg
.pEp*
lib
local.conf
build/
# Default ignored files
?idea/
# Windows
build-windows/Debug/
build-windows/Release/
build-windows/libpEpAdapter.vcxproj.user
/test/test_adapter.dSYM/Contents/Info.plist
/test/test_adapter_cxx.dSYM/Contents/Info.plist
/test/test_ensure_passphrase.dSYM/Contents/Info.plist
/test/test_leave_device_group.dSYM/Contents/Info.plist
/test/test_library.dSYM/Contents/Info.plist
/test/test_message_cache.dSYM/Contents/Info.plist
/test/test_passphrase_cache.dSYM/Contents/Info.plist
/test/test_semaphore.dSYM/Contents/Info.plist
/test/test_adapter_cxx.dSYM/Contents/Resources/DWARF/test_adapter_cxx
/test/test_adapter_cxx
/test/test_ensure_passphrase.dSYM/Contents/Resources/DWARF/test_ensure_passphrase
/test/test_ensure_passphrase
/test/test_leave_device_group.dSYM/Contents/Resources/DWARF/test_leave_device_group
/test/test_leave_device_group
/test/test_library.dSYM/Contents/Resources/DWARF/test_library
/test/test_library
/test/test_message_cache.dSYM/Contents/Resources/DWARF/test_message_cache
/test/test_message_cache
/test/test_passphrase_cache.dSYM/Contents/Resources/DWARF/test_passphrase_cache
/test/test_passphrase_cache
/test/test_semaphore.dSYM/Contents/Resources/DWARF/test_semaphore
/test/test_semaphore

@ -0,0 +1,22 @@
.ensure_docker: &ensure_docker
# Check for docker and install if missing
- 'which docker || ( sudo apt-get update -y && sudo apt-get install docker.io -y )'
.ensure_rsync: &ensure_rsync
# Install rsync and deps if missing
- 'which ssh-agent || ( sudo apt-get update -y && sudo apt-get install openssh-client -y )'
- 'which rsync || ( sudo apt-get update -y && sudo apt-get install rsync -y )'
- 'which make || ( sudo apt-get update -y && sudo apt-get install make -y )'
.standard_job:
tags: [kvm]
before_script:
- *ensure_docker
- *ensure_rsync
.make_in_docker:
extends: .standard_job
script:
- docker login -u ${DOCKER_REGISTRY_USER} -p ${DOCKER_REGISTRY_PASS} ${DOCKER_REGISTRY_HOST}
- cd scripts/${CI_DISTRO_TARGET}
- make

@ -0,0 +1,27 @@
include:
- '.gitlab-ci-files/common-prepare.yml'
stages:
- build
# Debian
debian10:build:
extends: .make_in_docker
stage: build
variables:
CI_DISTRO_TARGET: "debian10"
DEBIAN_FRONTEND: "noninteractive"
rules:
- if: '$CI_COMMIT_TAG !~ /^Release_[0-9]+\.[0-9]+\.[0-9]+$/'
debian10:tagged-build:
extends: .make_in_docker
stage: build
variables:
CI_DISTRO_TARGET: "debian10"
DEBIAN_FRONTEND: "noninteractive"
TAGGED_BUILD: "true"
rules:
- if: '$CI_COMMIT_TAG =~ /^Release_[0-9]+\.[0-9]+\.[0-9]+$/'

@ -1,14 +0,0 @@
syntax: glob
*.o
*.a
*.d
*.swp
ws
test_adapter
.gnupg
.pEp*
lib
local.conf
build/
# Default ignored files
.idea/workspace.xml

@ -42,7 +42,7 @@ namespace pEp {
notifyHandshake_t _notifyHandshake = nullptr;
std::thread _sync_thread;
::utility::locked_queue< SYNC_EVENT, ::free_Sync_event > q;
::utility::locked_queue< SYNC_EVENT, ::free_Sync_event > sync_evt_q;
std::mutex m;
std::thread::id sync_thread_id()
@ -54,11 +54,11 @@ namespace pEp {
{
try {
if (ev == nullptr) {
q.clear();
q.push_back(ev);
sync_evt_q.clear();
sync_evt_q.push_back(ev);
}
else {
q.push_front(ev);
sync_evt_q.push_front(ev);
}
}
catch (exception&) {
@ -76,10 +76,11 @@ namespace pEp {
SYNC_EVENT _retrieve_next_sync_event(void *management, unsigned threshold)
{
SYNC_EVENT syncEvent = nullptr;
const bool success = q.try_pop_front(syncEvent, std::chrono::seconds(threshold));
const bool success = sync_evt_q.try_pop_front(syncEvent, std::chrono::seconds(threshold));
if (!success)
if (!success) {
return new_sync_timeout_event();
}
return syncEvent;
}
@ -92,14 +93,14 @@ namespace pEp {
PEP_SESSION Session::operator()(session_action action)
{
std::lock_guard<mutex> lock(m);
bool in_sync = on_sync_thread();
PEP_STATUS status = PEP_STATUS_OK;
switch (action) {
case release:
if (_session.get())
if (_session.get()) {
_session = nullptr;
}
break;
case init:
@ -138,15 +139,16 @@ namespace pEp {
{
SYNC_EVENT ev;
try {
ev = q.back();
ev = sync_evt_q.back();
}
catch (std::underflow_error&) {
return false;
}
if (ev)
if (ev) {
return false;
else
} else {
return true;
}
}
}
}

@ -1,7 +1,8 @@
// This file is under GNU General Public License 3.0
// see LICENSE.txt
#pragma once
#ifndef LIBPEPADAPTER_ADAPTER_HH
#define LIBPEPADAPTER_ADAPTER_HH
#include <functional>
#include <string>
@ -68,3 +69,5 @@ namespace pEp {
}
#include "Adapter.hxx"
#endif //LIBPEPADAPTER_ADAPTER_HH

@ -1,12 +1,14 @@
// This file is under GNU General Public License 3.0
// see LICENSE.txt
#pragma once
#ifndef LIBPEPADAPTER_ADAPTER_HXX
#define LIBPEPADAPTER_ADAPTER_HXX
#include <thread>
#include "locked_queue.hh"
#include <cassert>
#include "pEpLog.hh"
#include <atomic>
namespace pEp {
namespace Adapter {
@ -16,35 +18,41 @@ namespace pEp {
extern notifyHandshake_t _notifyHandshake;
extern std::thread _sync_thread;
extern ::utility::locked_queue< SYNC_EVENT, ::free_Sync_event > q;
extern ::utility::locked_queue< SYNC_EVENT, ::free_Sync_event > sync_evt_q;
extern std::mutex m;
SYNC_EVENT _retrieve_next_sync_event(void *management, unsigned threshold);
static std::exception_ptr _ex;
static bool register_done = false;
static std::atomic_bool register_done{false};
template< class T >
void sync_thread(T *obj, function< void(T *) > _startup, function< void(T *) > _shutdown)
{
pEpLog("called");
_ex = nullptr;
assert(_messageToSend);
assert(_notifyHandshake);
if (obj && _startup)
if (obj && _startup) {
_startup(obj);
}
pEpLog("creating session");
session();
{
//TODO: Do we need to use a passphraseWrap here???
pEpLog("register_sync_callbacks()");
PEP_STATUS status = register_sync_callbacks(session(), nullptr,
_notifyHandshake, _retrieve_next_sync_event);
pEpLog("register_sync_callbacks() return:" << status);
try {
throw_status(status);
register_done = true;
register_done.store(true);
}
catch (...) {
_ex = std::current_exception();
register_done = true;
register_done.store(true);
return;
}
}
@ -56,8 +64,9 @@ namespace pEp {
session(release);
if (obj && _shutdown)
if (obj && _shutdown) {
_shutdown(obj);
}
}
template< class T >
@ -68,23 +77,34 @@ namespace pEp {
function< void(T *) > _startup,
function< void(T *) > _shutdown)
{
if (messageToSend)
pEpLog("called");
if (messageToSend) {
_messageToSend = messageToSend;
}
if (notifyHandshake)
if (notifyHandshake) {
_notifyHandshake = notifyHandshake;
}
pEpLog("creating session");
session();
if (!_sync_thread.joinable()) {
register_done = false;
register_done.store(false);
pEpLog("creating sync-thread");
_sync_thread = std::thread(sync_thread<T>, obj, _startup, _shutdown);
while (!register_done)
while (register_done.load() == false) {
pEpLog("waiting for sync-thread to init...");
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
if (_ex)
if (_ex) {
pEpLog("exception pending, rethrowing");
std::rethrow_exception(_ex);
}
}
}
}
}
#endif //LIBPEPADAPTER_ADAPTER_HXX

@ -0,0 +1,5 @@
# 1st Party Dependencies
## Prefer git tags instead of SHA hashes when possible.
pEpEngine=Release_2.1.18
sequoia=365d00a08bec6a5a48d48a7c7893d78c27092b59

@ -13,15 +13,10 @@ SOURCE=$(wildcard *.cc)
HEADERS=$(wildcard *.hh *.hxx)
OBJECTS=$(subst .cc,.o,$(SOURCE))
DEPENDS=$(subst .cc,.d,$(SOURCE))
CXXFLAGS+= -MMD -MP
all: $(TARGET)
%.d: %.cc
@set -e; rm -f $@; \
$(CXX) -MM $(CPPFLAGS) $(CXXFLAGS) $< > $@.$$$$; \
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$
ifneq ($(MAKECMDGOALS),clean)
-include $(DEPENDS)
endif

@ -1,11 +1,22 @@
// This file is under GNU General Public License 3.0
// see LICENSE.txt
#ifndef LIBPEPADAPTER_SEMAPHORE_HH
#define LIBPEPADAPTER_SEMAPHORE_HH
#include <mutex>
#include <condition_variable>
#include <atomic>
namespace pEp {
class Semaphore {
std::mutex mtx;
std::condition_variable cv;
bool _stop;
// Atomic types are types that encapsulate a value whose access is guaranteed
// to not cause data races and can be used to synchronize memory accesses among
// different threads.
// To synchronize threads, ALWAYS use <atomic> types
std::atomic_bool _stop;
public:
Semaphore() : _stop(false) { }
@ -13,25 +24,30 @@ namespace pEp {
void stop()
{
std::unique_lock<std::mutex> lock(mtx);
_stop = true;
_stop.store(true);
}
void try_wait()
{
std::unique_lock<std::mutex> lock(mtx);
if (!_stop)
if (!_stop.load()) {
return;
}
while(_stop)
while(_stop.load()) {
cv.wait(lock);
}
}
void go()
{
std::unique_lock<std::mutex> lock(mtx);
_stop = false;
_stop.store(false);
cv.notify_all();
}
};
}
#endif // LIBPEPADAPTER_SEMAPHORE_HH

@ -25,12 +25,7 @@ LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../../pEpEngine/build-android/include \
LOCAL_EXPORT_C_INCLUDES += $(LOCAL_PATH)../include
LOCAL_SRC_FILES += $(LOCAL_PATH)/../../Adapter.cc \
$(LOCAL_PATH)/../../slurp.cc \
$(LOCAL_PATH)/../../call_with_lock.cc \
$(LOCAL_PATH)/../../passphrase_cache.cc \
$(LOCAL_PATH)/../../callback_dispatcher.cc \
$(LOCAL_PATH)/../../status_to_string.cc
LOCAL_SRC_FILES += $(wildcard $(LOCAL_PATH)/../../*.cc)
include $(BUILD_STATIC_LIBRARY)

@ -64,11 +64,6 @@
<Link>
<SubSystem>Windows</SubSystem>
</Link>
<PostBuildEvent>
<Command>XCOPY "$(SolutionDir)libpEpAdapter\*.hh" "$(SolutionDir)pEp\" /I/F/Y
XCOPY "$(SolutionDir)libpEpAdapter\*.hxx" "$(SolutionDir)pEp\" /I/F/Y
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
@ -86,11 +81,6 @@ XCOPY "$(SolutionDir)libpEpAdapter\*.hxx" "$(SolutionDir)pEp\" /I/F/Y
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
<PostBuildEvent>
<Command>XCOPY "$(SolutionDir)libpEpAdapter\*.hh" "$(SolutionDir)pEp\" /I/F/Y
XCOPY "$(SolutionDir)libpEpAdapter\*.hxx" "$(SolutionDir)pEp\" /I/F/Y
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<Text Include="ReadMe.txt" />
@ -102,6 +92,7 @@ XCOPY "$(SolutionDir)libpEpAdapter\*.hxx" "$(SolutionDir)pEp\" /I/F/Y
<ClCompile Include="..\constant_time_algo.cc" />
<ClCompile Include="..\message_cache.cc" />
<ClCompile Include="..\passphrase_cache.cc" />
<ClCompile Include="..\pEpLog.cc" />
<ClCompile Include="..\slurp.cc" />
<ClCompile Include="..\status_to_string.cc" />
</ItemGroup>
@ -115,10 +106,16 @@ XCOPY "$(SolutionDir)libpEpAdapter\*.hxx" "$(SolutionDir)pEp\" /I/F/Y
<ClInclude Include="..\passphrase_cache.hh" />
<ClInclude Include="..\passphrase_cache.hxx" />
<ClInclude Include="..\pc_container.hh" />
<ClInclude Include="..\pEpLog.hh" />
<ClInclude Include="..\Semaphore.hh" />
<ClInclude Include="..\slurp.hh" />
<ClInclude Include="..\status_to_string.hh" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\pEpEngine\build-windows\pEpEngine.vcxproj">
<Project>{146e69f8-e1da-456a-b048-6dd29d9acf6b}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>

@ -42,6 +42,9 @@
<ClCompile Include="..\constant_time_algo.cc">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\pEpLog.cc">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\Adapter.hh">
@ -80,5 +83,8 @@
<ClInclude Include="..\constant_time_algo.hh">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\pEpLog.hh">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

@ -1,4 +1,5 @@
// this file is under GNU GPL 3.0, see LICENSE.txt
// This file is under GNU General Public License 3.0
// see LICENSE.txt
#include "call_with_lock.hh"

@ -1,7 +1,8 @@
// this file is under GNU GPL 3.0, see LICENSE.txt
// This file is under GNU General Public License 3.0
// see LICENSE.txt
#ifndef PEP_CALL_WITH_LOCK_HH
#define PEP_CALL_WITH_LOCK_HH
#ifndef LIBPEPADAPTER_CALL_WITH_LOCK_HH
#define LIBPEPADAPTER_CALL_WITH_LOCK_HH
#include <mutex>
@ -22,4 +23,4 @@ namespace pEp
}
#endif // PEP_CALL_WITH_LOCK_HH
#endif // LIBPEPADAPTER_CALL_WITH_LOCK_HH

@ -1,3 +1,6 @@
// This file is under GNU General Public License 3.0
// see LICENSE.txt
#include "callback_dispatcher.hh"
#include "passphrase_cache.hh"
#include <stdexcept>
@ -25,8 +28,9 @@ namespace pEp {
)
{
assert(messageToSend);
if (!messageToSend)
if (!messageToSend) {
throw std::invalid_argument("messageToSend must be set");
}
targets.push_back({messageToSend, notifyHandshake, on_startup, shutdown});
}
@ -34,8 +38,9 @@ namespace pEp {
void CallbackDispatcher::remove(::messageToSend_t messageToSend)
{
assert(messageToSend);
if (!messageToSend)
if (!messageToSend) {
throw std::invalid_argument("messageToSend argument needed");
}
for (auto target = targets.begin(); target != targets.end(); ++target) {
if (target->messageToSend == messageToSend) {
@ -43,28 +48,33 @@ namespace pEp {
break;
}
}
if (targets.empty())
if (targets.empty()) {
stop_sync();
}
}
void CallbackDispatcher::on_startup()
{
for (auto target : targets) {
if (target.on_startup)
if (target.on_startup) {
target.on_startup();
}
}
}
void CallbackDispatcher::on_shutdown()
{
for (auto target : targets) {
if (target.on_shutdown)
if (target.on_shutdown) {
target.on_shutdown();
}
}
}
void CallbackDispatcher::start_sync()
{
pEpLog("called");
callback_dispatcher.semaphore.go();
pEp::Adapter::startup<CallbackDispatcher>(CallbackDispatcher::messageToSend,
@ -72,9 +82,11 @@ namespace pEp {
&CallbackDispatcher::on_startup,
&CallbackDispatcher::on_shutdown);
pEpLog("all targets signal: SYNC_NOTIFY_START");
for (auto target : callback_dispatcher.targets) {
if (target.notifyHandshake)
if (target.notifyHandshake) {
target.notifyHandshake(nullptr, nullptr, SYNC_NOTIFY_START);
}
}
}
@ -85,8 +97,9 @@ namespace pEp {
callback_dispatcher.semaphore.go();
for (auto target : callback_dispatcher.targets) {
if (target.notifyHandshake)
if (target.notifyHandshake) {
target.notifyHandshake(nullptr, nullptr, SYNC_NOTIFY_STOP);
}
}
}
@ -95,14 +108,16 @@ namespace pEp {
if (Adapter::on_sync_thread() && !msg) {
semaphore.try_wait();
if (Adapter::in_shutdown())
if (Adapter::in_shutdown()) {
return PEP_SYNC_NO_CHANNEL;
}
PEP_STATUS status = PassphraseCache::config_next_passphrase();
// 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();
}
// the pEp engine must try again
return status;
@ -117,8 +132,9 @@ namespace pEp {
::message *_msg = nullptr;
if (msg) {
_msg = ::message_dup(msg);
if (!_msg)
if (!_msg) {
return PEP_OUT_OF_MEMORY;
}
}
assert(target.messageToSend);
target.messageToSend(_msg);
@ -135,8 +151,9 @@ namespace pEp {
::pEp_identity *_me = nullptr;
if (me) {
_me = ::identity_dup(me);
if (!_me)
if (!_me) {
return PEP_OUT_OF_MEMORY;
}
}
::pEp_identity *_partner = nullptr;
if (partner) {

@ -1,4 +1,8 @@
#pragma once
// This file is under GNU General Public License 3.0
// see LICENSE.txt
#ifndef LIBPEPADAPTER_CALLBACK_DISPATCHER_HH
#define LIBPEPADAPTER_CALLBACK_DISPATCHER_HH
#include <vector>
#include <functional>
@ -27,30 +31,37 @@ namespace pEp {
public:
void add(
::messageToSend_t messageToSend,
::notifyHandshake_t notifyHandshake,
proc on_startup = nullptr,
proc on_shutdown = nullptr
);
::messageToSend_t messageToSend,
::notifyHandshake_t notifyHandshake,
proc on_startup = nullptr,
proc on_shutdown = nullptr
);
void remove(::messageToSend_t messageToSend);
static void start_sync();
static void stop_sync();
static PEP_STATUS messageToSend(::message *msg);
static PEP_STATUS notifyHandshake(::pEp_identity *me,
::pEp_identity *partner, ::sync_handshake_signal signal);
static PEP_STATUS notifyHandshake(
::pEp_identity *me,
::pEp_identity *partner,
::sync_handshake_signal signal
);
protected:
void on_startup();
void on_shutdown();
PEP_STATUS _messageToSend(::message *msg);
PEP_STATUS _notifyHandshake(::pEp_identity *me,
::pEp_identity *partner, ::sync_handshake_signal signal);
PEP_STATUS _notifyHandshake(
::pEp_identity *me,
::pEp_identity *partner,
::sync_handshake_signal signal
);
friend const char *PassphraseCache::add(const std::string& passphrase);
};
extern CallbackDispatcher callback_dispatcher;
};
}
#endif // LIBPEPADAPTER_CALLBACK_DISPATCHER_HH

@ -1,3 +1,6 @@
// This file is under GNU General Public License 3.0
// see LICENSE.txt
#include "constant_time_algo.hh"
namespace pEp

@ -1,4 +1,8 @@
#pragma once
// This file is under GNU General Public License 3.0
// see LICENSE.txt
#ifndef LIBPEPADAPTER_CONSTANT_TIME_ALGO_HH
#define LIBPEPADAPTER_CONSTANT_TIME_ALGO_HH
#include <string>
@ -12,3 +16,5 @@ namespace pEp
bool constant_time_equal(const std::string& a, const std::string& b);
} // end of namespace pEp
#endif // LIBPEPADAPTER_CONSTANT_TIME_ALGO_HH

@ -1,7 +1,8 @@
// This file is under GNU General Public License 3.0
// see LICENSE.txt
#pragma once
#ifndef LIBPEPADAPTER_LOCKED_QUEUE_HH
#define LIBPEPADAPTER_LOCKED_QUEUE_HH
#include <deque>
#include <condition_variable>
@ -182,3 +183,5 @@ namespace utility
};
} // end of namespace utility
#endif // LIBPEPADAPTER_LOCKED_QUEUE_HH

@ -1,3 +1,6 @@
// This file is under GNU General Public License 3.0
// see LICENSE.txt
#include "message_cache.hh"
#include <cassert>
#include <cstring>

@ -1,4 +1,8 @@
#pragma once
// This file is under GNU General Public License 3.0
// see LICENSE.txt
#ifndef LIBPEPADAPTER_MESSAGE_CACHE_HH
#define LIBPEPADAPTER_MESSAGE_CACHE_HH
#include <string>
#include <unordered_map>
@ -128,3 +132,4 @@ namespace pEp {
extern MessageCache message_cache;
};
#endif // LIBPEPADAPTER_MESSAGE_CACHE_HH

@ -0,0 +1,40 @@
// This file is under GNU General Public License 3.0
// see LICENSE.txt
#include "pEpLog.hh"
#include <iostream>
#include <sstream>
#include <mutex>
#include <atomic>
namespace pEp {
namespace Adapter {
namespace pEpLog {
std::mutex mtx;
std::atomic_bool is_enabled{false};
void set_enabled(bool enabled) {
is_enabled.store(enabled);
}
bool get_enabled() {
return is_enabled.load();
}
void log(std::string msg) {
if (is_enabled.load()) {
std::lock_guard<std::mutex> l(mtx);
#ifdef ANDROID
__android_log_print(ANDROID_LOG_DEBUG, "pEpDebugLog", "%s", msg.c_str());
#else
std::cout << msg << std::endl; //std::endl also flushes
#endif
}
}
} // pEpLog
} // Adapter
} // pEp

@ -1,7 +1,62 @@
// TODO: put into not yet existing libpEpAdapter_utils.h, to be across whole libpEpAdapter
// This file is under GNU General Public License 3.0
// see LICENSE.txt
#ifndef LIBPEPADAPTER_PEPLOG_HH
#define LIBPEPADAPTER_PEPLOG_HH
#include <sstream>
#include <thread>
// pEpLog
// ======
// a "to be kept ultra small and simple" logging unit.
// featuring:
// * pEpLog macro that will be eliminated in release-builds (-DNDEBUG=1)
// * thread safe (no interleave when logging from diff threads)
// * OS dependent backend switches:
// * android: __android_log_print
// * all other OS: cout
// * runtime enabled/disabled switch (global)
//
// You might want more and more features, but the feature-policy is very restrictive, and there is a
// primary design goal to keep it simple, maintainable and portable.
//
// How to use:
// include <pEpLog.hh>
// use the macro pEpLog(msg) to do logging
// use NDEBUG=1 to turn logging on/off at compile-time
// use set_enabled(bool) to turn logging on/off at runtime
// use set_enabled_<backend>(bool) to turn logging on/off per backend
#ifdef NDEBUG
#define pEpLog(msg) do{}while(0)
#else
#include <iostream>
#define pEpLog(msg) do{std::cerr << __FILE__ << "::" << __FUNCTION__ << " - " << msg << '\n';} while(0)
#endif
#ifdef ANDROID
#include <android/log.h>
#endif
#define pEpLog(msg) \
do { \
std::stringstream msg_ss; \
msg_ss << std::this_thread::get_id() << " - " << __FILE__ << "::" << __FUNCTION__ << " - " << msg; \
pEp::Adapter::pEpLog::log(msg_ss.str()); \
} while(0)
#endif // NDEBUG
namespace pEp {
namespace Adapter {
namespace pEpLog {
void log(std::string msg);
void set_enabled(bool is_enabled);
bool get_enabled();
} // pEpLog
} // Adapter
} // pEp
#endif // LIBPEPADAPTER_PEPLOG_HH

@ -1,3 +1,6 @@
// This file is under GNU General Public License 3.0
// see LICENSE.txt
#include <cassert>
#include "Adapter.hh"
#include "passphrase_cache.hh"

@ -1,4 +1,8 @@
#pragma once
// This file is under GNU General Public License 3.0
// see LICENSE.txt
#ifndef LIBPEPADAPTER_PASSPHRASE_CACHE_HH
#define LIBPEPADAPTER_PASSPHRASE_CACHE_HH
#include <list>
#include <string>
@ -85,3 +89,4 @@ namespace pEp {
#include "passphrase_cache.hxx"
#endif // LIBPEPADAPTER_PASSPHRASE_CACHE_HH

@ -1,3 +1,9 @@
// This file is under GNU General Public License 3.0
// see LICENSE.txt
#ifndef LIBPEPADAPTER_PASSPHRASE_CACHE_HXX
#define LIBPEPADAPTER_PASSPHRASE_CACHE_HXX
#include "passphrase_cache.hh"
namespace pEp {
@ -20,3 +26,4 @@ namespace pEp {
}
};
#endif // LIBPEPADAPTER_PASSPHRASE_CACHE_HXX

@ -1,9 +1,10 @@
// This file is under GNU General Public License 3.0
// see LICENSE.txt
#pragma once
#ifndef LIBPEPADAPTER_PC_CONTAINER_HH
#define LIBPEPADAPTER_PC_CONTAINER_HH
// Conainer adapter that contains a container and a producer/consume queue
// Container adapter that contains a container and a producer/consume queue
// that holds references to all changed elements
#include <functional>
@ -82,4 +83,5 @@ private:
};
} // end of namespace pEp
#endif // LIBPEPADAPTER_PC_CONTAINER_HH

@ -0,0 +1,15 @@
CURRENT_DISTRO=$(shell basename $(shell pwd))
LIBPEPADAPTER_VERSION=$(shell git rev-parse --short=8 HEAD)
IMAGE_NAME=${DOCKER_REGISTRY_HOST}/pep-$(CURRENT_DISTRO)-libpepadapter
DOCKERFILE=libpEpAdapter.$(CURRENT_DISTRO).Dockerfile
all:
-docker pull $(IMAGE_NAME):latest
cd ../../ && docker build --build-arg CURRENT_DISTRO=$(CURRENT_DISTRO) \
--build-arg DOCKER_REGISTRY_HOST=${DOCKER_REGISTRY_HOST} \
--build-arg LIBPEPADAPTER_VERSION=$(LIBPEPADAPTER_VERSION) \
--cache-from $(IMAGE_NAME):latest \
--tag=$(IMAGE_NAME):$(LIBPEPADAPTER_VERSION) \
--tag=$(IMAGE_NAME):latest \
-f scripts/${CURRENT_DISTRO}/$(DOCKERFILE) .
docker push $(IMAGE_NAME):${LIBPEPADAPTER_VERSION}
docker push $(IMAGE_NAME):latest

@ -0,0 +1,8 @@
#!/usr/bin/env sh
set -exo
echo "ENGINE_LIB_PATH=${INSTPREFIX}/lib" >> local.conf
echo "ENGINE_INC_PATH=${INSTPREFIX}/include" >> local.conf
make
make install PREFIX="${INSTPREFIX}"

@ -0,0 +1,23 @@
ARG DOCKER_REGISTRY_HOST
ARG CURRENT_DISTRO
ARG PEPENGINE_VERSION=latest
FROM ${DOCKER_REGISTRY_HOST}/pep-${CURRENT_DISTRO}-engine:${PEPENGINE_VERSION}
ENV BUILDROOT /build
ENV INSTPREFIX /install
ENV OUTDIR /out
### Setup working directory
RUN mkdir ${BUILDROOT}/libpEpAdapter
COPY . ${BUILDROOT}/libpEpAdapter
USER root
RUN chown -R pep-builder:pep-builder ${BUILDROOT}/libpEpAdapter
USER pep-builder
WORKDIR ${BUILDROOT}/libpEpAdapter
ARG LIBPEPADAPTER_VERSION
ARG CURRENT_DISTRO
### Build libpEpAdapter
RUN sh ./scripts/${CURRENT_DISTRO}/build_libpEpAdapter.sh && \
rm -rf ${BUILDROOT}/*

@ -0,0 +1,27 @@
include ../../DEPENDENCIES
export
PEPENGINE_VERSION=${pEpEngine}
CURRENT_DISTRO=$(shell basename $(shell pwd))
IMAGE_NAME=${DOCKER_REGISTRY_HOST}/pep-$(CURRENT_DISTRO)-libpepadapter
DOCKERFILE=libpEpAdapter.$(CURRENT_DISTRO).Dockerfile
IS_TAGGED=${TAGGED_BUILD}
ifeq ($(IS_TAGGED), true)
# $CI_COMMIT_TAG is a predefined environment variable from Gitlab
LIBPEPADAPTER_VERSION=${CI_COMMIT_TAG}
else
LIBPEPADAPTER_VERSION=$(shell git rev-parse --short=8 HEAD)
endif
all:
-docker pull $(IMAGE_NAME):latest
cd ../../ && docker build --build-arg CURRENT_DISTRO=$(CURRENT_DISTRO) \
--build-arg DOCKER_REGISTRY_HOST=${DOCKER_REGISTRY_HOST} \
--build-arg PEPENGINE_VERSION=$(PEPENGINE_VERSION) \
--build-arg LIBPEPADAPTER_VERSION=$(LIBPEPADAPTER_VERSION) \
--cache-from $(IMAGE_NAME):latest \
--tag=$(IMAGE_NAME):$(LIBPEPADAPTER_VERSION) \
--tag=$(IMAGE_NAME):${LIBPEPADAPTER_VERSION}_engine-${PEPENGINE_VERSION} \
--tag=$(IMAGE_NAME):latest \
-f scripts/${CURRENT_DISTRO}/$(DOCKERFILE) .
docker push $(IMAGE_NAME):${LIBPEPADAPTER_VERSION}
docker push $(IMAGE_NAME):${LIBPEPADAPTER_VERSION}_engine-${PEPENGINE_VERSION}
docker push $(IMAGE_NAME):latest

@ -0,0 +1,8 @@
#!/usr/bin/env sh
set -exo
echo "ENGINE_LIB_PATH=${INSTPREFIX}/lib" >> local.conf
echo "ENGINE_INC_PATH=${INSTPREFIX}/include" >> local.conf
make
make install PREFIX="${INSTPREFIX}"

@ -0,0 +1,23 @@
ARG DOCKER_REGISTRY_HOST
ARG CURRENT_DISTRO
ARG PEPENGINE_VERSION=latest
FROM ${DOCKER_REGISTRY_HOST}/pep-${CURRENT_DISTRO}-engine:${PEPENGINE_VERSION}
ENV BUILDROOT /build
ENV INSTPREFIX /install
ENV OUTDIR /out
### Setup working directory
RUN mkdir ${BUILDROOT}/libpEpAdapter
COPY . ${BUILDROOT}/libpEpAdapter
USER root
RUN chown -R pep-builder:pep-builder ${BUILDROOT}/libpEpAdapter
USER pep-builder
WORKDIR ${BUILDROOT}/libpEpAdapter
ARG LIBPEPADAPTER_VERSION
ARG CURRENT_DISTRO
### Build libpEpAdapter
RUN sh ./scripts/${CURRENT_DISTRO}/build_libpEpAdapter.sh && \
rm -rf ${BUILDROOT}/*

@ -1,3 +1,6 @@
// This file is under GNU General Public License 3.0
// see LICENSE.txt
#include "slurp.hh"
#include <fstream>
#include <sstream>

@ -1,5 +1,8 @@
#ifndef PEP_LIB_SLURP_HH
#define PEP_LIB_SLURP_HH
// This file is under GNU General Public License 3.0
// see LICENSE.txt
#ifndef LIBPEPADAPTER_LIB_SLURP_HH
#define LIBPEPADAPTER_LIB_SLURP_HH
#include <string>
@ -11,4 +14,4 @@ namespace pEp
} // end of namespace pEp
#endif // PEP_LIB_SLURP_HH
#endif // LIBPEPADAPTER_LIB_SLURP_HH

@ -1,3 +1,6 @@
// This file is under GNU General Public License 3.0
// see LICENSE.txt
#include "status_to_string.hh"
#include <sstream>

@ -1,4 +1,8 @@
#pragma once
// This file is under GNU General Public License 3.0
// see LICENSE.txt
#ifndef LIBPEPADAPTER_STATUS_TO_STRING_HH
#define LIBPEPADAPTER_STATUS_TO_STRING_HH
#include <pEp/pEpEngine.h>
#include <pEp/status_to_string.h>
@ -11,3 +15,5 @@ namespace pEp
std::string status_to_string(PEP_STATUS status);
} // end of namespace pEp
#endif // LIBPEPADAPTER_STATUS_TO_STRING_HH

@ -1,4 +1,7 @@
#pragma once
// This file is under GNU General Public License 3.0
// see LICENSE.txt
#ifndef LIBPEPADAPTER_FRAMEWORK_HH
#define LIBPEPADAPTER_FRAMEWORK_HH
#include <string>
#include <vector>
@ -57,3 +60,4 @@ namespace pEp {
};
};
#endif // LIBPEPADAPTER_FRAMEWORK_HH

Loading…
Cancel
Save