finder: improve printing 42/230342/1 accepted/tizen_6.0_unified_hotfix tizen_6.0_hotfix accepted/tizen/6.0/unified/20201030.115601 accepted/tizen/6.0/unified/hotfix/20201103.003414 accepted/tizen/unified/20200428.001342 submit/tizen/20200427.012135 submit/tizen_6.0/20201029.205104 submit/tizen_6.0_hotfix/20201102.192504 submit/tizen_6.0_hotfix/20201103.114804 tizen_6.0.m2_release
authorAdrian Szyndela <adrian.s@samsung.com>
Thu, 9 Apr 2020 10:38:40 +0000 (12:38 +0200)
committerAdrian Szyndela <adrian.s@samsung.com>
Thu, 9 Apr 2020 10:38:40 +0000 (12:38 +0200)
Add actual attribute names to printing instead of printing just "send"
or "receive".

Change-Id: Ib117847d44a57abbf1fd1217a786c1d2d8b5d218

src/dbuspolicy_finder.cpp

index f22e4cd..a8edb68 100644 (file)
@@ -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"