summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Szyndela <adrian.s@samsung.com>2020-04-09 12:38:40 +0200
committerAdrian Szyndela <adrian.s@samsung.com>2020-04-09 12:38:40 +0200
commit434396148108ae1dad3215ed696e984b9930caaf (patch)
tree6f244fdda211265b86eabe66ea5f26ce0c44dce8
parent0821d6ca80fe71fdc251580c56cbe4595f6a84f3 (diff)
downloadlibdbuspolicy-434396148108ae1dad3215ed696e984b9930caaf.tar.gz
libdbuspolicy-434396148108ae1dad3215ed696e984b9930caaf.tar.bz2
libdbuspolicy-434396148108ae1dad3215ed696e984b9930caaf.zip
Add actual attribute names to printing instead of printing just "send" or "receive". Change-Id: Ib117847d44a57abbf1fd1217a786c1d2d8b5d218
-rw-r--r--src/dbuspolicy_finder.cpp65
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"