mirror of
https://gitlab.freedesktop.org/libinput/libei.git
synced 2026-05-02 01:38:13 +02:00
reis: simplify the library a bit
Pass the fd into the original context creation, then write any changes to the wire immediately. For the capabilities that means we can't build them up as before anymore, so change the API to have a vararg function and require the allowed capabilities to be passed in. There's likely little use for the previous allow-vs-deny policy etc, so let's not make things more complicated an they have to be. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
4376e8da88
commit
7fc9498f1d
7 changed files with 69 additions and 168 deletions
|
|
@ -64,9 +64,7 @@ message ConfigureName {
|
|||
|
||||
/* Changes the capability policy and allows or denies specific capabilities */
|
||||
message ConfigureCapabilities {
|
||||
bool policy_is_allow = 1;
|
||||
uint32 allowed_capabilities = 2;
|
||||
uint32 denied_capabilities = 3;
|
||||
}
|
||||
|
||||
message Connect {
|
||||
|
|
|
|||
|
|
@ -505,23 +505,9 @@ client_msg_configure_name(struct eis_client *client, const char *name)
|
|||
}
|
||||
|
||||
static int
|
||||
client_msg_configure_capabilities(struct eis_client *client, bool policy_is_allow,
|
||||
uint32_t allowed_caps, uint32_t denied_caps)
|
||||
client_msg_configure_capabilities(struct eis_client *client, uint32_t allowed_caps)
|
||||
{
|
||||
if (policy_is_allow) {
|
||||
/* We can only manage allow masks while we're in
|
||||
* default-allow policy.
|
||||
* first call to set allow masks is taken as-is, from then onwards
|
||||
* we can only restrict */
|
||||
if (client->restrictions.cap_allow_mask == ~0U)
|
||||
client->restrictions.cap_allow_mask = allowed_caps;
|
||||
else
|
||||
client->restrictions.cap_allow_mask &= allowed_caps;
|
||||
} else {
|
||||
client->restrictions.cap_policy = CLIENT_CAP_POLICY_DENY;
|
||||
}
|
||||
|
||||
client->restrictions.cap_deny_mask |= denied_caps;
|
||||
client->restrictions.cap_allow_mask = allowed_caps;
|
||||
|
||||
/* FIXME: if something is disallowed now, we should disconnect
|
||||
* accordingly.
|
||||
|
|
@ -722,9 +708,7 @@ eis_client_new(struct eis *eis, int fd)
|
|||
|
||||
client->source = source_ref(s);
|
||||
client->state = EIS_CLIENT_STATE_NEW;
|
||||
client->restrictions.cap_policy = CLIENT_CAP_POLICY_ALLOW;
|
||||
client->restrictions.cap_allow_mask = ~0U;
|
||||
client->restrictions.cap_deny_mask = 0;
|
||||
|
||||
eis_add_client(eis, eis_client_ref(client));
|
||||
|
||||
|
|
|
|||
|
|
@ -78,12 +78,7 @@ struct eis_client {
|
|||
struct list properties;
|
||||
|
||||
struct {
|
||||
enum {
|
||||
CLIENT_CAP_POLICY_ALLOW,
|
||||
CLIENT_CAP_POLICY_DENY,
|
||||
} cap_policy;
|
||||
uint32_t cap_allow_mask;
|
||||
uint32_t cap_deny_mask;
|
||||
} restrictions;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -407,9 +407,7 @@ eis_proto_handle_message(struct eis_client *client,
|
|||
break;
|
||||
case CLIENT_MESSAGE__MSG_CONFIGURE_CAPABILITIES:
|
||||
rc = call(configure_capabilities, client,
|
||||
proto->configure_capabilities->policy_is_allow,
|
||||
proto->configure_capabilities->allowed_capabilities,
|
||||
proto->configure_capabilities->denied_capabilities);
|
||||
proto->configure_capabilities->allowed_capabilities);
|
||||
break;
|
||||
case CLIENT_MESSAGE__MSG_FRAME:
|
||||
rc = call(frame, client, proto->frame->deviceid);
|
||||
|
|
|
|||
|
|
@ -56,9 +56,7 @@ struct eis_proto_interface {
|
|||
uint32_t tid, double x, double y);
|
||||
int (*touch_up)(struct eis_client *client, uint32_t deviceid, uint32_t tid);
|
||||
int (*configure_name)(struct eis_client *client, const char *name);
|
||||
int (*configure_capabilities)(struct eis_client *client,
|
||||
bool policy_is_allow,
|
||||
uint32_t allow, uint32_t deny);
|
||||
int (*configure_capabilities)(struct eis_client *client, uint32_t allow);
|
||||
int (*frame) (struct eis_client *client, uint32_t deviceid);
|
||||
int (*property)(struct eis_client *client, const char *name,
|
||||
const char *value, uint32_t permissions);
|
||||
|
|
|
|||
110
src/libreis.c
110
src/libreis.c
|
|
@ -36,16 +36,13 @@
|
|||
|
||||
struct reis {
|
||||
struct object object;
|
||||
char *name;
|
||||
bool policy_is_allow;
|
||||
uint32_t allow;
|
||||
uint32_t deny;
|
||||
int eisfd;
|
||||
};
|
||||
|
||||
static void
|
||||
reis_destroy(struct reis *reis)
|
||||
{
|
||||
free(reis->name);
|
||||
xclose(reis->eisfd);
|
||||
}
|
||||
|
||||
_public_
|
||||
|
|
@ -68,13 +65,15 @@ send_msg(int fd, const ClientMessage *msg)
|
|||
}
|
||||
|
||||
_public_ struct reis *
|
||||
reis_new(void)
|
||||
reis_new(int eisfd)
|
||||
{
|
||||
struct reis *reis = reis_create(NULL);
|
||||
_unref_(reis) *reis = reis_create(NULL);
|
||||
|
||||
reis->policy_is_allow = true;
|
||||
reis->eisfd = dup(eisfd);
|
||||
if (reis->eisfd == -1)
|
||||
return NULL;
|
||||
|
||||
return reis;
|
||||
return steal(&reis);
|
||||
}
|
||||
|
||||
#define prepare_msg(_type, _struct, _field) \
|
||||
|
|
@ -83,79 +82,44 @@ reis_new(void)
|
|||
msg.msg_case = CLIENT_MESSAGE__MSG_##_type; \
|
||||
msg._field = &_field
|
||||
|
||||
_public_ int
|
||||
reis_apply(struct reis *reis, int eisfd)
|
||||
{
|
||||
if (reis->name) {
|
||||
prepare_msg(CONFIGURE_NAME, ConfigureName, configure_name);
|
||||
configure_name.name = reis->name;
|
||||
|
||||
int rc = send_msg(eisfd, &msg);
|
||||
if (rc)
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (!reis->policy_is_allow || reis->allow || reis->deny) {
|
||||
prepare_msg(CONFIGURE_CAPABILITIES, ConfigureCapabilities, configure_capabilities);
|
||||
configure_capabilities.policy_is_allow = reis->policy_is_allow;
|
||||
configure_capabilities.allowed_capabilities = reis->allow;
|
||||
configure_capabilities.denied_capabilities = reis->deny;
|
||||
|
||||
int rc = send_msg(eisfd, &msg);
|
||||
if (rc)
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
_public_ int
|
||||
reis_set_name(struct reis *reis, const char *name)
|
||||
{
|
||||
free(reis->name);
|
||||
reis->name = xstrdup(name);
|
||||
prepare_msg(CONFIGURE_NAME, ConfigureName, configure_name);
|
||||
configure_name.name = (char*)name;
|
||||
|
||||
return 0;
|
||||
int rc = send_msg(reis->eisfd, &msg);
|
||||
return rc;
|
||||
}
|
||||
|
||||
_public_ int
|
||||
reis_set_cap_policy_allow(struct reis *reis)
|
||||
reis_allow_capability(struct reis *reis, enum reis_device_capability capability, ...)
|
||||
{
|
||||
reis->policy_is_allow = true;
|
||||
return 0;
|
||||
}
|
||||
enum reis_device_capability cap = capability;
|
||||
uint32_t caps = 0;
|
||||
va_list args;
|
||||
|
||||
_public_ int
|
||||
reis_set_cap_policy_deny(struct reis *reis)
|
||||
{
|
||||
reis->policy_is_allow = false;
|
||||
return 0;
|
||||
}
|
||||
va_start(args, capability);
|
||||
do {
|
||||
switch (cap) {
|
||||
case REIS_DEVICE_CAP_POINTER:
|
||||
case REIS_DEVICE_CAP_POINTER_ABSOLUTE:
|
||||
case REIS_DEVICE_CAP_KEYBOARD:
|
||||
case REIS_DEVICE_CAP_TOUCH:
|
||||
caps |= bit(cap);
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
} while ((cap = va_arg(args, enum reis_device_capability)) > 0);
|
||||
va_end(args);
|
||||
|
||||
prepare_msg(CONFIGURE_CAPABILITIES, ConfigureCapabilities, configure_capabilities);
|
||||
configure_capabilities.allowed_capabilities = caps;
|
||||
|
||||
int rc = send_msg(reis->eisfd, &msg);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
_public_ int
|
||||
reis_allow_cap(struct reis *reis, enum reis_device_capability cap)
|
||||
{
|
||||
switch (cap) {
|
||||
case REIS_DEVICE_CAP_POINTER:
|
||||
case REIS_DEVICE_CAP_POINTER_ABSOLUTE:
|
||||
case REIS_DEVICE_CAP_KEYBOARD:
|
||||
case REIS_DEVICE_CAP_TOUCH:
|
||||
reis->allow |= bit(cap);
|
||||
return 0;
|
||||
}
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
_public_ int
|
||||
reis_deny_cap(struct reis *reis, enum reis_device_capability cap)
|
||||
{
|
||||
switch (cap) {
|
||||
case REIS_DEVICE_CAP_POINTER:
|
||||
case REIS_DEVICE_CAP_POINTER_ABSOLUTE:
|
||||
case REIS_DEVICE_CAP_KEYBOARD:
|
||||
case REIS_DEVICE_CAP_TOUCH:
|
||||
reis->deny |= bit(cap);
|
||||
return 0;
|
||||
}
|
||||
return -EINVAL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,10 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define _sentinel_ __attribute__((sentinel))
|
||||
|
||||
/**
|
||||
* REIS is the library for Restrictions for EIS. This library is used by
|
||||
* intermediaries between EI and EIS to reduce the capabilities that an EI
|
||||
|
|
@ -43,27 +47,22 @@ enum reis_device_capability {
|
|||
REIS_DEVICE_CAP_POINTER_ABSOLUTE,
|
||||
REIS_DEVICE_CAP_KEYBOARD,
|
||||
REIS_DEVICE_CAP_TOUCH,
|
||||
|
||||
REIS_DEVICE_CAP_ALL = ~0,
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new reis context based on the EIS connection at the other end of
|
||||
* @a eisfd. The EIS context does not need to be in any
|
||||
* specific state and no checking is done that there is indeed an EIS
|
||||
* context at the other end of the fd.
|
||||
*/
|
||||
struct reis *
|
||||
reis_new(void);
|
||||
reis_new(int eisfd);
|
||||
|
||||
struct reis *
|
||||
reis_unref(struct reis* reis);
|
||||
|
||||
/**
|
||||
* Apply the currently configured set of restrictions to the EIS context at
|
||||
* the other end of eisfd. The EIS context does not need to be in any
|
||||
* specific state and no checking is done that there is indeed an EIS
|
||||
* context at the other end of the fd.
|
||||
*
|
||||
* Once applied, the reis context should be released with reis_unref()
|
||||
*
|
||||
* @return zero on success or a negative errno otherwise
|
||||
*/
|
||||
int
|
||||
reis_apply(struct reis *reis, int eisfd);
|
||||
|
||||
/**
|
||||
* Set the name for the client on this connection.
|
||||
*
|
||||
|
|
@ -80,55 +79,20 @@ int
|
|||
reis_set_name(struct reis *reis, const char *name);
|
||||
|
||||
/**
|
||||
* Change the default policy for capabilities to "allow". Capabilities are
|
||||
* allowed unless explicitly denied by reis_deny_cap().
|
||||
* Explicitly allow the given capabilities. The argument list must be
|
||||
* terminated with zero.
|
||||
*
|
||||
* This function has no effect if the default policy is "deny".
|
||||
* By default, an EIS implementation will allow any capability. Calling this
|
||||
* function changes the EIS implementation's default behavior to deny all
|
||||
* capabilities EXCEPT the ones given in this call. For example, the following
|
||||
* code only allows the pointer and keyboard capabilty:
|
||||
*
|
||||
* @code
|
||||
* reis_allow_capability(reis, REIS_DEVICE_CAP_POINTER,
|
||||
* REIS_DEVICE_CAP_KEYBOARD, 0);
|
||||
* @endcode
|
||||
*
|
||||
* @return Zero on success or a negative errno on failure
|
||||
*/
|
||||
int
|
||||
reis_set_cap_policy_allow(struct reis *reis);
|
||||
|
||||
/**
|
||||
* Change the default policy for capabilities to "deny". Capabilities are
|
||||
* denied unless explicitly denied by reis_allow_cap().
|
||||
*
|
||||
* A caller must call reis_allow_cap() *before* calling
|
||||
* reis_set_cap_policy_deny(), once the default deny policy is in place, the
|
||||
* allowed capabilities cannot be expanded further.
|
||||
*
|
||||
* A capability is permitted if:
|
||||
* - the policy is allow and the capability is not in the deny list
|
||||
* - the policy is deny and the capability was added to the allow list
|
||||
* before the policy was set to deny
|
||||
*/
|
||||
int
|
||||
reis_set_cap_policy_deny(struct reis *reis);
|
||||
|
||||
/**
|
||||
* Explicitly allow the given capability.
|
||||
*
|
||||
* This function may be called multiple times before reis_apply() to create
|
||||
* a set of allowed capabilities.
|
||||
*
|
||||
* Where reis_apply() is called multiple times with reis_allow_cap(), the
|
||||
* final set of allowed capabilities is the intersection of all sets.
|
||||
* In other words, calling reis_apply() once with pointer and keyboard caps
|
||||
* and once with just keyboard caps results in just keyboard caps.
|
||||
*/
|
||||
int
|
||||
reis_allow_cap(struct reis *reis, enum reis_device_capability cap);
|
||||
|
||||
/**
|
||||
* Explicitly deny the given capability.
|
||||
*
|
||||
* This function may be called multiple times before reis_apply() to create
|
||||
* a set of denied capabilities.
|
||||
*
|
||||
* Where reis_apply() is called multiple times with reis_deny_cap(), the
|
||||
* final set of denied capabilities is the union of all sets.
|
||||
* In other words, calling reis_apply() once with pointer caps denied
|
||||
* and once with keyboard caps denied results in both pointer and keyboard
|
||||
* caps denied.
|
||||
*/
|
||||
int
|
||||
reis_deny_cap(struct reis *reis, enum reis_device_capability cap);
|
||||
_sentinel_ int
|
||||
reis_allow_capability(struct reis *reis, enum reis_device_capability cap, ...);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue