diff options
author | Adrian Szyndela <adrian.s@samsung.com> | 2020-04-09 12:38:40 +0200 |
---|---|---|
committer | Adrian Szyndela <adrian.s@samsung.com> | 2020-04-09 12:38:40 +0200 |
commit | 434396148108ae1dad3215ed696e984b9930caaf (patch) | |
tree | 6f244fdda211265b86eabe66ea5f26ce0c44dce8 | |
parent | 0821d6ca80fe71fdc251580c56cbe4595f6a84f3 (diff) | |
download | libdbuspolicy-434396148108ae1dad3215ed696e984b9930caaf.tar.gz libdbuspolicy-434396148108ae1dad3215ed696e984b9930caaf.tar.bz2 libdbuspolicy-434396148108ae1dad3215ed696e984b9930caaf.zip |
finder: improve printingtizen_6.0.m2_releasesubmit/tizen_6.0_hotfix/20201103.114804submit/tizen_6.0_hotfix/20201102.192504submit/tizen_6.0/20201029.205104submit/tizen/20200427.012135accepted/tizen/unified/20200428.001342accepted/tizen/6.0/unified/hotfix/20201103.003414accepted/tizen/6.0/unified/20201030.115601tizen_6.0_hotfixaccepted/tizen_6.0_unified_hotfix
Add actual attribute names to printing instead of printing just "send"
or "receive".
Change-Id: Ib117847d44a57abbf1fd1217a786c1d2d8b5d218
-rw-r--r-- | src/dbuspolicy_finder.cpp | 65 |
1 files changed, 35 insertions, 30 deletions
diff --git a/src/dbuspolicy_finder.cpp b/src/dbuspolicy_finder.cpp index f22e4cd..a8edb68 100644 --- a/src/dbuspolicy_finder.cpp +++ b/src/dbuspolicy_finder.cpp @@ -77,43 +77,48 @@ MessageType stringToMessageType(std::string tmp) { } } -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 << '*'; @@ -273,7 +278,7 @@ template <typename T> void handlePolicy(const std::string & interface, const std 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" |