}
}
+namespace print_content {
+static bool xml_format = false;
+void use_xml_format(const bool xml) {
+ xml_format = xml;
+}
+}
+
template <typename T>
std::ostream &print_val(std::ostream &stream, const boost::string_ref &name, const T &val) {
return stream << name << "(" << val << ")";
const boost::string_ref &member,
const boost::string_ref &path,
ldp_xml_parser::MessageType type,
- const ldp_xml_parser::DecisionItem &decisionItem)
+ const ldp_xml_parser::DecisionItem &decisionItem,
+ const bool is_prefix)
{
stream << item_type << ": ";
- print_val(stream, "name", name);
+ if (is_prefix)
+ print_val(stream, "name_prefix", name);
+ else
+ print_val(stream, "name", name);
print_next_val(stream, "inter", interface);
print_next_val(stream, "member", member);
print_next_val(stream, "path", path);
return print_next_val(stream, "decision", decisionItem);
}
+std::ostream &print_content_item_sr_xml(std::ostream &stream,
+ const boost::string_ref &item_type,
+ const boost::string_ref &name,
+ const boost::string_ref &interface,
+ const boost::string_ref &member,
+ const boost::string_ref &path,
+ ldp_xml_parser::MessageType type,
+ const ldp_xml_parser::DecisionItem &decisionItem,
+ const bool is_prefix)
+{
+ const char *strDecision[] = {"any", "allow", "deny", "check"};
+ const char *sr;
+ std::string type_str;
+
+ if (item_type == "ItemSend")
+ sr = "send";
+ else
+ sr = "receive";
+
+ stream << "<" << strDecision[static_cast<std::size_t>(decisionItem.getDecision())] << " ";
+ if (is_prefix)
+ stream << sr << "_destination_prefix=\"" << name << "\" ";
+ else if (!name.empty())
+ stream << sr << "_" << (item_type == "ItemSend" ? "destination" : "sender") << "=\"" << name << "\" ";
+
+ if (!path.empty())
+ stream << sr << "_" << "path=\"" << path << "\" ";
+ if (!interface.empty())
+ stream << sr << "_" << "interface=\"" << interface << "\" ";
+ if (!member.empty())
+ stream << sr << "_" << "member=\"" << member << "\" ";
+ if (!decisionItem.getPrivilege().empty())
+ stream << sr << "_" << "privilege=\"" << decisionItem.getPrivilege() << "\" ";
+
+ type_str = __message_type_to_str(type);
+ std::transform(type_str.begin(), type_str.end(), type_str.begin(), [](unsigned char c){ return std::tolower(c); });
+
+ if (type_str != "any")
+ stream << sr << "_" << "type=\"" << type_str << "\" ";
+
+ return stream << "/>";
+}
+
namespace {
static const char* message_decision[] = {"NO_DECISION", "ALLOW", "DENY", "CHECK"};
static inline const char* __decision_to_str(ldp_xml_parser::Decision dec) {
template <typename T>
void printContentItemSR(std::ostream &stream, const boost::string_ref &item_type, const T *item) {
- print_content_item_sr(stream, item_type, item->name()->c_str(), item->interface()->c_str(),
+ auto print_func = (print_content::xml_format ? print_content_item_sr_xml : print_content_item_sr);
+ print_func(stream, item_type, item->name()->c_str(), item->interface()->c_str(),
item->member()->c_str(), item->path()->c_str(), makeMessageType(item->type()),
- makeDecisionItem(item->decision()));
+ makeDecisionItem(item->decision()), item->is_name_prefix());
}
template <> void printContentItem(std::ostream &stream, const FB::ItemSend *item) {
}
std::ostream &operator<<(std::ostream &stream, const ldp_xml_parser::ItemSend &item) {
- return print_content_item_sr(stream, "ItemSend", item.getName(), item.getInterface(), item.getMember(),
- item.getPath(), item.getType(), item.getDecision());
+ auto print_func = (print_content::xml_format ? print_content_item_sr_xml : print_content_item_sr);
+ return print_func(stream, "ItemSend", item.getName(), item.getInterface(), item.getMember(),
+ item.getPath(), item.getType(), item.getDecision(), item.isNamePrefix());
}
std::ostream &operator<<(std::ostream &stream, const ldp_xml_parser::ItemReceive &item) {
- return print_content_item_sr(stream, "ItemReceive", item.getName(), item.getInterface(), item.getMember(),
- item.getPath(), item.getType(), item.getDecision());
+ auto print_func = (print_content::xml_format ? print_content_item_sr_xml : print_content_item_sr);
+ return print_func(stream, "ItemReceive", item.getName(), item.getInterface(), item.getMember(),
+ item.getPath(), item.getType(), item.getDecision(), item.isNamePrefix());
}
std::ostream &operator<<(std::ostream &stream, const ldp_xml_parser::ItemAccess &item) {