init: make label rewriting more flexible

This patch complements the existing 'label' attribute of session-route
target nodes with the new 'identity', 'resource', and 'prepend_resource'
attributes that allow for the partial rewriting of the label.

Fixes #5447
This commit is contained in:
Norman Feske 2025-02-12 15:17:35 +01:00 committed by Christian Helmuth
parent c5a2b00068
commit bf2c48f26f
2 changed files with 34 additions and 9 deletions

View File

@ -5,12 +5,23 @@
<xs:complexType name="template_service">
<xs:choice minOccurs="1" maxOccurs="3">
<xs:element name="parent"/>
<xs:element name="parent">
<xs:complexType>
<xs:attribute name="label" type="Session_label" />
<xs:attribute name="identity" type="Session_label" />
<xs:attribute name="resource" type="Session_label" />
<xs:attribute name="prefix_resource" type="Session_label" />
<xs:attribute name="diag" type="Boolean" />
</xs:complexType>
</xs:element>
<xs:element name="any-child"/>
<xs:element name="child">
<xs:complexType>
<xs:attribute name="name" type="xs:string" />
<xs:attribute name="label" type="Session_label" />
<xs:attribute name="name" type="xs:string" />
<xs:attribute name="label" type="Session_label" />
<xs:attribute name="identity" type="Session_label" />
<xs:attribute name="resource" type="Session_label" />
<xs:attribute name="prefix_resource" type="Session_label" />
</xs:complexType>
</xs:element>
</xs:choice>

View File

@ -559,14 +559,28 @@ Sandbox::Child::resolve_session_request(Service::Name const &service_name,
* Determine session label to be provided to the server
*
* By default, the client's identity (accompanied with the a
* client-provided label) is presented as session label to the
* server. However, the target node can explicitly override the
* client's identity by a custom label via the 'label'
* attribute.
* client-provided label) is presented as session label to the server.
* However, the target node can explicitly override the client's
* identity and the client's resource selection via the 'label',
* 'identity', 'resource', and 'prepend_resource' attributes.
*/
using Label = String<Session_label::capacity()>;
Label const target_label =
target.attribute_value("label", Label(label.string()));
auto rewritten_target_label = [&] () -> Label
{
if (target.has_attribute("label"))
return target.attribute_value("label", Label());
Label const
identity = target.attribute_value("identity", Label(label.prefix())),
resource = target.attribute_value("resource", Label(label.last_element())),
prepend = target.attribute_value("prepend_resource", Label(""));
Label const prepended_resource { prepend, resource };
return identity.length() > 1 ? prefixed_label(identity, prepended_resource)
: prepended_resource;
};
Label const target_label = rewritten_target_label();
Session::Diag const
target_diag { target.attribute_value("diag", diag.enabled) };