"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "plugins/rule_engines/irods_rule_engine_plugin-passthrough/libirods_rule_engine_plugin-passthrough.cpp" between
irods-4.2.5.tar.gz and irods-4.2.6.tar.gz

About: iRODS (the integrated Rule Oriented Data System) is a distributed data-management system for creating data grids, digital libraries, persistent archives, and real-time data systems.

libirods_rule_engine_plugin-passthrough.cpp  (irods-4.2.5):libirods_rule_engine_plugin-passthrough.cpp  (irods-4.2.6)
#include "irods_plugin_context.hpp" #include "irods_plugin_context.hpp"
#include "irods_re_plugin.hpp" #include "irods_re_plugin.hpp"
#include "irods_server_properties.hpp" #include "irods_server_properties.hpp"
#include "irods_state_table.h" #include "irods_state_table.h"
#include "rodsError.h" #include "rodsError.h"
#include "rodsErrorTable.h"
#include "rodsLog.h" #include "rodsLog.h"
#include <string> #include <string>
#include <functional> #include <functional>
#include <vector> #include <vector>
#include <unordered_map>
#include <regex> #include <regex>
#include <iterator>
#include <algorithm>
#include <initializer_list>
namespace
{
//
// Rule Engine Plugin
//
template <typename ...Args>
using operation = std::function<irods::error(irods::default_re_ctx&, Args...
)>;
struct pep_config
{
std::regex regex;
int code;
};
std::unordered_map<std::string, std::vector<pep_config>> pep_configs;
int matched_code = 0;
irods::error start(irods::default_re_ctx&, const std::string& _instance_name
)
{
try {
const auto& rule_engines = irods::get_server_property<const std::vec
tor<boost::any>&>(
std::vector<std::string>{irods::CFG_PLUGIN_CONFIGURATION_KW, iro
ds::PLUGIN_TYPE_RULE_ENGINE});
for (const auto& element : rule_engines) {
const auto& rule_engine = boost::any_cast<const std::unordered_m
ap<std::string, boost::any>&>(element);
const auto& instance_name = boost::any_cast<const std::string&>(
rule_engine.at(irods::CFG_INSTANCE_NAME_KW));
if (instance_name == _instance_name) {
const auto& plugin_spec_cfg = boost::any_cast<const std::uno
rdered_map<std::string, boost::any>&>(
rule_engine.at(irods::CFG_PLUGIN_SPECIFIC_CONFIGURATION_
KW));
for (const auto& e : boost::any_cast<const std::vector<boost
::any>&>(plugin_spec_cfg.at("return_codes_for_peps"))) {
const auto& config = boost::any_cast<const std::unordere
d_map<std::string, boost::any>&>(e);
const auto& regex = boost::any_cast<const std::string&>(
config.at("regex"));
const auto code = boost::any_cast<int>(config.at("code")
);
pep_configs[_instance_name].push_back({std::regex{regex}
, code});
}
using pluggable_rule_engine = irods::pluggable_rule_engine<irods::default_re_ctx return SUCCESS();
>;
namespace {
//
// Rule Engine Plugin
//
template <typename ...Args>
using operation = std::function<irods::error(irods::default_re_ctx&, Args...)>;
struct pep_config
{
std::regex regex;
int code;
};
std::vector<pep_config> pep_configs;
int matched_code = 0;
irods::error start(irods::default_re_ctx&, const std::string& _instance_name)
{
try {
const auto& rule_engines = irods::get_server_property<const std::vector<
boost::any>&>(
std::vector<std::string>{irods::CFG_PLUGIN_CONFIGURATION_KW, irods::
PLUGIN_TYPE_RULE_ENGINE});
for (const auto& element : rule_engines) {
const auto& rule_engine = boost::any_cast<const std::unordered_map<s
td::string, boost::any>&>(element);
const auto& instance_name = boost::any_cast<const std::string&>(rule
_engine.at(irods::CFG_INSTANCE_NAME_KW));
if (instance_name == _instance_name) {
const auto& plugin_spec_cfg = boost::any_cast<const std::unorder
ed_map<std::string, boost::any>&>(
rule_engine.at(irods::CFG_PLUGIN_SPECIFIC_CONFIGURATION_KW))
;
for (const auto& e : boost::any_cast<const std::vector<boost::an
y>&>(plugin_spec_cfg.at("return_codes_for_peps"))) {
const auto& config = boost::any_cast<const std::unordered_ma
p<std::string, boost::any>&>(e);
const auto& regex = boost::any_cast<const std::string&>(conf
ig.at("regex"));
const auto code = boost::any_cast<int>(config.at("code"));
pep_configs.push_back({std::regex{regex}, code});
} }
return SUCCESS();
} }
} }
} catch (const boost::bad_any_cast& e) {
catch (const boost::bad_any_cast& e) { return ERROR(INVALID_ANY_CAST, e.what());
return ERROR(INVALID_ANY_CAST, e.what()); }
} catch (const std::exception& e) {
catch (const std::exception& e) { return ERROR(SYS_CONFIG_FILE_ERR, e.what());
return ERROR(SYS_CONFIG_FILE_ERR, e.what()); }
return ERROR(SYS_CONFIG_FILE_ERR, "[passthrough] Bad rule engine plugin
configuration.");
} }
return ERROR(SYS_CONFIG_FILE_ERR, "[passthrough] bad rule engine plugin conf irods::error rule_exists(const std::string& _instance_name,
iguration."); irods::default_re_ctx&,
} const std::string& _rule_name,
bool& _exists)
{
for (const auto& pc : pep_configs[_instance_name]) {
_exists = std::regex_search(_rule_name, pc.regex);
if (_exists) {
matched_code = pc.code;
break;
}
}
irods::error rule_exists(irods::default_re_ctx&, const std::string& _rule_name, const char* msg = "[passthrough] In rule_exists. instance name = %s, rul
bool& _exists) e = %s, exists = %s.";
{ rodsLog(LOG_DEBUG, msg, _instance_name.c_str(), _rule_name.c_str(), (_ex
for (const auto& pc : pep_configs) { ists ? "true" : "false"));
_exists = std::regex_search(_rule_name, pc.regex);
if (_exists) { return SUCCESS();
matched_code = pc.code;
break;
}
} }
const char* msg = "[passthrough] in rule_exists. rule = %s, exists = %s."; irods::error list_rules(irods::default_re_ctx&, std::vector<std::string>& _r
rodsLog(LOG_DEBUG, msg, _rule_name.c_str(), (_exists ? "true" : "false")); ules)
{
rodsLog(LOG_DEBUG, "[passthrough] In list_rules.");
return SUCCESS();
}
return SUCCESS(); irods::error exec_rule(const std::string& _instance_name,
} irods::default_re_ctx&,
const std::string& _rule_name,
std::list<boost::any>& _rule_arguments,
irods::callback _effect_handler)
{
const char* msg = "[passthrough] In exec_rule. instance name = %s, rule
= %s, returned '%s' to REPF.";
const auto matched_code_string = std::to_string(matched_code);
rodsLog(LOG_DEBUG, msg, _instance_name.c_str(), _rule_name.c_str(), matc
hed_code_string.c_str());
irods::error list_rules(irods::default_re_ctx&, std::vector<std::string>& _rules const std::initializer_list<int> continuation_codes = {SYS_NOT_SUPPORTED
) , RULE_ENGINE_CONTINUE};
{ const auto pred = [ec = matched_code](const auto _ec) { return _ec == ec
rodsLog(LOG_DEBUG, "[passthrough] in list_rules."); ; };
return SUCCESS();
}
irods::error exec_rule(irods::default_re_ctx&, if (std::any_of(std::begin(continuation_codes), std::end(continuation_co
const std::string& _rule_name, des), pred)) {
std::list<boost::any>& _rule_arguments, return CODE(matched_code);
irods::callback _effect_handler) }
{
const char* msg = "[passthrough] in exec_rule. rule = %s, returned 'RULE_ENG
INE_CONTINUE' to REPF.";
rodsLog(LOG_DEBUG, msg, _rule_name.c_str());
return ERROR(matched_code, "");
}
return ERROR(matched_code, "");
}
} // namespace (anonymous) } // namespace (anonymous)
// //
// Plugin Factory // Plugin Factory
// //
using pluggable_rule_engine = irods::pluggable_rule_engine<irods::default_re_ctx
>;
extern "C" extern "C"
pluggable_rule_engine* plugin_factory(const std::string& _instance_name, pluggable_rule_engine* plugin_factory(const std::string& _instance_name,
const std::string& _context) const std::string& _context)
{ {
// clang-format off // clang-format off
const auto no_op = [] { return SUCCESS(); }; const auto no_op = [](auto...) { return SUCCESS(); };
const auto not_supported = [] { return ERROR(SYS_NOT_SUPPORTED, "not support const auto not_supported = [](auto...) { return CODE(SYS_NOT_SUPPORTED); };
ed"); };
// clang-format on // clang-format on
const auto rule_exists_wrapper = [_instance_name](irods::default_re_ctx& _ct
x,
const std::string& _rule_n
ame,
bool& _exists)
{
return rule_exists(_instance_name, _ctx, _rule_name, _exists);
};
const auto exec_rule_wrapper = [_instance_name](irods::default_re_ctx& _ctx,
const std::string& _rule_nam
e,
std::list<boost::any>& _rule
_arguments,
irods::callback _effect_hand
ler)
{
return exec_rule(_instance_name, _ctx, _rule_name, _rule_arguments, _eff
ect_handler);
};
auto* re = new pluggable_rule_engine{_instance_name, _context}; auto* re = new pluggable_rule_engine{_instance_name, _context};
re->add_operation("start", operation<const std::string&>{start}); re->add_operation("start", operation<const std::string&>{start});
re->add_operation("stop", {no_op}); re->add_operation("stop", operation<const std::string&>{no_op});
re->add_operation("rule_exists", operation<const std::string&, bool&>{rule_e re->add_operation("rule_exists", operation<const std::string&, bool&>{rule_e
xists}); xists_wrapper});
re->add_operation("list_rules", operation<std::vector<std::string>&>{list_ru les}); re->add_operation("list_rules", operation<std::vector<std::string>&>{list_ru les});
re->add_operation("exec_rule", operation<const std::string&, std::list<boost re->add_operation("exec_rule", operation<const std::string&, std::list<boost
::any>&, irods::callback>{exec_rule}); ::any>&, irods::callback>{exec_rule_wrapper});
re->add_operation("exec_rule_text", {not_supported}); re->add_operation("exec_rule_text", operation<const std::string&, msParamArr
re->add_operation("exec_rule_expression", {not_supported}); ay_t*, const std::string&, irods::callback>{not_supported});
re->add_operation("exec_rule_expression", operation<const std::string&, msPa
ramArray_t*, const std::string&, irods::callback>{not_supported});
return re; return re;
} }
 End of changes. 19 change blocks. 
99 lines changed or deleted 147 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)