mirror of
https://github.com/genodelabs/genode.git
synced 2025-04-09 04:15:52 +00:00
os: Split Session_label from Session_policy
By splitting Session_policy into two classes, we make it more flexible. Originally, the constructor accepted solely an args string, which made it unusable for situations where we already have extracted the session label (e.g., stored in the session meta data of a server). Now, the extraction of the label from the args string is performed by the new Session_label class instead, which, in turn, can be passed to the constructor of Session_policy. This change causes a minor API change. The following code Session_policy policy(session_args); Must be turned into Session_label label(session_args); Session_policy policy(label);
This commit is contained in:
parent
f371aef346
commit
6575856624
@ -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);
|
||||
|
@ -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
|
||||
|
@ -118,7 +118,8 @@ class Log_root : public Genode::Root_component<Log_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");
|
||||
|
@ -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),
|
||||
"<undefined>");
|
||||
}
|
||||
|
||||
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), "<unlabeled>");
|
||||
|
||||
/* 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)) { }
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user