mirror of
https://github.com/genodelabs/genode.git
synced 2025-06-18 07:08:18 +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:
@ -458,7 +458,8 @@ namespace Terminal {
|
|||||||
Genode::size_t io_buffer_size = 4096;
|
Genode::size_t io_buffer_size = 4096;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Genode::Session_policy policy(args);
|
Genode::Session_label label(args);
|
||||||
|
Genode::Session_policy policy(label);
|
||||||
|
|
||||||
unsigned tcp_port = 0;
|
unsigned tcp_port = 0;
|
||||||
policy.attribute("port").value(&tcp_port);
|
policy.attribute("port").value(&tcp_port);
|
||||||
|
@ -879,7 +879,8 @@ namespace File_system {
|
|||||||
root[0] = 0;
|
root[0] = 0;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Session_policy policy(args);
|
Session_label label(args);
|
||||||
|
Session_policy policy(label);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Determine directory that is used as root directory of
|
* 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 };
|
enum { FILENAME_MAX_LEN = 256 };
|
||||||
char filename[FILENAME_MAX_LEN];
|
char filename[FILENAME_MAX_LEN];
|
||||||
try {
|
try {
|
||||||
Session_policy policy(args);
|
Session_label label(args);
|
||||||
|
Session_policy policy(label);
|
||||||
policy.attribute("file").value(filename, sizeof(filename));
|
policy.attribute("file").value(filename, sizeof(filename));
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
PERR("Invalid session request, no matching policy");
|
PERR("Invalid session request, no matching policy");
|
||||||
|
@ -19,6 +19,34 @@
|
|||||||
|
|
||||||
namespace Genode {
|
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
|
* 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
|
* Returns true if the start of the label matches the specified
|
||||||
* match string
|
* match string
|
||||||
*/
|
*/
|
||||||
static bool _label_matches(const char *label, const char *match) {
|
static bool _label_matches(Session_label const &label, char const *match) {
|
||||||
return strcmp(label, match, strlen(match)) == 0; }
|
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 */
|
/* find index of policy node that matches best */
|
||||||
int best_match = -1;
|
int best_match = -1;
|
||||||
try {
|
try {
|
||||||
@ -62,11 +85,11 @@ namespace Genode {
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* label attribtute from policy node */
|
/* label attribtute from policy node */
|
||||||
char policy_label[LABEL_LEN];
|
char policy_label[Session_label::MAX_LEN];
|
||||||
policy.attribute("label").value(policy_label,
|
policy.attribute("label").value(policy_label,
|
||||||
sizeof(policy_label));
|
sizeof(policy_label));
|
||||||
|
|
||||||
if (!_label_matches(session_label, policy_label)
|
if (!_label_matches(label, policy_label)
|
||||||
|| strlen(policy_label) < label_len)
|
|| strlen(policy_label) < label_len)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -92,18 +115,17 @@ namespace Genode {
|
|||||||
* policy defined for the session
|
* policy defined for the session
|
||||||
* request
|
* request
|
||||||
*
|
*
|
||||||
* On construction, the 'Session_policy' looks up the 'policy'
|
* On construction, the 'Session_policy' looks up the 'policy' XML
|
||||||
* XML note that matches the label delivered as session argument.
|
* note that matches the label provided as argument. The
|
||||||
* The server-side policies are defined in one or more policy
|
* server-side policies are defined in one or more policy subnodes
|
||||||
* subnodes of the server's 'config' node. Each policy node has
|
* of the server's 'config' node. Each policy node has a label
|
||||||
* a label attribute. The if policy label matches the first
|
* attribute. The if policy label matches the first part of the
|
||||||
* part of the label delivered as session argument, the policy
|
* label delivered as session argument, the policy matches. If
|
||||||
* matches. If multiple policies match, the one with the largest
|
* multiple policies match, the one with the largest label is
|
||||||
* label is selected.
|
* selected.
|
||||||
*/
|
*/
|
||||||
Session_policy(char const *args)
|
explicit Session_policy(Session_label const &label)
|
||||||
: Xml_node(_query_policy(args))
|
: Xml_node(_query_policy(label)) { }
|
||||||
{ }
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,7 +221,8 @@ namespace Uart {
|
|||||||
Session_component *_create_session(const char *args)
|
Session_component *_create_session(const char *args)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
Session_policy policy(args);
|
Session_label label(args);
|
||||||
|
Session_policy policy(label);
|
||||||
|
|
||||||
unsigned index = 0;
|
unsigned index = 0;
|
||||||
policy.attribute("uart").value(&index);
|
policy.attribute("uart").value(&index);
|
||||||
|
@ -171,7 +171,6 @@ namespace Net {
|
|||||||
|
|
||||||
enum { MAX_IP_ADDR_LENGTH = 16, };
|
enum { MAX_IP_ADDR_LENGTH = 16, };
|
||||||
char ip_addr[MAX_IP_ADDR_LENGTH];
|
char ip_addr[MAX_IP_ADDR_LENGTH];
|
||||||
char label[256];
|
|
||||||
|
|
||||||
Session_component *_create_session(const char *args)
|
Session_component *_create_session(const char *args)
|
||||||
{
|
{
|
||||||
@ -180,11 +179,11 @@ namespace Net {
|
|||||||
memset(ip_addr, 0, MAX_IP_ADDR_LENGTH);
|
memset(ip_addr, 0, MAX_IP_ADDR_LENGTH);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Genode::Arg_string::find_arg(args, "label").string(label, sizeof(label), "");
|
Session_label label(args);
|
||||||
Session_policy policy(args);
|
Session_policy policy(label);
|
||||||
policy.attribute("ip_addr").value(ip_addr, sizeof(ip_addr));
|
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) {
|
} catch (Xml_node::Nonexistent_attribute) {
|
||||||
if (verbose) PDBG("Missing \"ip_addr\" attribute in policy definition");
|
if (verbose) PDBG("Missing \"ip_addr\" attribute in policy definition");
|
||||||
} catch (Session_policy::No_policy_defined) {
|
} catch (Session_policy::No_policy_defined) {
|
||||||
|
@ -70,7 +70,8 @@ static Color session_color(char const *session_args)
|
|||||||
Color color = WHITE;
|
Color color = WHITE;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Session_policy policy(session_args);
|
Session_label label(session_args);
|
||||||
|
Session_policy policy(label);
|
||||||
|
|
||||||
/* read color attribute */
|
/* read color attribute */
|
||||||
policy.attribute("color").value(&color);
|
policy.attribute("color").value(&color);
|
||||||
|
@ -437,7 +437,8 @@ namespace File_system {
|
|||||||
root[0] = 0;
|
root[0] = 0;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Session_policy policy(args);
|
Session_label label(args);
|
||||||
|
Session_policy policy(label);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Determine directory that is used as root directory of
|
* Determine directory that is used as root directory of
|
||||||
|
@ -450,7 +450,8 @@ namespace File_system {
|
|||||||
root[0] = 0;
|
root[0] = 0;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Session_policy policy(args);
|
Session_label label(args);
|
||||||
|
Session_policy policy(label);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Determine directory that is used as root directory of
|
* Determine directory that is used as root directory of
|
||||||
|
Reference in New Issue
Block a user