Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ limitations under the License.

#include <Poco/Dynamic/Var.h>

#include "privmx/endpoint/core/c_api.h"
#include "privmx/endpoint/core/BackendRequester.hpp"
#include "privmx/endpoint/core/VarDeserializer.hpp"
#include "privmx/endpoint/core/VarSerializer.hpp"
Expand All @@ -24,18 +25,14 @@ namespace core {

class BackendRequesterVarInterface {
public:
enum METHOD {
BackendRequest = 0
};

BackendRequesterVarInterface(const core::VarSerializer& serializer)
: _serializer(serializer) {}

Poco::Dynamic::Var backendRequest(const Poco::Dynamic::Var& args);

Poco::Dynamic::Var exec(METHOD method, const Poco::Dynamic::Var& args);
Poco::Dynamic::Var exec(privmx_BackendRequester_Method method, const Poco::Dynamic::Var& args);
private:
static std::map<METHOD, Poco::Dynamic::Var (BackendRequesterVarInterface::*)(const Poco::Dynamic::Var&)> methodMap;
static std::map<privmx_BackendRequester_Method, Poco::Dynamic::Var (BackendRequesterVarInterface::*)(const Poco::Dynamic::Var&)> methodMap;

core::VarDeserializer _deserializer;
core::VarSerializer _serializer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ limitations under the License.

#include <Poco/Dynamic/Var.h>

#include "privmx/endpoint/core/c_api.h"
#include "privmx/endpoint/core/Connection.hpp"
#include "privmx/endpoint/core/VarDeserializer.hpp"
#include "privmx/endpoint/core/VarSerializer.hpp"
Expand All @@ -24,15 +25,6 @@ namespace core {

class ConnectionVarInterface {
public:
enum METHOD {
Connect = 0,
ConnectPublic = 1,
GetConnectionId = 2,
ListContexts = 3,
Disconnect = 4,
GetContextUsers = 5
};

ConnectionVarInterface(const core::VarSerializer& serializer)
: _serializer(serializer) {}

Expand All @@ -43,12 +35,12 @@ class ConnectionVarInterface {
Poco::Dynamic::Var disconnect(const Poco::Dynamic::Var& args);
Poco::Dynamic::Var getContextUsers(const Poco::Dynamic::Var& args);

Poco::Dynamic::Var exec(METHOD method, const Poco::Dynamic::Var& args);
Poco::Dynamic::Var exec(privmx_Connection_Method method, const Poco::Dynamic::Var& args);

Connection getApi() const { return _connection; }

private:
static std::map<METHOD, Poco::Dynamic::Var (ConnectionVarInterface::*)(const Poco::Dynamic::Var&)> methodMap;
static std::map<privmx_Connection_Method, Poco::Dynamic::Var (ConnectionVarInterface::*)(const Poco::Dynamic::Var&)> methodMap;

Connection _connection;
core::VarDeserializer _deserializer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ limitations under the License.

#include <Poco/Dynamic/Var.h>

#include "privmx/endpoint/core/c_api.h"
#include "privmx/endpoint/core/EventQueue.hpp"
#include "privmx/endpoint/core/VarSerializer.hpp"

Expand All @@ -23,19 +24,17 @@ namespace core {

class EventQueueVarInterface {
public:
enum METHOD { WaitEvent = 0, GetEvent = 1, EmitBreakEvent = 2 };

EventQueueVarInterface(EventQueue eventQueue, const VarSerializer& serializer)
: _eventQueue(std::move(eventQueue)), _serializer(serializer) {}

Poco::Dynamic::Var waitEvent(const Poco::Dynamic::Var& args);
Poco::Dynamic::Var getEvent(const Poco::Dynamic::Var& args);
Poco::Dynamic::Var emitBreakEvent(const Poco::Dynamic::Var& args);

Poco::Dynamic::Var exec(METHOD method, const Poco::Dynamic::Var& args);
Poco::Dynamic::Var exec(privmx_EventQueue_Method method, const Poco::Dynamic::Var& args);

private:
static std::map<METHOD, Poco::Dynamic::Var (EventQueueVarInterface::*)(const Poco::Dynamic::Var&)> methodMap;
static std::map<privmx_EventQueue_Method, Poco::Dynamic::Var (EventQueueVarInterface::*)(const Poco::Dynamic::Var&)> methodMap;

EventQueue _eventQueue;
VarSerializer _serializer;
Expand Down
41 changes: 41 additions & 0 deletions endpoint/core/include_pub/privmx/endpoint/core/c_api.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
PrivMX Endpoint.
Copyright © 2024 Simplito sp. z o.o.

This file is part of the PrivMX Platform (https://privmx.dev).
This software is Licensed under the PrivMX Free License.

See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef _PRIVMXLIB_ENDPOINT_CORE_C_API_H_
#define _PRIVMXLIB_ENDPOINT_CORE_C_API_H_

#ifdef __cplusplus
extern "C" {
#endif

typedef enum {
privmx_BackendRequester_BackendRequest = 0,
} privmx_BackendRequester_Method;

typedef enum {
privmx_Connection_Connect = 0,
privmx_Connection_ConnectPublic = 1,
privmx_Connection_GetConnectionId = 2,
privmx_Connection_ListContexts = 3,
privmx_Connection_Disconnect = 4,
privmx_Connection_GetContextUsers = 5,
} privmx_Connection_Method;

typedef enum {
privmx_EventQueue_WaitEvent = 0,
privmx_EventQueue_GetEvent = 1,
privmx_EventQueue_EmitBreakEvent = 2,
} privmx_EventQueue_Method;

#ifdef __cplusplus
}
#endif

#endif // _PRIVMXLIB_ENDPOINT_CORE_C_API_H_
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ limitations under the License.

using namespace privmx::endpoint::core;

std::map<BackendRequesterVarInterface::METHOD, Poco::Dynamic::Var (BackendRequesterVarInterface::*)(const Poco::Dynamic::Var&)>
BackendRequesterVarInterface::methodMap = {{BackendRequest, &BackendRequesterVarInterface::backendRequest}};
std::map<privmx_BackendRequester_Method, Poco::Dynamic::Var (BackendRequesterVarInterface::*)(const Poco::Dynamic::Var&)>
BackendRequesterVarInterface::methodMap = {{privmx_BackendRequester_BackendRequest, &BackendRequesterVarInterface::backendRequest}};

Poco::Dynamic::Var BackendRequesterVarInterface::backendRequest(const Poco::Dynamic::Var& args) {
Poco::JSON::Array::Ptr argsArr = VarInterfaceUtil::validateAndExtractArray(args, 3, 6);
Expand Down Expand Up @@ -46,7 +46,7 @@ Poco::Dynamic::Var BackendRequesterVarInterface::backendRequest(const Poco::Dyna
}
}

Poco::Dynamic::Var BackendRequesterVarInterface::exec(METHOD method, const Poco::Dynamic::Var& args) {
Poco::Dynamic::Var BackendRequesterVarInterface::exec(privmx_BackendRequester_Method method, const Poco::Dynamic::Var& args) {
auto it = methodMap.find(method);
if (it == methodMap.end()) {
throw InvalidMethodException();
Expand Down
16 changes: 8 additions & 8 deletions endpoint/core/src/varinterface/ConnectionVarInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ limitations under the License.

using namespace privmx::endpoint::core;

std::map<ConnectionVarInterface::METHOD, Poco::Dynamic::Var (ConnectionVarInterface::*)(const Poco::Dynamic::Var&)>
ConnectionVarInterface::methodMap = {{Connect, &ConnectionVarInterface::connect},
{ConnectPublic, &ConnectionVarInterface::connectPublic},
{GetConnectionId, &ConnectionVarInterface::getConnectionId},
{ListContexts, &ConnectionVarInterface::listContexts},
{Disconnect, &ConnectionVarInterface::disconnect},
{GetContextUsers, &ConnectionVarInterface::getContextUsers}};
std::map<privmx_Connection_Method, Poco::Dynamic::Var (ConnectionVarInterface::*)(const Poco::Dynamic::Var&)>
ConnectionVarInterface::methodMap = {{privmx_Connection_Connect, &ConnectionVarInterface::connect},
{privmx_Connection_ConnectPublic, &ConnectionVarInterface::connectPublic},
{privmx_Connection_GetConnectionId, &ConnectionVarInterface::getConnectionId},
{privmx_Connection_ListContexts, &ConnectionVarInterface::listContexts},
{privmx_Connection_Disconnect, &ConnectionVarInterface::disconnect},
{privmx_Connection_GetContextUsers, &ConnectionVarInterface::getContextUsers}};

Poco::Dynamic::Var ConnectionVarInterface::connect(const Poco::Dynamic::Var& args) {
auto argsArr = VarInterfaceUtil::validateAndExtractArray(args, 3);
Expand Down Expand Up @@ -67,7 +67,7 @@ Poco::Dynamic::Var ConnectionVarInterface::getContextUsers(const Poco::Dynamic::
return _serializer.serialize(result);
}

Poco::Dynamic::Var ConnectionVarInterface::exec(METHOD method, const Poco::Dynamic::Var& args) {
Poco::Dynamic::Var ConnectionVarInterface::exec(privmx_Connection_Method method, const Poco::Dynamic::Var& args) {
auto it = methodMap.find(method);
if (it == methodMap.end()) {
throw InvalidMethodException();
Expand Down
10 changes: 5 additions & 5 deletions endpoint/core/src/varinterface/EventQueueVarInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ limitations under the License.

using namespace privmx::endpoint::core;

std::map<EventQueueVarInterface::METHOD, Poco::Dynamic::Var (EventQueueVarInterface::*)(const Poco::Dynamic::Var&)>
EventQueueVarInterface::methodMap = {{WaitEvent, &EventQueueVarInterface::waitEvent},
{GetEvent, &EventQueueVarInterface::getEvent},
{EmitBreakEvent, &EventQueueVarInterface::emitBreakEvent}};
std::map<privmx_EventQueue_Method, Poco::Dynamic::Var (EventQueueVarInterface::*)(const Poco::Dynamic::Var&)>
EventQueueVarInterface::methodMap = {{privmx_EventQueue_WaitEvent, &EventQueueVarInterface::waitEvent},
{privmx_EventQueue_GetEvent, &EventQueueVarInterface::getEvent},
{privmx_EventQueue_EmitBreakEvent, &EventQueueVarInterface::emitBreakEvent}};

Poco::Dynamic::Var EventQueueVarInterface::waitEvent(const Poco::Dynamic::Var& args) {
VarInterfaceUtil::validateAndExtractArray(args, 0);
Expand All @@ -47,7 +47,7 @@ Poco::Dynamic::Var EventQueueVarInterface::emitBreakEvent(const Poco::Dynamic::V
return {};
}

Poco::Dynamic::Var EventQueueVarInterface::exec(METHOD method, const Poco::Dynamic::Var& args) {
Poco::Dynamic::Var EventQueueVarInterface::exec(privmx_EventQueue_Method method, const Poco::Dynamic::Var& args) {
auto it = methodMap.find(method);
if (it == methodMap.end()) {
throw InvalidMethodException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,14 @@ limitations under the License.
#include "privmx/endpoint/core/VarDeserializer.hpp"
#include "privmx/endpoint/core/VarSerializer.hpp"
#include "privmx/endpoint/crypto/CryptoApi.hpp"
#include "privmx/endpoint/crypto/c_api.h"

namespace privmx {
namespace endpoint {
namespace crypto {

class CryptoApiVarInterface {
public:
enum METHOD {
Create = 0,
SignData = 1,
GeneratePrivateKey = 2,
DerivePrivateKey = 3,
DerivePrivateKey2 = 4,
DerivePublicKey = 5,
GenerateKeySymmetric = 6,
EncryptDataSymmetric = 7,
DecryptDataSymmetric = 8,
ConvertPEMKeytoWIFKey = 9,
VerifySignature = 10,
};

CryptoApiVarInterface(const core::VarSerializer& serializer)
: _serializer(serializer) {}

Expand All @@ -54,10 +41,10 @@ class CryptoApiVarInterface {

Poco::Dynamic::Var convertPEMKeytoWIFKey(const Poco::Dynamic::Var& args);

Poco::Dynamic::Var exec(METHOD method, const Poco::Dynamic::Var& args);
Poco::Dynamic::Var exec(privmx_CryptoApi_Method method, const Poco::Dynamic::Var& args);

private:
static std::map<METHOD, Poco::Dynamic::Var (CryptoApiVarInterface::*)(const Poco::Dynamic::Var&)> methodMap;
static std::map<privmx_CryptoApi_Method, Poco::Dynamic::Var (CryptoApiVarInterface::*)(const Poco::Dynamic::Var&)> methodMap;

CryptoApi _cryptoApi;
core::VarDeserializer _deserializer;
Expand Down
36 changes: 36 additions & 0 deletions endpoint/crypto/include_pub/privmx/endpoint/crypto/c_api.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
PrivMX Endpoint.
Copyright © 2024 Simplito sp. z o.o.

This file is part of the PrivMX Platform (https://privmx.dev).
This software is Licensed under the PrivMX Free License.

See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef _PRIVMXLIB_ENDPOINT_CRYPTO_C_API_H_
#define _PRIVMXLIB_ENDPOINT_CRYPTO_C_API_H_

#ifdef __cplusplus
extern "C" {
#endif

typedef enum {
privmx_CryptoApi_Create = 0,
privmx_CryptoApi_SignData = 1,
privmx_CryptoApi_GeneratePrivateKey = 2,
privmx_CryptoApi_DerivePrivateKey = 3,
privmx_CryptoApi_DerivePrivateKey2 = 4,
privmx_CryptoApi_DerivePublicKey = 5,
privmx_CryptoApi_GenerateKeySymmetric = 6,
privmx_CryptoApi_EncryptDataSymmetric = 7,
privmx_CryptoApi_DecryptDataSymmetric = 8,
privmx_CryptoApi_ConvertPEMKeytoWIFKey = 9,
privmx_CryptoApi_VerifySignature = 10,
} privmx_CryptoApi_Method;

#ifdef __cplusplus
}
#endif

#endif // _PRIVMXLIB_ENDPOINT_CRYPTO_C_API_H_
26 changes: 13 additions & 13 deletions endpoint/crypto/src/varinterface/CryptoApiVarInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ limitations under the License.
using namespace privmx::endpoint;
using namespace privmx::endpoint::crypto;

std::map<CryptoApiVarInterface::METHOD, Poco::Dynamic::Var (CryptoApiVarInterface::*)(const Poco::Dynamic::Var&)>
CryptoApiVarInterface::methodMap = {{Create, &CryptoApiVarInterface::create},
{SignData, &CryptoApiVarInterface::signData},
{GeneratePrivateKey, &CryptoApiVarInterface::generatePrivateKey},
{DerivePrivateKey, &CryptoApiVarInterface::derivePrivateKey},
{DerivePrivateKey2, &CryptoApiVarInterface::derivePrivateKey2},
{DerivePublicKey, &CryptoApiVarInterface::derivePublicKey},
{GenerateKeySymmetric, &CryptoApiVarInterface::generateKeySymmetric},
{EncryptDataSymmetric, &CryptoApiVarInterface::encryptDataSymmetric},
{DecryptDataSymmetric, &CryptoApiVarInterface::decryptDataSymmetric},
{ConvertPEMKeytoWIFKey, &CryptoApiVarInterface::convertPEMKeytoWIFKey},
{VerifySignature, &CryptoApiVarInterface::verifySignature}};
std::map<privmx_CryptoApi_Method, Poco::Dynamic::Var (CryptoApiVarInterface::*)(const Poco::Dynamic::Var&)>
CryptoApiVarInterface::methodMap = {{privmx_CryptoApi_Create, &CryptoApiVarInterface::create},
{privmx_CryptoApi_SignData, &CryptoApiVarInterface::signData},
{privmx_CryptoApi_GeneratePrivateKey, &CryptoApiVarInterface::generatePrivateKey},
{privmx_CryptoApi_DerivePrivateKey, &CryptoApiVarInterface::derivePrivateKey},
{privmx_CryptoApi_DerivePrivateKey2, &CryptoApiVarInterface::derivePrivateKey2},
{privmx_CryptoApi_DerivePublicKey, &CryptoApiVarInterface::derivePublicKey},
{privmx_CryptoApi_GenerateKeySymmetric, &CryptoApiVarInterface::generateKeySymmetric},
{privmx_CryptoApi_EncryptDataSymmetric, &CryptoApiVarInterface::encryptDataSymmetric},
{privmx_CryptoApi_DecryptDataSymmetric, &CryptoApiVarInterface::decryptDataSymmetric},
{privmx_CryptoApi_ConvertPEMKeytoWIFKey, &CryptoApiVarInterface::convertPEMKeytoWIFKey},
{privmx_CryptoApi_VerifySignature, &CryptoApiVarInterface::verifySignature}};

Poco::Dynamic::Var CryptoApiVarInterface::create(const Poco::Dynamic::Var& args) {
core::VarInterfaceUtil::validateAndExtractArray(args, 0);
Expand Down Expand Up @@ -112,7 +112,7 @@ Poco::Dynamic::Var CryptoApiVarInterface::convertPEMKeytoWIFKey(const Poco::Dyna
return _serializer.serialize(result);
}

Poco::Dynamic::Var CryptoApiVarInterface::exec(METHOD method, const Poco::Dynamic::Var& args) {
Poco::Dynamic::Var CryptoApiVarInterface::exec(privmx_CryptoApi_Method method, const Poco::Dynamic::Var& args) {
auto it = methodMap.find(method);
if (it == methodMap.end()) {
throw core::InvalidMethodException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,14 @@ limitations under the License.
#include "privmx/endpoint/event/EventApi.hpp"
#include "privmx/endpoint/event/EventVarSerializer.hpp"
#include <privmx/endpoint/core/VarDeserializer.hpp>
#include "privmx/endpoint/event/c_api.h"

namespace privmx {
namespace endpoint {
namespace event {

class EventApiVarInterface {
public:
enum METHOD {
Create = 0,
EmitEvent = 1,
SubscribeForCustomEvents = 2,
UnsubscribeFromCustomEvents = 3,
};

EventApiVarInterface(core::Connection connection, const core::VarSerializer& serializer)
: _connection(std::move(connection)), _serializer(serializer) {}

Expand All @@ -39,12 +33,12 @@ class EventApiVarInterface {
Poco::Dynamic::Var subscribeForCustomEvents(const Poco::Dynamic::Var& args);
Poco::Dynamic::Var unsubscribeFromCustomEvents(const Poco::Dynamic::Var& args);

Poco::Dynamic::Var exec(METHOD method, const Poco::Dynamic::Var& args);
Poco::Dynamic::Var exec(privmx_EventApi_Method method, const Poco::Dynamic::Var& args);

EventApi getApi() const { return _eventApi; }

private:
static std::map<METHOD, Poco::Dynamic::Var (EventApiVarInterface::*)(const Poco::Dynamic::Var&)> methodMap;
static std::map<privmx_EventApi_Method, Poco::Dynamic::Var (EventApiVarInterface::*)(const Poco::Dynamic::Var&)> methodMap;

core::Connection _connection;
EventApi _eventApi;
Expand Down
29 changes: 29 additions & 0 deletions endpoint/event/include_pub/privmx/endpoint/event/c_api.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
PrivMX Endpoint.
Copyright © 2024 Simplito sp. z o.o.

This file is part of the PrivMX Platform (https://privmx.dev).
This software is Licensed under the PrivMX Free License.

See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef _PRIVMXLIB_ENDPOINT_EVENT_C_API_H_
#define _PRIVMXLIB_ENDPOINT_EVENT_C_API_H_

#ifdef __cplusplus
extern "C" {
#endif

typedef enum {
privmx_EventApi_Create = 0,
privmx_EventApi_EmitEvent = 1,
privmx_EventApi_SubscribeForCustomEvents = 2,
privmx_EventApi_UnsubscribeFromCustomEvents = 3,
} privmx_EventApi_Method;

#ifdef __cplusplus
}
#endif

#endif // _PRIVMXLIB_ENDPOINT_EVENT_C_API_H_
Loading