The logs take relatively large space within actual source code.
This makes them smaller to help with avoiding distraction.
Change-Id: Iafca91f5e30f4446e28215cafbf78325ac9287bd
static void __log_item(const MatchItemSR& item)
{
- char tmp[MAX_LOG_LINE];
- const char* i_str = item.toString(tmp);
- std::cout << "checkpolicy for: " << i_str <<std::endl;
+ std::cout << "checkpolicy for: " << item << std::endl;
}
}
for (auto i : policy) {
if (tslog::verbose()) {
- char tmp[MAX_LOG_LINE];
- const char* i_str = i->getDecision().toString(tmp);
- std::cout << "-read: " << i_str;
- i_str = i->toString(tmp);
- std::cout << " " << i_str <<std::endl;
+ std::cout << "-read: " << i->getDecision() << " " << i << std::endl;
}
if (i->match(item)) {
if (tslog::verbose()) {
- char tmp[MAX_LOG_LINE];
- const char* i_str = i->getDecision().toString(tmp);
- std::cout << "-matched: " << i_str;
- const char* i_str2 = i->toString(tmp);
- std::cout << " " << i_str2 <<std::endl;
+ std::cout << "-matched: " << i->getDecision() << " " << i << std::endl;
}
return i->getDecision();
}
template<typename T>
void log_item_add(const T* item) {
if (tslog::enabled()) {
- char tmp[MAX_LOG_LINE];
- const char* i_str = item->toString(tmp);
- char tmp2[MAX_LOG_LINE];
- const char* d_str = item->getDecision().toString(tmp2);
- std::cout << "Add item: " << i_str << ", decision: " << d_str << std::endl;
+ std::cout << "Add item: " << item << ", decision: " << item->getDecision() << std::endl;
}
}
}
void NaivePolicyDb::PolicySR::printContent() const {
- char str[MAX_LOG_LINE];
- for (const auto& i : m_items) {
- i->toString(str);
- std::cerr << str << std::endl;
- }
+ for (const auto& i : m_items)
+ std::cerr << i << std::endl;
}
void NaivePolicyDb::PolicyOwn::addItem(ItemOwn* item) {
}
void NaivePolicyDb::PolicyAccess::printContent() const {
- char str[MAX_LOG_LINE];
- for (const auto& i : m_items) {
- i.toString(str);
- std::cerr << str << std::endl;
- }
+ for (const auto& i : m_items)
+ std::cerr << i << std::endl;
}
template<typename S, typename T>
void OwnershipTree::printTreeLevel(const TreeNode& node, const std::string& indent) const
{
- char str[MAX_LOG_LINE];
-
std::cerr << indent << "| " << node.__token << " (" << node.__children.size() << ") | "
- << node.__own_decision_item.toString(str) << " " << node.__own_prefix_decision_item.toString(str) << std::endl;
+ << node.__own_decision_item << " " << node.__own_prefix_decision_item << std::endl;
for (const auto& i : node.__children)
printTreeLevel(*i.second, indent + "\t");
return ItemType::GENERIC;
}
-const char* DecisionItem::toString(char* str) const {
- snprintf(str, MAX_LOG_LINE, "%s%s%s", __decision_to_str(__decision), __privilege == "" ? "" : ":", __privilege.c_str());
- return str;
-}
-
size_t DecisionItem::getSize() const {
return get_string_heap_allocated_memory(__privilege);
}
return ItemType::OWN;
}
-const char* ItemOwn::toString(char* str) const {
- snprintf(str, MAX_LOG_LINE, "ItemOwn: service(%s), pref(%d)", __name == "" ? "*" : __name.c_str(), __is_prefix);
- return str;
-}
-
const char* ItemOwn::getName() const {
if (__name == "") {
return nullptr;
__direction(direction) {
}
-const char* ItemSendReceive::toString(char* str) const {
- snprintf(str, MAX_LOG_LINE, "ItemSR: name(%s), inter(%s), member(%s), path(%s), type(%s), dir(%s)", __name.name, __interface, __member, __path, __message_type_to_str(__type), __message_dir_to_str(__direction));
- return str;
-}
-
ItemSendReceive::~ItemSendReceive() {
delete[] __interface;
delete[] __member;
return false;
}
-const char* ItemAccess::toString(char* str) const
-{
- snprintf(str, MAX_LOG_LINE, "ItemAccess: type(%s), uid(%d), gid(%d)", __access_type_to_str(__type), __uid, __gid);
- return str;
-}
-
size_t ItemAccess::getSize() const
{
return __decision.getSize();
sr->__is_name_prefix = prefix;
}
-const char* MatchItemSR::toString(char* str) const {
- char tmp[MAX_LOG_LINE];
- tmp[0] = 0;
- for (int i = 0; i < names_num; i++) {
- std::strncat(tmp, names[i].name, sizeof(tmp) - strlen(tmp) - 1);
- std::strncat(tmp, " ", sizeof(tmp) - strlen(tmp) - 1);
- }
- snprintf(str, MAX_LOG_LINE, "matcher: services(%s), interface(%s), member(%s), path(%s), type(%s), direction(%s)", tmp, interface, member, path, __message_type_to_str(type), __message_dir_to_str(direction) );
- return str;
-}
-
void ItemBuilder::addInterface(const char* interface) {
ItemSendReceive* sr = getSendReceiveItem();
sr->__interface = duplicate(interface);
PolicyTypeValue::PolicyTypeValue(uid_t us) : user(us) {
}
+
+namespace ldp_xml_parser {
+
+std::ostream &operator<<(std::ostream& stream, const DecisionItem &di)
+{
+ return stream << __decision_to_str(di.__decision) << (di.__privilege.empty() ? "" : ":") << di.__privilege;
+}
+
+std::ostream &operator<<(std::ostream& stream, const ItemOwn &item)
+{
+ return stream << "ItemOwn: service(" << (item.__name.empty() ? "*" : item.__name) <<
+ "), pref(" << item.__is_prefix << ")";
+}
+
+std::ostream &operator<<(std::ostream& stream, const MatchItemSR &item)
+{
+ stream << "matcher: services(";
+ for (int i = 0; i < item.names_num; i++) {
+ stream << item.names[i].name;
+ if (i != item.names_num -1)
+ stream << " ";
+ }
+ return stream << "), interface(" << item.interface << "), member(" << item.member <<
+ "), path(" << item.path << "), type(" << __message_type_to_str(item.type) << "), direction(" <<
+ __message_dir_to_str(item.direction) << ")";
+}
+
+std::ostream &operator<<(std::ostream& stream, const ItemSendReceive &item)
+{
+ return stream << "ItemSR: name(" << item.__name.name << "), inter(" << item.__interface <<
+ "), member(" << item.__member << "), path(" << item.__path << "), type(" <<
+ __message_type_to_str(item.__type) << "), dir(" << __message_dir_to_str(item.__direction) << ")";
+}
+
+std::ostream &operator<<(std::ostream& stream, const ItemAccess &item)
+{
+ return stream << "ItemAccess: type(" << __access_type_to_str(item.__type) << "), uid(" <<
+ item.__uid << "), gid(" << item.__gid << ")";
+}
+
+}
#include <string>
#include <vector>
-#define MAX_LOG_LINE 1024
/** Maximum tree node children. It is connected with proper characters which can be used in name.*/
#define MAX_CHILDREN 65
Decision getDecision() const;
const char* getPrivilege() const;
ItemType getType() const;
- const char* toString(char* str) const;
size_t getSize() const;
+
+ friend std::ostream &operator<<(std::ostream& stream, const DecisionItem &di);
};
+ std::ostream &operator<<(std::ostream& stream, const DecisionItem &di);
/** Class contains info about ownership policy item */
class ItemOwn {
const char* privilege = NULL);
bool match(const char* const name) const;
ItemType getType() const;
- const char* toString(char* str) const;
const DecisionItem& getDecision() const;
const char* getName() const;
bool isPrefix() const;
bool isMatchAll() const;
+
+ friend std::ostream &operator<<(std::ostream& stream, const ItemOwn &item);
};
+ std::ostream &operator<<(std::ostream& stream, const ItemOwn &item);
/** Name structure for send/receive policy */
struct NameSR {
MatchItemSR(const char* i = NULL, const char* me = NULL, const char* p = NULL, MessageType t = MessageType::ANY, MessageDirection d = MessageDirection::ANY);
void addName(const char* name);
bool addNames(const char* name);
- const char* toString(char* str) const;
+
+ friend std::ostream &operator<<(std::ostream& stream, const MatchItemSR &item);
};
+ std::ostream &operator<<(std::ostream& stream, const MatchItemSR &item);
/** Class contains info about item send/receive */
class ItemSendReceive {
bool match(const MatchItemSR& item) const;
MessageDirection getDirection() const;
ItemType getType() const;
- const char* toString(char* str) const;
const DecisionItem& getDecision() const;
size_t getSize() const;
+
+ friend std::ostream &operator<<(std::ostream& stream, const ItemSendReceive &item);
};
+ std::ostream &operator<<(std::ostream& stream, const ItemSendReceive &item);
class MatchItemAccess {
private:
friend class ItemBuilder;
const DecisionItem& getDecision() const;
bool match(const MatchItemAccess& query) const;
- const char* toString(char* str) const;
size_t getSize() const;
+ friend std::ostream &operator<<(std::ostream& stream, const ItemAccess &item);
};
+ std::ostream &operator<<(std::ostream& stream, const ItemAccess &item);
class NaivePolicyDb;