}
}
-std::pair <std::string, std::string> getItemStrings (const ItemSend &) {
- return std::make_pair ("send", "send_destination");
+std::string getPrefix(const ItemSend &) {
+ return "send_";
}
-std::pair <std::string, std::string> getItemStrings (const ItemReceive &) {
- return std::make_pair ("receive", "receive_sender");
+
+std::string getPrefix(const ItemReceive &) {
+ return "receive_";
+}
+
+std::string getNameAttr(const ItemSend &) {
+ return "destination";
+}
+
+std::string getNameAttr(const ItemReceive &) {
+ return "sender";
}
template <typename T> void printDecision(const T & item) {
bool everything_is_null = true;
- const auto strings = getItemStrings(item);
+ const auto prefix = getPrefix(item);
+
+ auto printAttribute = [&everything_is_null, &prefix](const std::string &attr_name, const std::string &attr_value) {
+ if (!attr_value.empty()) {
+ std::cout << " " << prefix << attr_name << "=\"" << attr_value << "\"";
+ everything_is_null = false;
+ }
+ };
+
+ printAttribute("interface", item.getInterface());
+ printAttribute("member", item.getMember());
+ printAttribute("path", item.getPath());
+
+ const auto nameAttr = getNameAttr(item);
+ if (!item.isNamePrefix())
+ printAttribute(nameAttr, item.getName());
+ else
+ printAttribute(nameAttr + "_prefix", item.getName());
- if (!item.getInterface().empty()) {
- everything_is_null = false;
- std::cout << " " << strings.first << "=\"" << item.getInterface() << "\"";
- }
- if (!item.getMember().empty()) {
- everything_is_null = false;
- std::cout << " " << strings.first << "=\"" << item.getMember() << "\"";
- }
- if (!item.getPath().empty()) {
- everything_is_null = false;
- std::cout << " " << strings.first << "=\"" << item.getPath() << "\"";
- }
- if (!item.getName().empty()) {
- everything_is_null = false;
- std::cout << " " << strings.first << "=\"" << item.getName() << "\"";
- }
- if (!item.getName().empty() && item.isNamePrefix()) {
- everything_is_null = false;
- std::cout << " " << strings.second << "=\"" << item.getName() << "\"";
- }
const auto type_it = std::find_if(types.begin(), types.end(), [&item] (const decltype(types)::value_type & type) { return type.second == item.getType(); } );
- if (type_it != types.end()) {
- everything_is_null = false;
- std::cout << " type=\"" << type_it->first << "\"";
- }
+ if (type_it != types.end())
+ printAttribute("type", type_it->first);
+
if (everything_is_null)
std::cout << '*';
int showHelp() {
std::cout << "\nUsage:\n"
- "dbuspolicy-filter {send|receive|access|own} [options]\n"
+ "dbuspolicy-finder {send|receive|access|own} [options]\n"
"\n"
" -c, --configuration {file name} | --session | --system\n"
" -e, --explain \tread an error message from standard input and find relevant policy rules\n"