mirror of
https://github.com/genodelabs/genode.git
synced 2025-06-05 17:01:47 +00:00
This patch unconditionally applies the labeling of sessions and thereby removes the most common use case of 'Child_policy::filter_session_args'. Furthermore, the patch removes an ambiguity of the session labels of sessions created by the parent of behalf of its child, e.g., the PD session created as part of 'Child' now has the label "<child-name>" whereas an unlabeled PD-session request originating from the child has the label "<child-name> -> ". This way, the routing-policy of 'Child_policy::resolve_session_request' can differentiate both cases. As a consequence, the stricter labeling must now be considered wherever a precise label was specified as a key for a session route or a server- side policy selection. The simplest way to adapt those cases is to use a 'label_prefix' instead of the 'label' attribute. Alternatively, the 'label' attribute may used by appending " -> " (note the whitespace). Fixes #2171
102 lines
2.4 KiB
C++
102 lines
2.4 KiB
C++
/*
|
|
* \brief Session label utility class
|
|
* \author Emery Hemingway
|
|
* \author Norman Feske
|
|
* \date 2016-07-01
|
|
*/
|
|
|
|
/*
|
|
* Copyright (C) 2016 Genode Labs GmbH
|
|
*
|
|
* This file is part of the Genode OS framework, which is distributed
|
|
* under the terms of the GNU General Public License version 2.
|
|
*/
|
|
|
|
#ifndef _INCLUDE__BASE__SESSION_LABEL_H_
|
|
#define _INCLUDE__BASE__SESSION_LABEL_H_
|
|
|
|
#include <base/snprintf.h>
|
|
#include <util/arg_string.h>
|
|
#include <util/string.h>
|
|
|
|
namespace Genode { struct Session_label; }
|
|
|
|
struct Genode::Session_label : String<160>
|
|
{
|
|
private:
|
|
|
|
typedef String<capacity()> String;
|
|
|
|
static char const *_separator() { return " -> "; }
|
|
static size_t _separator_len() { return 4; }
|
|
|
|
public:
|
|
|
|
using String::String;
|
|
|
|
Session_label last_element() const
|
|
{
|
|
char const * const full = string();
|
|
size_t const full_len = strlen(full);
|
|
|
|
if (full_len < _separator_len())
|
|
return full;
|
|
|
|
unsigned i = full_len - _separator_len();
|
|
do {
|
|
if (!strcmp(_separator(), full + i, _separator_len()))
|
|
return full + i + _separator_len();
|
|
} while (i-- > 0);
|
|
|
|
return Session_label(Cstring(full));
|
|
}
|
|
|
|
/**
|
|
* Return part of the label without the last element
|
|
*/
|
|
inline Session_label prefix() const
|
|
{
|
|
if (length() < _separator_len() + 1)
|
|
return Session_label();
|
|
|
|
/* search for last occurrence of the separator */
|
|
unsigned prefix_len = length() - _separator_len() - 1;
|
|
char const * const full = string();
|
|
|
|
for (; prefix_len > 0; prefix_len--)
|
|
if (strcmp(full + prefix_len, _separator(), _separator_len()) == 0)
|
|
break;
|
|
|
|
/* construct new label with only the prefix part */
|
|
return Session_label(Cstring(full, prefix_len));
|
|
}
|
|
};
|
|
|
|
|
|
namespace Genode {
|
|
|
|
/**
|
|
* Extract label from session arguments in the form of 'label="..."'
|
|
*/
|
|
inline Session_label label_from_args(char const *args)
|
|
{
|
|
char buf[Session_label::capacity()];
|
|
Arg_string::find_arg(args, "label").string(buf, sizeof(buf), "");
|
|
|
|
return Session_label(Cstring(buf));
|
|
}
|
|
|
|
/**
|
|
* Create a compound label in the form of 'prefix -> label'
|
|
*/
|
|
template <size_t N1, size_t N2>
|
|
inline Session_label prefixed_label(String<N1> const &prefix,
|
|
String<N2> const &label)
|
|
{
|
|
String<N1 + N2 + 4> const prefixed_label(prefix, " -> ", label);
|
|
return Session_label(prefixed_label);
|
|
}
|
|
}
|
|
|
|
#endif /* _INCLUDE__BASE__SESSION_LABEL_H_ */
|