diff --git a/repos/os/include/os/session_policy.h b/repos/os/include/os/session_policy.h index a374c409c9..d5a4cd2bcd 100644 --- a/repos/os/include/os/session_policy.h +++ b/repos/os/include/os/session_policy.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -57,7 +58,7 @@ struct Genode::Xml_node_label_score Xml_node_label_score() { } template - Xml_node_label_score(Xml_node node, String const &label) + Xml_node_label_score(Xml_node const &node, String const &label) : label_present (node.has_attribute("label")), prefix_present(node.has_attribute("label_prefix")), @@ -178,28 +179,31 @@ void Genode::with_matching_policy(String const &label, /* * Find policy node that matches best */ - Xml_node best_match(""); - Xml_node_label_score best_score; + Constructible best_match { }; + Xml_node_label_score best_score; policies.for_each_sub_node("policy", [&] (Xml_node const &policy) { Xml_node_label_score const score(policy, label); - if (score.stronger(best_score)) { - best_match = policy; - best_score = score; - } + if (score.stronger(best_score)) + policy.with_raw_node([&] (char const *ptr, size_t len) { + best_match.construct(ptr, len); + best_score = score; }); }); /* fall back to default policy if no match exists */ - if (best_match.has_type("none")) + if (!best_match.constructed()) policies.with_optional_sub_node("default-policy", [&] (Xml_node const &policy) { - best_match = policy; }); + policy.with_raw_node([&] (char const *ptr, size_t len) { + best_match.construct(ptr, len); }); }); - if (best_match.has_type("none")) + if (best_match.constructed()) { + Xml_node const &node = *best_match; + match_fn(node); + } else { no_match_fn(); - else - match_fn(best_match); + } } @@ -221,20 +225,24 @@ class Genode::Session_policy : public Xml_node * Query session policy from session label */ template - static Xml_node _query_policy(String const &label, Xml_node config) + static Const_byte_range_ptr _query_policy(String const &label, Xml_node const &config) { - Xml_node result(""); + char const *start_ptr = ""; + size_t num_bytes = 7; with_matching_policy(label, config, [&] (Xml_node const &policy) { - result = policy; }, + policy.with_raw_node([&] (char const *ptr, size_t len) { + start_ptr = ptr; + num_bytes = len; }); + }, [&] () { warning("no policy defined for label '", label, "'"); throw No_policy_defined(); }); - return result; + return { start_ptr, num_bytes }; } public: @@ -257,7 +265,7 @@ class Genode::Session_policy : public Xml_node * with the longest label is selected. */ template - Session_policy(String const &label, Xml_node config) + Session_policy(String const &label, Xml_node const &config) : Xml_node(_query_policy(label, config)) { }