diff --git a/gems/src/server/tcp_terminal/main.cc b/gems/src/server/tcp_terminal/main.cc index 705ade303..d1d4eb95e 100644 --- a/gems/src/server/tcp_terminal/main.cc +++ b/gems/src/server/tcp_terminal/main.cc @@ -458,7 +458,8 @@ namespace Terminal { Genode::size_t io_buffer_size = 4096; try { - Genode::Session_policy policy(args); + Genode::Session_label label(args); + Genode::Session_policy policy(label); unsigned tcp_port = 0; policy.attribute("port").value(&tcp_port); diff --git a/libports/src/server/ffat_fs/main.cc b/libports/src/server/ffat_fs/main.cc index 2034c0cef..0b7d6ad2d 100644 --- a/libports/src/server/ffat_fs/main.cc +++ b/libports/src/server/ffat_fs/main.cc @@ -879,7 +879,8 @@ namespace File_system { root[0] = 0; try { - Session_policy policy(args); + Session_label label(args); + Session_policy policy(label); /* * Determine directory that is used as root directory of diff --git a/libports/src/server/fs_log/main.cc b/libports/src/server/fs_log/main.cc index d7b485e46..8f290ffb1 100644 --- a/libports/src/server/fs_log/main.cc +++ b/libports/src/server/fs_log/main.cc @@ -118,7 +118,8 @@ class Log_root : public Genode::Root_component enum { FILENAME_MAX_LEN = 256 }; char filename[FILENAME_MAX_LEN]; try { - Session_policy policy(args); + Session_label label(args); + Session_policy policy(label); policy.attribute("file").value(filename, sizeof(filename)); } catch (...) { PERR("Invalid session request, no matching policy"); diff --git a/os/include/os/session_policy.h b/os/include/os/session_policy.h index 5f19bdd99..150135445 100644 --- a/os/include/os/session_policy.h +++ b/os/include/os/session_policy.h @@ -19,6 +19,34 @@ namespace Genode { + class Session_label + { + public: + + enum { MAX_LEN = 128 }; + + private: + + char _buf[MAX_LEN]; + + public: + + Session_label() { _buf[0] = 0; } + + /** + * Constructor + * + * \param args session-arguments as null-terminated string + */ + explicit Session_label(char const *args) + { + Arg_string::find_arg(args, "label").string(_buf, sizeof(_buf), + ""); + } + + char const *string() const { return _buf; } + }; + /** * Query server-side policy for a session request */ @@ -37,19 +65,14 @@ namespace Genode { * Returns true if the start of the label matches the specified * match string */ - static bool _label_matches(const char *label, const char *match) { - return strcmp(label, match, strlen(match)) == 0; } + static bool _label_matches(Session_label const &label, char const *match) { + return strcmp(label.string(), match, strlen(match)) == 0; } /** - * Query session policy from config + * Query session policy from session label */ - static Xml_node _query_policy(char const *args) + static Xml_node _query_policy(Session_label const &label) { - enum { LABEL_LEN = 128 }; - char session_label[LABEL_LEN]; - Arg_string::find_arg(args, "label"). - string(session_label, sizeof(session_label), ""); - /* find index of policy node that matches best */ int best_match = -1; try { @@ -62,11 +85,11 @@ namespace Genode { continue; /* label attribtute from policy node */ - char policy_label[LABEL_LEN]; + char policy_label[Session_label::MAX_LEN]; policy.attribute("label").value(policy_label, sizeof(policy_label)); - if (!_label_matches(session_label, policy_label) + if (!_label_matches(label, policy_label) || strlen(policy_label) < label_len) continue; @@ -92,18 +115,17 @@ namespace Genode { * policy defined for the session * request * - * On construction, the 'Session_policy' looks up the 'policy' - * XML note that matches the label delivered as session argument. - * The server-side policies are defined in one or more policy - * subnodes of the server's 'config' node. Each policy node has - * a label attribute. The if policy label matches the first - * part of the label delivered as session argument, the policy - * matches. If multiple policies match, the one with the largest - * label is selected. + * On construction, the 'Session_policy' looks up the 'policy' XML + * note that matches the label provided as argument. The + * server-side policies are defined in one or more policy subnodes + * of the server's 'config' node. Each policy node has a label + * attribute. The if policy label matches the first part of the + * label delivered as session argument, the policy matches. If + * multiple policies match, the one with the largest label is + * selected. */ - Session_policy(char const *args) - : Xml_node(_query_policy(args)) - { } + explicit Session_policy(Session_label const &label) + : Xml_node(_query_policy(label)) { } }; } diff --git a/os/src/drivers/uart/uart_component.h b/os/src/drivers/uart/uart_component.h index 191c59b74..ee81e27aa 100644 --- a/os/src/drivers/uart/uart_component.h +++ b/os/src/drivers/uart/uart_component.h @@ -221,7 +221,8 @@ namespace Uart { Session_component *_create_session(const char *args) { try { - Session_policy policy(args); + Session_label label(args); + Session_policy policy(label); unsigned index = 0; policy.attribute("uart").value(&index); diff --git a/os/src/server/nic_bridge/component.h b/os/src/server/nic_bridge/component.h index 9be5045b0..e509ae60e 100644 --- a/os/src/server/nic_bridge/component.h +++ b/os/src/server/nic_bridge/component.h @@ -171,7 +171,6 @@ namespace Net { enum { MAX_IP_ADDR_LENGTH = 16, }; char ip_addr[MAX_IP_ADDR_LENGTH]; - char label[256]; Session_component *_create_session(const char *args) { @@ -180,11 +179,11 @@ namespace Net { memset(ip_addr, 0, MAX_IP_ADDR_LENGTH); try { - Genode::Arg_string::find_arg(args, "label").string(label, sizeof(label), ""); - Session_policy policy(args); + Session_label label(args); + Session_policy policy(label); policy.attribute("ip_addr").value(ip_addr, sizeof(ip_addr)); - if (verbose) PDBG("policy: %s ip_addr = %s", label, ip_addr); + if (verbose) PDBG("policy: %s ip_addr = %s", label.string(), ip_addr); } catch (Xml_node::Nonexistent_attribute) { if (verbose) PDBG("Missing \"ip_addr\" attribute in policy definition"); } catch (Session_policy::No_policy_defined) { diff --git a/os/src/server/nitpicker/main.cc b/os/src/server/nitpicker/main.cc index f0bb58336..eefd05602 100644 --- a/os/src/server/nitpicker/main.cc +++ b/os/src/server/nitpicker/main.cc @@ -70,7 +70,8 @@ static Color session_color(char const *session_args) Color color = WHITE; try { - Session_policy policy(session_args); + Session_label label(session_args); + Session_policy policy(label); /* read color attribute */ policy.attribute("color").value(&color); diff --git a/os/src/server/ram_fs/main.cc b/os/src/server/ram_fs/main.cc index a56da5ca6..09d80d152 100644 --- a/os/src/server/ram_fs/main.cc +++ b/os/src/server/ram_fs/main.cc @@ -437,7 +437,8 @@ namespace File_system { root[0] = 0; try { - Session_policy policy(args); + Session_label label(args); + Session_policy policy(label); /* * Determine directory that is used as root directory of diff --git a/os/src/server/tar_fs/main.cc b/os/src/server/tar_fs/main.cc index 65a61f8cc..aeb2ad58d 100644 --- a/os/src/server/tar_fs/main.cc +++ b/os/src/server/tar_fs/main.cc @@ -450,7 +450,8 @@ namespace File_system { root[0] = 0; try { - Session_policy policy(args); + Session_label label(args); + Session_policy policy(label); /* * Determine directory that is used as root directory of