Skip to content

Commit

Permalink
[irods#7553] Added serialize function for MsParamArray**
Browse files Browse the repository at this point in the history
  • Loading branch information
FifthPotato authored and korydraughn committed Apr 21, 2024
1 parent 1b4552b commit cd6b746
Show file tree
Hide file tree
Showing 2 changed files with 166 additions and 1 deletion.
75 changes: 75 additions & 0 deletions scripts/irods/test/test_dynamic_peps.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,3 +617,78 @@ def test_if_StructFileExtAndRegInp_is_exposed__issue_7413(self):
self.user.run_icommand(['irm', '-rf', TEST_COLLECTION_NAME])
self.user.run_icommand(['irm', '-rf', TEST_COLLECTION_NAME + "_backup"])
self.user.run_icommand(['irm', '-f', TEST_TARFILE_NAME])

@unittest.skipIf(plugin_name != 'irods_rule_engine_plugin-irods_rule_language' or test.settings.RUN_IN_TOPOLOGY, "Requires NREP and single node zone.")
def test_if_MsParamArray_is_exposed__issue_7553(self):
with temporary_core_file() as core:
avu_prefix = 'test_if_MsParamArray_is_exposed__issue_7553'
# Add a rule to core.re which when triggered will add AVUs to the user's
# session collection.
core.add_rule(dedent('''
pep_api_exec_my_rule_post(*INSTANCE, *COMM, *STRUCTINP, *OUT) {{
*v = *OUT."0_inOutStruct";
msiModAVUMetadata('-C', '{self.user.session_collection}', 'add', '{avu_prefix}_0', *v, '');
*v = *OUT."0_label";
msiModAVUMetadata('-C', '{self.user.session_collection}', 'add', '{avu_prefix}_1', *v, '');
*v = *OUT."0_type";
msiModAVUMetadata('-C', '{self.user.session_collection}', 'add', '{avu_prefix}_2', *v, '');
*v = *OUT.len;
msiModAVUMetadata('-C', '{self.user.session_collection}', 'add', '{avu_prefix}_3', *v, '');
*v = *OUT.oprType;
msiModAVUMetadata('-C', '{self.user.session_collection}', 'add', '{avu_prefix}_4', *v, '');
*v = *OUT."1_inOutStruct";
msiModAVUMetadata('-C', '{self.user.session_collection}', 'add', '{avu_prefix}_5', *v, '');
*v = *OUT."1_label";
msiModAVUMetadata('-C', '{self.user.session_collection}', 'add', '{avu_prefix}_6', *v, '');
*v = *OUT."1_type";
msiModAVUMetadata('-C', '{self.user.session_collection}', 'add', '{avu_prefix}_7', *v, '');
*v = *OUT."2_inOutStruct";
msiModAVUMetadata('-C', '{self.user.session_collection}', 'add', '{avu_prefix}_8', *v, '');
*v = *OUT."2_label";
msiModAVUMetadata('-C', '{self.user.session_collection}', 'add', '{avu_prefix}_9', *v, '');
*v = *OUT."2_type";
msiModAVUMetadata('-C', '{self.user.session_collection}', 'add', '{avu_prefix}_10', *v, '');
}}
'''.format(**locals())))

try:
# Should trigger PEP
self.user.assert_icommand(['irule', '*A=4;*B=3.4;*C="potato"', 'null', '*A%*B%*C'], 'STDOUT')

self.user.assert_icommand(['imeta', 'ls', '-C', self.user.session_collection], 'STDOUT', [
f'attribute: {avu_prefix}_0\nvalue: 4\n',
f'attribute: {avu_prefix}_1\nvalue: *A\n',
f'attribute: {avu_prefix}_2\nvalue: INT_PI\n',
f'attribute: {avu_prefix}_3\nvalue: 3\n',
f'attribute: {avu_prefix}_4\nvalue: 0\n',
f'attribute: {avu_prefix}_5\nvalue: 3.400000\n',
f'attribute: {avu_prefix}_6\nvalue: *B\n',
f'attribute: {avu_prefix}_7\nvalue: DOUBLE_PI\n',
f'attribute: {avu_prefix}_8\nvalue: potato\n',
f'attribute: {avu_prefix}_9\nvalue: *C\n',
f'attribute: {avu_prefix}_10\nvalue: STR_PI\n',
])

finally:
# Remove the AVUs
self.user.run_icommand(['imeta', 'rm', '-C', self.user.session_collection, f'{avu_prefix}_0', "4"])
self.user.run_icommand(['imeta', 'rm', '-C', self.user.session_collection, f'{avu_prefix}_1', "*A"])
self.user.run_icommand(['imeta', 'rm', '-C', self.user.session_collection, f'{avu_prefix}_2', "INT_PI"])
self.user.run_icommand(['imeta', 'rm', '-C', self.user.session_collection, f'{avu_prefix}_3', "3"])
self.user.run_icommand(['imeta', 'rm', '-C', self.user.session_collection, f'{avu_prefix}_4', "0"])
self.user.run_icommand(['imeta', 'rm', '-C', self.user.session_collection, f'{avu_prefix}_5', "3.400000"])
self.user.run_icommand(['imeta', 'rm', '-C', self.user.session_collection, f'{avu_prefix}_6', "*B"])
self.user.run_icommand(['imeta', 'rm', '-C', self.user.session_collection, f'{avu_prefix}_7', "DOUBLE_PI"])
self.user.run_icommand(['imeta', 'rm', '-C', self.user.session_collection, f'{avu_prefix}_8', "potato"])
self.user.run_icommand(['imeta', 'rm', '-C', self.user.session_collection, f'{avu_prefix}_9', "*C"])
self.user.run_icommand(['imeta', 'rm', '-C', self.user.session_collection, f'{avu_prefix}_10', "STR_PI"])
92 changes: 91 additions & 1 deletion server/re/src/irods_re_serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1319,6 +1319,95 @@ namespace irods::re_serialization
}
}

static irods::error serialize_msParamArray_ptr_ptr(boost::any _p, serialized_parameter_t& _out)
{
try {
log_re::trace(__func__);
const auto* const* casted_ptr = boost::any_cast<msParamArray_t**>(_p);
if (!casted_ptr) {
_out["msParamArray_ptr_ptr"] = "nullptr";
return SUCCESS();
}
if (!*casted_ptr) {
_out["msParamArray_ptr"] = "nullptr";
return SUCCESS();
}
const auto* derefed_ptr = *casted_ptr;
_out["len"] = boost::lexical_cast<std::string>(derefed_ptr->len);
_out["oprType"] = boost::lexical_cast<std::string>(derefed_ptr->oprType);
for (int i = 0; i < derefed_ptr->len; i++) {
std::string prefix = std::to_string(i) + "_";
const auto* lbl = derefed_ptr->msParam[i]->label;
const auto* typ = derefed_ptr->msParam[i]->type;
_out[prefix + "label"] = lbl ? lbl : "nullptr";
_out[prefix + "type"] = typ ? typ : "nullptr";
const auto* msparam_ptr = derefed_ptr->msParam[i];

if (msparam_ptr == nullptr || msparam_ptr->inOutStruct == nullptr || !typ) {
_out[prefix + "inOutStruct"] = "nullptr";
}
else if (strcmp(msparam_ptr->type, STR_MS_T) == 0) {
_out[prefix + "inOutStruct"] = static_cast<char*>(msparam_ptr->inOutStruct);
}
else if (strcmp(msparam_ptr->type, INT_MS_T) == 0) {
_out[prefix + "inOutStruct"] = std::to_string(parseMspForPosInt(const_cast<MsParam*>(msparam_ptr)));
}
else if (strcmp(msparam_ptr->type, DOUBLE_MS_T) == 0) {
double out = 0.0;
if (parseMspForDouble(const_cast<MsParam*>(msparam_ptr), &out)) {
THROW(SYS_INVALID_INPUT_PARAM, "Failed to convert microservice argument to float.");
}
_out[prefix + "inOutStruct"] = std::to_string(out);
}
else if (strcmp(msparam_ptr->type, FLOAT_MS_T) == 0) {
float out = 0.0;
if (parseMspForFloat(const_cast<MsParam*>(msparam_ptr), &out)) {
THROW(SYS_INVALID_INPUT_PARAM, "Failed to convert microservice argument to float.");
}
_out[prefix + "inOutStruct"] = std::to_string(out);
}
else {
_out[prefix + "inOutStruct"] = fmt::format("unrepresentable_type_{}", msparam_ptr->type);
}

const auto* ptr = derefed_ptr->msParam[i]->inpOutBuf;
if (ptr) {
_out[prefix + "inpOutBuf_len"] = boost::lexical_cast<std::string>(ptr->len);
std::string& str = _out[prefix + "inpOutBuf_buf"];

for (int j = 0; j < ptr->len; j++) {
unsigned char c = *(static_cast<unsigned char*>(ptr->buf) + j);

if (isprint(c) || isspace(c)) {
str += c;
}
else {
str += fmt::format("\\x{0:02x}", c);
}
}
}
else {
_out[prefix + "null_value"] = "null_value";
}
}
return SUCCESS();
}
catch (const boost::bad_any_cast& e) {
return ERROR(INVALID_ANY_CAST,
fmt::format("{}: failed to cast pointer to [msParamArray_t**]: {}", __func__, e.what()));
}
catch (const irods::exception& e) {
return ERROR(
e.code(),
fmt::format(
"{}: failed to cast pointer to [msParamArray_t**]: {}, ec: {}", __func__, e.what(), e.code()));
}
catch (const std::exception& e) {
return ERROR(
SYS_LIBRARY_ERROR, fmt::format("{}: failed to serialize [msParamArray_t**]: {}", __func__, e.what()));
}
} // serialize_msParamArray_ptr_ptr

#if 0
static error serialize_XXXX_ptr(
boost::any _p,
Expand Down Expand Up @@ -1377,7 +1466,8 @@ namespace irods::re_serialization
{std::type_index(typeid(const std::vector<std::string>*)), serialize_const_vector_of_strings_ptr},
{std::type_index(typeid(std::vector<std::string>*)), serialize_vector_of_strings_ptr},
{std::type_index(typeid(execMyRuleInp_t*)), serialize_execMyRuleInp_ptr},
{std::type_index(typeid(structFileExtAndRegInp_t*)), serialize_structFileExtAndRegInp_ptr}};
{std::type_index(typeid(structFileExtAndRegInp_t*)), serialize_structFileExtAndRegInp_ptr},
{std::type_index(typeid(msParamArray_t**)), serialize_msParamArray_ptr_ptr}};
return the_map;

} // get_serialization_map
Expand Down

0 comments on commit cd6b746

Please sign in to comment.