Browse Source

Booooy... I'm giving up and implement FuncCache for 'config_passphrase()' and 'config_passphrase_for_new_keys()' manually to get rid of that template gebastel and resource management of C strings in the function cache.

JSON-153
Roker 2 years ago
parent
commit
f317afaa78
3 changed files with 67 additions and 3 deletions
  1. +2
    -0
      server/ev_server.cc
  2. +61
    -1
      server/function_map.hh
  3. +4
    -2
      server/server_version.cc

+ 2
- 0
server/ev_server.cc View File

@ -97,6 +97,8 @@ const FunctionMap functions = {
// FP( "config_use_only_own_private_keys", new FuncCache<void, In_Pep_Session, In<bool>>( "conf_uoopk", &config_use_only_own_private_keys) ),
FP( "config_service_log" , new FuncCache<void, In_Pep_Session, In<bool>>( "conf_service_log", &config_service_log) ),
FP( "config_cipher_suite", new FuncCache<void, In_Pep_Session, In<PEP_CIPHER_SUITE>>( "config_cipher_suite", &config_cipher_suite) ),
FP( "config_passphrase", new FuncCachePassphrase<void, In_Pep_Session, In<c_string>>( "config_passphrase" ) ),
FP( "config_passphrase_for_new_keys", new FuncCachePassphrase4NewKeys<void, In_Pep_Session, In<bool>, In<c_string>>( "config_passphrase4nk" ) ),
FP( "Identity Management API", new Separator),
FP( "get_identity" , new Func<PEP_STATUS, In_Pep_Session, In<c_string>, In<c_string>, Out<pEp_identity*>>( &get_identity) ),


+ 61
- 1
server/function_map.hh View File

@ -224,7 +224,7 @@ public:
js::Value call(const js::Array& parameters, Context* context) const override
{
Logger Log("FuncCache::call<2>");
Logger Log("FuncCache::call");
typedef std::tuple<typename Args::c_type...> param_tuple_t;
//param_tuple_t param_tuple;
@ -243,6 +243,66 @@ private:
};
template<class R, class... Args>
class FuncCachePassphrase : public Func<R, Args...>
{
public:
typedef Func<R, Args...> Base;
typedef typename Return<R>::return_type ReturnType;
typedef helper<R, 0, sizeof...(Args), Args...> Helper;
FuncCachePassphrase(const std::string& _func_name )
: Base( &config_passphrase )
, func_name(_func_name)
{}
js::Value call(const js::Array& parameters, Context* context) const override
{
Logger Log("FuncCachePasswd::call");
const std::string& passphrase = parameters.at(0).get_str();
Log << Logger::Debug << "func_name=\"" << func_name << "\", value is confidential. ";
std::function<void(PEP_SESSION)> func = [passphrase](PEP_SESSION session) { config_passphrase(session, passphrase.c_str()); };
context->cache(func_name, func);
return Base::call(parameters, context);
}
private:
const std::string func_name;
};
template<class R, class... Args>
class FuncCachePassphrase4NewKeys : public Func<R, Args...>
{
public:
typedef Func<R, Args...> Base;
typedef typename Return<R>::return_type ReturnType;
typedef helper<R, 0, sizeof...(Args), Args...> Helper;
FuncCachePassphrase4NewKeys(const std::string& _func_name )
: Base( &config_passphrase_for_new_keys )
, func_name(_func_name)
{}
js::Value call(const js::Array& parameters, Context* context) const override
{
Logger Log("FuncCachePasswd4NK::call");
bool enable = parameters.at(0).get_bool();
const std::string& passphrase = parameters.at(1).get_str();
Log << Logger::Debug << "func_name=\"" << func_name << "\", value is confidential. ";
std::function<void(PEP_SESSION)> func = [enable, passphrase](PEP_SESSION session) { config_passphrase_for_new_keys(session, enable, passphrase.c_str()); };
context->cache(func_name, func);
return Base::call(parameters, context);
}
private:
const std::string func_name;
};
// Just a separating placeholder in the drop-down list. Does not calls anything.
class Separator : public FuncBase


+ 4
- 2
server/server_version.cc View File

@ -73,7 +73,8 @@ static const std::string VersionName =
// "(40b) Sättelstädt"; // JSON-139: support for NULL pointers in "const char*" parameters: In<c_string, NullOkay>
// 41a,b were skipped, intentionally
"(42) Gotha"; // JSON-152: 2-parameter version of pollForEvents().
// "(42) Gotha"; // JSON-152: 2-parameter version of pollForEvents().
"(43) Wandersleben"; // JSON-153 passphrase support. *sigh*
} // end of anonymous namespace
////////////////////////////////////////////////////////////////////////////
@ -106,7 +107,8 @@ const ServerVersion& server_version()
//static const ServerVersion sv(0,18,4); // JSON-141: fix handling of parameters of type PEP_rating
// 0.19 was skipped intentionally.
static const ServerVersion sv(0,20,0); // JSON-152: 2-parameter version of pollForEvents().
//static const ServerVersion sv(0,20,0); // JSON-152: 2-parameter version of pollForEvents().
static const ServerVersion sv(0,20,1); // JSON-153: passphrase support
return sv;
}


Loading…
Cancel
Save