Skip to content

Commit

Permalink
Fix enum sequence and struct sequence validation (#412)
Browse files Browse the repository at this point in the history
* Improve reporting and logging of errors
* Fix constraint validation of enum sequences and struct sequences
* Return NcMethosResultError instead of NcMethodResult

---------

Co-authored-by: Simon Lo <[email protected]>
  • Loading branch information
jonathan-r-thorpe and lo-simon authored Oct 14, 2024
1 parent 067b424 commit 7a264e9
Show file tree
Hide file tree
Showing 2 changed files with 158 additions and 137 deletions.
41 changes: 31 additions & 10 deletions Development/nmos/control_protocol_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace nmos
// unknown property
utility::stringstream_t ss;
ss << U("unknown property: ") << property_id.serialize() << U(" to do Get");
slog::log<slog::severities::error>(gate, SLOG_FLF) << ss.str();

Check warning on line 33 in Development/nmos/control_protocol_methods.cpp

View workflow job for this annotation

GitHub Actions / windows-2022: build and test (install mdns: false, use conan: true, force cpprest asio: true, dns-sd mode: multicast, enable_authorization: false)

nonstandard extension used: 'argument': conversion from 'slog::detail::`anonymous-namespace'::log<slog::base_gate,20>' to 'slog::log_statement &'

Check warning on line 33 in Development/nmos/control_protocol_methods.cpp

View workflow job for this annotation

GitHub Actions / windows-2019: build and test (install mdns: false, use conan: true, force cpprest asio: false, dns-sd mode: multicast, enable_authorization: true)

nonstandard extension used: 'argument': conversion from 'slog::detail::`anonymous-namespace'::log<slog::base_gate,20>' to 'slog::log_statement &'

Check warning on line 33 in Development/nmos/control_protocol_methods.cpp

View workflow job for this annotation

GitHub Actions / windows-2022: build and test (install mdns: false, use conan: true, force cpprest asio: true, dns-sd mode: multicast, enable_authorization: true)

nonstandard extension used: 'argument': conversion from 'slog::detail::`anonymous-namespace'::log<slog::base_gate,20>' to 'slog::log_statement &'
return details::make_nc_method_result_error({ nc_method_status::property_not_implemented }, ss.str());
}

Expand Down Expand Up @@ -82,15 +83,17 @@ namespace nmos
}
catch (const nmos::control_protocol_exception& e)
{
slog::log<slog::severities::error>(gate, SLOG_FLF) << "Set property: " << property_id.serialize() << " value: " << val.serialize() << " error: " << e.what();

return details::make_nc_method_result({ nc_method_status::parameter_error });
utility::stringstream_t ss;
ss << "Set property: " << property_id.serialize() << " value: " << val.serialize() << " error: " << e.what();
slog::log<slog::severities::error>(gate, SLOG_FLF) << ss.str();

Check warning on line 88 in Development/nmos/control_protocol_methods.cpp

View workflow job for this annotation

GitHub Actions / windows-2022: build and test (install mdns: false, use conan: true, force cpprest asio: true, dns-sd mode: multicast, enable_authorization: false)

nonstandard extension used: 'argument': conversion from 'slog::detail::`anonymous-namespace'::log<slog::base_gate,20>' to 'slog::log_statement &'

Check warning on line 88 in Development/nmos/control_protocol_methods.cpp

View workflow job for this annotation

GitHub Actions / windows-2019: build and test (install mdns: false, use conan: true, force cpprest asio: false, dns-sd mode: multicast, enable_authorization: true)

nonstandard extension used: 'argument': conversion from 'slog::detail::`anonymous-namespace'::log<slog::base_gate,20>' to 'slog::log_statement &'

Check warning on line 88 in Development/nmos/control_protocol_methods.cpp

View workflow job for this annotation

GitHub Actions / windows-2022: build and test (install mdns: false, use conan: true, force cpprest asio: true, dns-sd mode: multicast, enable_authorization: true)

nonstandard extension used: 'argument': conversion from 'slog::detail::`anonymous-namespace'::log<slog::base_gate,20>' to 'slog::log_statement &'
return details::make_nc_method_result_error({ nc_method_status::parameter_error }, ss.str());
}
}

// unknown property
utility::stringstream_t ss;
ss << U("unknown property: ") << property_id.serialize() << " to do Set";
slog::log<slog::severities::error>(gate, SLOG_FLF) << ss.str();

Check warning on line 96 in Development/nmos/control_protocol_methods.cpp

View workflow job for this annotation

GitHub Actions / windows-2022: build and test (install mdns: false, use conan: true, force cpprest asio: true, dns-sd mode: multicast, enable_authorization: false)

nonstandard extension used: 'argument': conversion from 'slog::detail::`anonymous-namespace'::log<slog::base_gate,20>' to 'slog::log_statement &'

Check warning on line 96 in Development/nmos/control_protocol_methods.cpp

View workflow job for this annotation

GitHub Actions / windows-2019: build and test (install mdns: false, use conan: true, force cpprest asio: false, dns-sd mode: multicast, enable_authorization: true)

nonstandard extension used: 'argument': conversion from 'slog::detail::`anonymous-namespace'::log<slog::base_gate,20>' to 'slog::log_statement &'

Check warning on line 96 in Development/nmos/control_protocol_methods.cpp

View workflow job for this annotation

GitHub Actions / windows-2022: build and test (install mdns: false, use conan: true, force cpprest asio: true, dns-sd mode: multicast, enable_authorization: true)

nonstandard extension used: 'argument': conversion from 'slog::detail::`anonymous-namespace'::log<slog::base_gate,20>' to 'slog::log_statement &'
return details::make_nc_method_result_error({ nc_method_status::property_not_implemented }, ss.str());
}

Expand Down Expand Up @@ -126,12 +129,14 @@ namespace nmos
// out of bound
utility::stringstream_t ss;
ss << U("property: ") << property_id.serialize() << U(" is outside the available range to do GetSequenceItem");
slog::log<slog::severities::error>(gate, SLOG_FLF) << ss.str();

Check warning on line 132 in Development/nmos/control_protocol_methods.cpp

View workflow job for this annotation

GitHub Actions / windows-2022: build and test (install mdns: false, use conan: true, force cpprest asio: true, dns-sd mode: multicast, enable_authorization: false)

nonstandard extension used: 'argument': conversion from 'slog::detail::`anonymous-namespace'::log<slog::base_gate,20>' to 'slog::log_statement &'

Check warning on line 132 in Development/nmos/control_protocol_methods.cpp

View workflow job for this annotation

GitHub Actions / windows-2019: build and test (install mdns: false, use conan: true, force cpprest asio: false, dns-sd mode: multicast, enable_authorization: true)

nonstandard extension used: 'argument': conversion from 'slog::detail::`anonymous-namespace'::log<slog::base_gate,20>' to 'slog::log_statement &'

Check warning on line 132 in Development/nmos/control_protocol_methods.cpp

View workflow job for this annotation

GitHub Actions / windows-2022: build and test (install mdns: false, use conan: true, force cpprest asio: true, dns-sd mode: multicast, enable_authorization: true)

nonstandard extension used: 'argument': conversion from 'slog::detail::`anonymous-namespace'::log<slog::base_gate,20>' to 'slog::log_statement &'
return details::make_nc_method_result_error({ nc_method_status::index_out_of_bounds }, ss.str());
}

// unknown property
utility::stringstream_t ss;
ss << U("unknown property: ") << property_id.serialize() << U(" to do GetSequenceItem");
slog::log<slog::severities::error>(gate, SLOG_FLF) << ss.str();

Check warning on line 139 in Development/nmos/control_protocol_methods.cpp

View workflow job for this annotation

GitHub Actions / windows-2022: build and test (install mdns: false, use conan: true, force cpprest asio: true, dns-sd mode: multicast, enable_authorization: false)

nonstandard extension used: 'argument': conversion from 'slog::detail::`anonymous-namespace'::log<slog::base_gate,20>' to 'slog::log_statement &'

Check warning on line 139 in Development/nmos/control_protocol_methods.cpp

View workflow job for this annotation

GitHub Actions / windows-2019: build and test (install mdns: false, use conan: true, force cpprest asio: false, dns-sd mode: multicast, enable_authorization: true)

nonstandard extension used: 'argument': conversion from 'slog::detail::`anonymous-namespace'::log<slog::base_gate,20>' to 'slog::log_statement &'

Check warning on line 139 in Development/nmos/control_protocol_methods.cpp

View workflow job for this annotation

GitHub Actions / windows-2022: build and test (install mdns: false, use conan: true, force cpprest asio: true, dns-sd mode: multicast, enable_authorization: true)

nonstandard extension used: 'argument': conversion from 'slog::detail::`anonymous-namespace'::log<slog::base_gate,20>' to 'slog::log_statement &'
return details::make_nc_method_result_error({ nc_method_status::property_not_implemented }, ss.str());
}

Expand Down Expand Up @@ -163,6 +168,7 @@ namespace nmos
// property is not a sequence
utility::stringstream_t ss;
ss << U("property: ") << property_id.serialize() << U(" is not a sequence to do SetSequenceItem");
slog::log<slog::severities::error>(gate, SLOG_FLF) << ss.str();

Check warning on line 171 in Development/nmos/control_protocol_methods.cpp

View workflow job for this annotation

GitHub Actions / windows-2022: build and test (install mdns: false, use conan: true, force cpprest asio: true, dns-sd mode: multicast, enable_authorization: false)

nonstandard extension used: 'argument': conversion from 'slog::detail::`anonymous-namespace'::log<slog::base_gate,20>' to 'slog::log_statement &'

Check warning on line 171 in Development/nmos/control_protocol_methods.cpp

View workflow job for this annotation

GitHub Actions / windows-2019: build and test (install mdns: false, use conan: true, force cpprest asio: false, dns-sd mode: multicast, enable_authorization: true)

nonstandard extension used: 'argument': conversion from 'slog::detail::`anonymous-namespace'::log<slog::base_gate,20>' to 'slog::log_statement &'

Check warning on line 171 in Development/nmos/control_protocol_methods.cpp

View workflow job for this annotation

GitHub Actions / windows-2022: build and test (install mdns: false, use conan: true, force cpprest asio: true, dns-sd mode: multicast, enable_authorization: true)

nonstandard extension used: 'argument': conversion from 'slog::detail::`anonymous-namespace'::log<slog::base_gate,20>' to 'slog::log_statement &'
return details::make_nc_method_result_error({ nc_method_status::invalid_request }, ss.str());
}

Expand Down Expand Up @@ -190,21 +196,24 @@ namespace nmos
}
catch (const nmos::control_protocol_exception& e)
{
slog::log<slog::severities::error>(gate, SLOG_FLF) << "Set sequence item: " << property_id.serialize() << " index: " << index << " value: " << val.serialize() << " error: " << e.what();

return details::make_nc_method_result({ nc_method_status::parameter_error });
utility::stringstream_t ss;
ss << "Set sequence item: " << property_id.serialize() << " index: " << index << " value: " << val.serialize() << " error: " << e.what();
slog::log<slog::severities::error>(gate, SLOG_FLF) << ss.str();

Check warning on line 201 in Development/nmos/control_protocol_methods.cpp

View workflow job for this annotation

GitHub Actions / windows-2022: build and test (install mdns: false, use conan: true, force cpprest asio: true, dns-sd mode: multicast, enable_authorization: false)

nonstandard extension used: 'argument': conversion from 'slog::detail::`anonymous-namespace'::log<slog::base_gate,20>' to 'slog::log_statement &'

Check warning on line 201 in Development/nmos/control_protocol_methods.cpp

View workflow job for this annotation

GitHub Actions / windows-2019: build and test (install mdns: false, use conan: true, force cpprest asio: false, dns-sd mode: multicast, enable_authorization: true)

nonstandard extension used: 'argument': conversion from 'slog::detail::`anonymous-namespace'::log<slog::base_gate,20>' to 'slog::log_statement &'

Check warning on line 201 in Development/nmos/control_protocol_methods.cpp

View workflow job for this annotation

GitHub Actions / windows-2022: build and test (install mdns: false, use conan: true, force cpprest asio: true, dns-sd mode: multicast, enable_authorization: true)

nonstandard extension used: 'argument': conversion from 'slog::detail::`anonymous-namespace'::log<slog::base_gate,20>' to 'slog::log_statement &'
return details::make_nc_method_result_error({ nc_method_status::parameter_error }, ss.str());
}
}

// out of bound
utility::stringstream_t ss;
ss << U("property: ") << property_id.serialize() << U(" is outside the available range to do SetSequenceItem");
slog::log<slog::severities::error>(gate, SLOG_FLF) << ss.str();

Check warning on line 209 in Development/nmos/control_protocol_methods.cpp

View workflow job for this annotation

GitHub Actions / windows-2022: build and test (install mdns: false, use conan: true, force cpprest asio: true, dns-sd mode: multicast, enable_authorization: false)

nonstandard extension used: 'argument': conversion from 'slog::detail::`anonymous-namespace'::log<slog::base_gate,20>' to 'slog::log_statement &'

Check warning on line 209 in Development/nmos/control_protocol_methods.cpp

View workflow job for this annotation

GitHub Actions / windows-2019: build and test (install mdns: false, use conan: true, force cpprest asio: false, dns-sd mode: multicast, enable_authorization: true)

nonstandard extension used: 'argument': conversion from 'slog::detail::`anonymous-namespace'::log<slog::base_gate,20>' to 'slog::log_statement &'

Check warning on line 209 in Development/nmos/control_protocol_methods.cpp

View workflow job for this annotation

GitHub Actions / windows-2022: build and test (install mdns: false, use conan: true, force cpprest asio: true, dns-sd mode: multicast, enable_authorization: true)

nonstandard extension used: 'argument': conversion from 'slog::detail::`anonymous-namespace'::log<slog::base_gate,20>' to 'slog::log_statement &'
return details::make_nc_method_result_error({ nc_method_status::index_out_of_bounds }, ss.str());
}

// unknown property
utility::stringstream_t ss;
ss << U("unknown property: ") << property_id.serialize() << U(" to do SetSequenceItem");
slog::log<slog::severities::error>(gate, SLOG_FLF) << ss.str();

Check warning on line 216 in Development/nmos/control_protocol_methods.cpp

View workflow job for this annotation

GitHub Actions / windows-2022: build and test (install mdns: false, use conan: true, force cpprest asio: true, dns-sd mode: multicast, enable_authorization: false)

nonstandard extension used: 'argument': conversion from 'slog::detail::`anonymous-namespace'::log<slog::base_gate,20>' to 'slog::log_statement &'

Check warning on line 216 in Development/nmos/control_protocol_methods.cpp

View workflow job for this annotation

GitHub Actions / windows-2019: build and test (install mdns: false, use conan: true, force cpprest asio: false, dns-sd mode: multicast, enable_authorization: true)

nonstandard extension used: 'argument': conversion from 'slog::detail::`anonymous-namespace'::log<slog::base_gate,20>' to 'slog::log_statement &'

Check warning on line 216 in Development/nmos/control_protocol_methods.cpp

View workflow job for this annotation

GitHub Actions / windows-2022: build and test (install mdns: false, use conan: true, force cpprest asio: true, dns-sd mode: multicast, enable_authorization: true)

nonstandard extension used: 'argument': conversion from 'slog::detail::`anonymous-namespace'::log<slog::base_gate,20>' to 'slog::log_statement &'
return details::make_nc_method_result_error({ nc_method_status::property_not_implemented }, ss.str());
}

Expand Down Expand Up @@ -266,15 +275,17 @@ namespace nmos
}
catch (const nmos::control_protocol_exception& e)
{
slog::log<slog::severities::error>(gate, SLOG_FLF) << "Add sequence item: " << property_id.serialize() << " value: " << val.serialize() << " error: " << e.what();

return details::make_nc_method_result({ nc_method_status::parameter_error });
utility::stringstream_t ss;
ss << "Add sequence item: " << property_id.serialize() << " value: " << val.serialize() << " error: " << e.what();
slog::log<slog::severities::error>(gate, SLOG_FLF) << ss.str();

Check warning on line 280 in Development/nmos/control_protocol_methods.cpp

View workflow job for this annotation

GitHub Actions / windows-2022: build and test (install mdns: false, use conan: true, force cpprest asio: true, dns-sd mode: multicast, enable_authorization: false)

nonstandard extension used: 'argument': conversion from 'slog::detail::`anonymous-namespace'::log<slog::base_gate,20>' to 'slog::log_statement &'

Check warning on line 280 in Development/nmos/control_protocol_methods.cpp

View workflow job for this annotation

GitHub Actions / windows-2019: build and test (install mdns: false, use conan: true, force cpprest asio: false, dns-sd mode: multicast, enable_authorization: true)

nonstandard extension used: 'argument': conversion from 'slog::detail::`anonymous-namespace'::log<slog::base_gate,20>' to 'slog::log_statement &'

Check warning on line 280 in Development/nmos/control_protocol_methods.cpp

View workflow job for this annotation

GitHub Actions / windows-2022: build and test (install mdns: false, use conan: true, force cpprest asio: true, dns-sd mode: multicast, enable_authorization: true)

nonstandard extension used: 'argument': conversion from 'slog::detail::`anonymous-namespace'::log<slog::base_gate,20>' to 'slog::log_statement &'
return details::make_nc_method_result_error({ nc_method_status::parameter_error }, ss.str());
}
}

// unknown property
utility::stringstream_t ss;
ss << U("unknown property: ") << property_id.serialize() << U(" to do AddSequenceItem");
slog::log<slog::severities::error>(gate, SLOG_FLF) << ss.str();
return details::make_nc_method_result_error({ nc_method_status::property_not_implemented }, ss.str());
}

Expand All @@ -299,6 +310,7 @@ namespace nmos
// property is not a sequence
utility::stringstream_t ss;
ss << U("property: ") << property_id.serialize() << U(" is not a sequence to do RemoveSequenceItem");
slog::log<slog::severities::error>(gate, SLOG_FLF) << ss.str();
return details::make_nc_method_result_error({ nc_method_status::invalid_request }, ss.str());
}

Expand All @@ -317,12 +329,14 @@ namespace nmos
// out of bound
utility::stringstream_t ss;
ss << U("property: ") << property_id.serialize() << U(" is outside the available range to do RemoveSequenceItem");
slog::log<slog::severities::error>(gate, SLOG_FLF) << ss.str();
return details::make_nc_method_result_error({ nc_method_status::index_out_of_bounds }, ss.str());
}

// unknown property
utility::stringstream_t ss;
ss << U("unknown property: ") << property_id.serialize() << U(" to do RemoveSequenceItem");
slog::log<slog::severities::error>(gate, SLOG_FLF) << ss.str();
return details::make_nc_method_result_error({ nc_method_status::property_not_implemented }, ss.str());
}

Expand All @@ -346,6 +360,7 @@ namespace nmos
// property is not a sequence
utility::stringstream_t ss;
ss << U("property: ") << property_id.serialize() << U(" is not a sequence to do GetSequenceLength");
slog::log<slog::severities::error>(gate, SLOG_FLF) << ss.str();
return details::make_nc_method_result_error({ nc_method_status::invalid_request }, ss.str());
}

Expand All @@ -368,6 +383,7 @@ namespace nmos
// null
utility::stringstream_t ss;
ss << U("property: ") << property_id.serialize() << " is a null sequence to do GetSequenceLength";
slog::log<slog::severities::error>(gate, SLOG_FLF) << ss.str();
return details::make_nc_method_result_error({ nc_method_status::invalid_request }, ss.str());
}
}
Expand All @@ -377,6 +393,7 @@ namespace nmos
// unknown property
utility::stringstream_t ss;
ss << U("unknown property: ") << property_id.serialize() << " to do GetSequenceLength";
slog::log<slog::severities::error>(gate, SLOG_FLF) << ss.str();
return details::make_nc_method_result_error({ nc_method_status::property_not_implemented }, ss.str());
}

Expand Down Expand Up @@ -444,13 +461,17 @@ namespace nmos
// no role
utility::stringstream_t ss;
ss << U("role: ") << role.as_string() << U(" not found to do FindMembersByPath");
slog::log<slog::severities::error>(gate, SLOG_FLF) << ss.str();
return details::make_nc_method_result_error({ nc_method_status::parameter_error }, ss.str());
}
}
else
{
// no members
return details::make_nc_method_result_error({ nc_method_status::parameter_error }, U("no members to do FindMembersByPath"));
utility::stringstream_t ss;
ss << U("role: ") << role.as_string() << U(" has no members to do FindMembersByPath");
slog::log<slog::severities::error>(gate, SLOG_FLF) << ss.str();
return details::make_nc_method_result_error({ nc_method_status::parameter_error }, ss.str());
}
}

Expand Down
Loading

0 comments on commit 7a264e9

Please sign in to comment.