access: add access checks

Rework the access checks.
Add owner field to more objects to do access control checks
Make sure the object global is set in the object before signaling the
new global.
This commit is contained in:
Wim Taymans 2017-04-12 19:24:48 +02:00
parent d9bb116d27
commit 4cf59e3953
18 changed files with 230 additions and 200 deletions

View file

@ -42,6 +42,14 @@ struct _PinosInterface {
const void *events;
};
#define PINOS_CORE_METHOD_CLIENT_UPDATE 0
#define PINOS_CORE_METHOD_SYNC 1
#define PINOS_CORE_METHOD_GET_REGISTRY 2
#define PINOS_CORE_METHOD_CREATE_NODE 3
#define PINOS_CORE_METHOD_CREATE_CLIENT_NODE 4
#define PINOS_CORE_METHOD_UPDATE_TYPES 5
#define PINOS_CORE_METHOD_NUM 6
typedef struct {
void (*client_update) (void *object,
const SpaDict *props);
@ -71,6 +79,13 @@ typedef struct {
#define pinos_core_do_create_client_node(r,...) ((PinosCoreMethods*)r->iface->methods)->create_client_node(r,__VA_ARGS__)
#define pinos_core_do_update_types(r,...) ((PinosCoreMethods*)r->iface->methods)->update_types(r,__VA_ARGS__)
#define PINOS_CORE_EVENT_INFO 0
#define PINOS_CORE_EVENT_DONE 1
#define PINOS_CORE_EVENT_ERROR 2
#define PINOS_CORE_EVENT_REMOVE_ID 3
#define PINOS_CORE_EVENT_UPDATE_TYPES 4
#define PINOS_CORE_EVENT_NUM 5
typedef struct {
void (*info) (void *object,
PinosCoreInfo *info);
@ -94,6 +109,10 @@ typedef struct {
#define pinos_core_notify_remove_id(r,...) ((PinosCoreEvents*)r->iface->events)->remove_id(r,__VA_ARGS__)
#define pinos_core_notify_update_types(r,...) ((PinosCoreEvents*)r->iface->events)->update_types(r,__VA_ARGS__)
#define PINOS_REGISTRY_METHOD_BIND 0
#define PINOS_REGISTRY_METHOD_NUM 1
typedef struct {
void (*bind) (void *object,
uint32_t id,
@ -102,6 +121,10 @@ typedef struct {
#define pinos_registry_do_bind(r,...) ((PinosRegistryMethods*)r->iface->methods)->bind(r,__VA_ARGS__)
#define PINOS_REGISTRY_EVENT_GLOBAL 0
#define PINOS_REGISTRY_EVENT_GLOBAL_REMOVE 1
#define PINOS_REGISTRY_EVENT_NUM 2
typedef struct {
void (*global) (void *object,
uint32_t id,
@ -113,6 +136,9 @@ typedef struct {
#define pinos_registry_notify_global(r,...) ((PinosRegistryEvents*)r->iface->events)->global(r,__VA_ARGS__)
#define pinos_registry_notify_global_remove(r,...) ((PinosRegistryEvents*)r->iface->events)->global_remove(r,__VA_ARGS__)
#define PINOS_MODULE_EVENT_INFO 0
#define PINOS_MODULE_EVENT_NUM 1
typedef struct {
void (*info) (void *object,
PinosModuleInfo *info);
@ -120,6 +146,9 @@ typedef struct {
#define pinos_module_notify_info(r,...) ((PinosModuleEvents*)r->iface->events)->info(r,__VA_ARGS__)
#define PINOS_NODE_EVENT_INFO 0
#define PINOS_NODE_EVENT_NUM 1
typedef struct {
void (*info) (void *object,
PinosNodeInfo *info);
@ -134,6 +163,12 @@ struct _PinosClientNodeBuffer {
SpaBuffer *buffer;
};
#define PINOS_CLIENT_NODE_METHOD_UPDATE 0
#define PINOS_CLIENT_NODE_METHOD_PORT_UPDATE 1
#define PINOS_CLIENT_NODE_METHOD_EVENT 2
#define PINOS_CLIENT_NODE_METHOD_DESTROY 3
#define PINOS_CLIENT_NODE_METHOD_NUM 4
typedef struct {
void (*update) (void *object,
#define PINOS_MESSAGE_NODE_UPDATE_MAX_INPUTS (1 << 0)
@ -167,6 +202,19 @@ typedef struct {
#define pinos_client_node_do_event(r,...) ((PinosClientNodeMethods*)r->iface->methods)->event(r,__VA_ARGS__)
#define pinos_client_node_do_destroy(r) ((PinosClientNodeMethods*)r->iface->methods)->destroy(r)
#define PINOS_CLIENT_NODE_EVENT_DONE 0
#define PINOS_CLIENT_NODE_EVENT_EVENT 1
#define PINOS_CLIENT_NODE_EVENT_ADD_PORT 2
#define PINOS_CLIENT_NODE_EVENT_REMOVE_PORT 3
#define PINOS_CLIENT_NODE_EVENT_SET_FORMAT 4
#define PINOS_CLIENT_NODE_EVENT_SET_PROPERTY 5
#define PINOS_CLIENT_NODE_EVENT_ADD_MEM 6
#define PINOS_CLIENT_NODE_EVENT_USE_BUFFERS 7
#define PINOS_CLIENT_NODE_EVENT_NODE_COMMAND 8
#define PINOS_CLIENT_NODE_EVENT_PORT_COMMAND 9
#define PINOS_CLIENT_NODE_EVENT_TRANSPORT 10
#define PINOS_CLIENT_NODE_EVENT_NUM 11
typedef struct {
void (*done) (void *object,
int datafd);
@ -230,6 +278,9 @@ typedef struct {
#define pinos_client_node_notify_port_command(r,...) ((PinosClientNodeEvents*)r->iface->events)->port_command(r,__VA_ARGS__)
#define pinos_client_node_notify_transport(r,...) ((PinosClientNodeEvents*)r->iface->events)->transport(r,__VA_ARGS__)
#define PINOS_CLIENT_EVENT_INFO 0
#define PINOS_CLIENT_EVENT_NUM 1
typedef struct {
void (*info) (void *object,
PinosClientInfo *info);
@ -237,6 +288,9 @@ typedef struct {
#define pinos_client_notify_info(r,...) ((PinosClientEvents*)r->iface->events)->info(r,__VA_ARGS__)
#define PINOS_LINK_EVENT_INFO 0
#define PINOS_LINK_EVENT_NUM 1
typedef struct {
void (*info) (void *object,
PinosLinkInfo *info);

View file

@ -95,7 +95,7 @@ core_marshal_client_update (void *object,
}
spa_pod_builder_add (&b.b, -SPA_POD_TYPE_STRUCT, &f, 0);
pinos_connection_end_write (connection, proxy->id, 0, b.b.offset);
pinos_connection_end_write (connection, proxy->id, PINOS_CORE_METHOD_CLIENT_UPDATE, b.b.offset);
}
static void
@ -112,7 +112,7 @@ core_marshal_sync (void *object,
spa_pod_builder_struct (&b.b, &f,
SPA_POD_TYPE_INT, seq);
pinos_connection_end_write (connection, proxy->id, 1, b.b.offset);
pinos_connection_end_write (connection, proxy->id, PINOS_CORE_METHOD_SYNC, b.b.offset);
}
static void
@ -129,7 +129,7 @@ core_marshal_get_registry (void *object,
spa_pod_builder_struct (&b.b, &f,
SPA_POD_TYPE_INT, new_id);
pinos_connection_end_write (connection, proxy->id, 2, b.b.offset);
pinos_connection_end_write (connection, proxy->id, PINOS_CORE_METHOD_GET_REGISTRY, b.b.offset);
}
static void
@ -165,7 +165,7 @@ core_marshal_create_node (void *object,
SPA_POD_TYPE_INT, new_id,
-SPA_POD_TYPE_STRUCT, &f, 0);
pinos_connection_end_write (connection, proxy->id, 3, b.b.offset);
pinos_connection_end_write (connection, proxy->id, PINOS_CORE_METHOD_CREATE_NODE, b.b.offset);
}
static void
@ -199,7 +199,7 @@ core_marshal_create_client_node (void *object,
SPA_POD_TYPE_INT, new_id,
-SPA_POD_TYPE_STRUCT, &f, 0);
pinos_connection_end_write (connection, proxy->id, 4, b.b.offset);
pinos_connection_end_write (connection, proxy->id, PINOS_CORE_METHOD_CREATE_CLIENT_NODE, b.b.offset);
}
static void
@ -226,7 +226,7 @@ core_marshal_update_types (void *object,
spa_pod_builder_add (&b.b,
-SPA_POD_TYPE_STRUCT, &f, 0);
pinos_connection_end_write (connection, proxy->id, 5, b.b.offset);
pinos_connection_end_write (connection, proxy->id, PINOS_CORE_METHOD_UPDATE_TYPES, b.b.offset);
}
static bool
@ -467,7 +467,7 @@ client_node_marshal_update (void *object,
SPA_POD_TYPE_INT, max_output_ports,
SPA_POD_TYPE_POD, props);
pinos_connection_end_write (connection, proxy->id, 0, b.b.offset);
pinos_connection_end_write (connection, proxy->id, PINOS_CLIENT_NODE_METHOD_UPDATE, b.b.offset);
}
static void
@ -532,7 +532,7 @@ client_node_marshal_port_update (void *object,
}
spa_pod_builder_add (&b.b, -SPA_POD_TYPE_STRUCT, &f[0], 0);
pinos_connection_end_write (connection, proxy->id, 1, b.b.offset);
pinos_connection_end_write (connection, proxy->id, PINOS_CLIENT_NODE_METHOD_PORT_UPDATE, b.b.offset);
}
static void
@ -549,7 +549,7 @@ client_node_marshal_event (void *object,
spa_pod_builder_struct (&b.b, &f,
SPA_POD_TYPE_POD, event);
pinos_connection_end_write (connection, proxy->id, 2, b.b.offset);
pinos_connection_end_write (connection, proxy->id, PINOS_CLIENT_NODE_METHOD_EVENT, b.b.offset);
}
static void
@ -564,7 +564,7 @@ client_node_marshal_destroy (void *object)
spa_pod_builder_struct (&b.b, &f, 0);
pinos_connection_end_write (connection, proxy->id, 3, b.b.offset);
pinos_connection_end_write (connection, proxy->id, PINOS_CLIENT_NODE_METHOD_DESTROY, b.b.offset);
}
static bool
@ -983,7 +983,7 @@ registry_marshal_bind (void *object,
SPA_POD_TYPE_INT, id,
SPA_POD_TYPE_INT, new_id);
pinos_connection_end_write (connection, proxy->id, 0, b.b.offset);
pinos_connection_end_write (connection, proxy->id, PINOS_REGISTRY_METHOD_BIND, b.b.offset);
}
static const PinosCoreMethods pinos_protocol_native_client_core_methods = {
@ -1004,8 +1004,8 @@ static const PinosDemarshalFunc pinos_protocol_native_client_core_demarshal[] =
};
static const PinosInterface pinos_protocol_native_client_core_interface = {
6, &pinos_protocol_native_client_core_methods,
5, pinos_protocol_native_client_core_demarshal
PINOS_CORE_METHOD_NUM, &pinos_protocol_native_client_core_methods,
PINOS_CORE_EVENT_NUM, pinos_protocol_native_client_core_demarshal
};
static const PinosRegistryMethods pinos_protocol_native_client_registry_methods = {
@ -1018,8 +1018,8 @@ static const PinosDemarshalFunc pinos_protocol_native_client_registry_demarshal[
};
static const PinosInterface pinos_protocol_native_client_registry_interface = {
1, &pinos_protocol_native_client_registry_methods,
2, pinos_protocol_native_client_registry_demarshal,
PINOS_REGISTRY_METHOD_NUM, &pinos_protocol_native_client_registry_methods,
PINOS_REGISTRY_EVENT_NUM, pinos_protocol_native_client_registry_demarshal,
};
static const PinosClientNodeMethods pinos_protocol_native_client_client_node_methods = {
@ -1044,8 +1044,8 @@ static const PinosDemarshalFunc pinos_protocol_native_client_client_node_demarsh
};
static const PinosInterface pinos_protocol_native_client_client_node_interface = {
4, &pinos_protocol_native_client_client_node_methods,
11, pinos_protocol_native_client_client_node_demarshal,
PINOS_CLIENT_NODE_METHOD_NUM, &pinos_protocol_native_client_client_node_methods,
PINOS_CLIENT_NODE_EVENT_NUM, pinos_protocol_native_client_client_node_demarshal,
};
static const PinosDemarshalFunc pinos_protocol_native_client_module_demarshal[] = {
@ -1054,7 +1054,7 @@ static const PinosDemarshalFunc pinos_protocol_native_client_module_demarshal[]
static const PinosInterface pinos_protocol_native_client_module_interface = {
0, NULL,
1, pinos_protocol_native_client_module_demarshal,
PINOS_MODULE_EVENT_NUM, pinos_protocol_native_client_module_demarshal,
};
static const PinosDemarshalFunc pinos_protocol_native_client_node_demarshal[] = {
@ -1063,7 +1063,7 @@ static const PinosDemarshalFunc pinos_protocol_native_client_node_demarshal[] =
static const PinosInterface pinos_protocol_native_client_node_interface = {
0, NULL,
1, pinos_protocol_native_client_node_demarshal,
PINOS_NODE_EVENT_NUM, pinos_protocol_native_client_node_demarshal,
};
static const PinosDemarshalFunc pinos_protocol_native_client_client_demarshal[] = {
@ -1072,7 +1072,7 @@ static const PinosDemarshalFunc pinos_protocol_native_client_client_demarshal[]
static const PinosInterface pinos_protocol_native_client_client_interface = {
0, NULL,
1, pinos_protocol_native_client_client_demarshal,
PINOS_CLIENT_EVENT_NUM, pinos_protocol_native_client_client_demarshal,
};
static const PinosDemarshalFunc pinos_protocol_native_client_link_demarshal[] = {
@ -1081,7 +1081,7 @@ static const PinosDemarshalFunc pinos_protocol_native_client_link_demarshal[] =
static const PinosInterface pinos_protocol_native_client_link_interface = {
0, NULL,
1, pinos_protocol_native_client_link_demarshal,
PINOS_LINK_EVENT_NUM, pinos_protocol_native_client_link_demarshal,
};
bool

View file

@ -34,97 +34,60 @@ typedef struct {
PinosListener check_dispatch;
} ModuleImpl;
#if 0
static bool
check_global_owner (PinosCore *core,
PinosClient *client,
uint32_t id)
PinosGlobal *global)
{
PinosGlobal *global;
pinos_log_debug ("%p", global);
global = pinos_map_lookup (&core->objects, id);
if (global == NULL)
return false;
pinos_log_debug ("%p", global->owner);
if (global->owner == NULL)
return true;
pinos_log_debug ("%d %d", global->owner->ucred.uid, client->ucred.uid);
if (global->owner->ucred.uid == client->ucred.uid)
return true;
return false;
}
#endif
static void
do_check_send (PinosListener *listener,
PinosAccessFunc func,
PinosAccessData *data)
static SpaResult
do_check_global (PinosAccess *access,
PinosClient *client,
PinosGlobal *global)
{
PinosClient *client = data->client;
PinosCore *core = client->core;
if (global->type == client->core->type.link) {
PinosLink *link = global->object;
if (data->resource->type == core->type.registry) {
#if 0
switch (data->opcode) {
case 0:
pinos_log_debug ("link %p: global %p %p %p %p", link, global->owner, client, link->output, link->input);
/* we must be able to see both nodes */
if (link->output && !check_global_owner (client->core, client, link->output->node->global))
return SPA_RESULT_ERROR;
pinos_log_debug ("link %p: global %p %p %p %p", link, global->owner, client, link->output, link->input);
if (link->input && !check_global_owner (client->core, client, link->input->node->global))
return SPA_RESULT_ERROR;
pinos_log_debug ("link %p: global %p %p %p %p", link, global->owner, client, link->output, link->input);
}
else if (!check_global_owner (client->core, client, global))
return SPA_RESULT_ERROR;
return SPA_RESULT_OK;
}
static PinosAccess access_checks =
{
PinosMessageNotifyGlobal *m = data->message;
if (check_global_owner (core, client, m->id))
data->res = SPA_RESULT_OK;
else
data->res = SPA_RESULT_SKIPPED;
break;
}
case 1:
{
PinosMessageNotifyGlobalRemove *m = data->message;
if (check_global_owner (core, client, m->id))
data->res = SPA_RESULT_OK;
else
data->res = SPA_RESULT_SKIPPED;
break;
}
default:
data->res = SPA_RESULT_NO_PERMISSION;
break;
}
#endif
}
else {
data->res = SPA_RESULT_OK;
}
}
static void
do_check_dispatch (PinosListener *listener,
PinosAccessFunc func,
PinosAccessData *data)
{
PinosClient *client = data->client;
PinosCore *core = client->core;
if (data->resource->type == core->type.registry) {
#if 0
if (data->opcode == 0) {
PinosMessageBind *m = data->message;
if (check_global_owner (core, client, m->id))
data->res = SPA_RESULT_OK;
else
data->res = SPA_RESULT_NO_PERMISSION;
} else {
data->res = SPA_RESULT_NO_PERMISSION;
}
#endif
}
else {
data->res = SPA_RESULT_OK;
}
}
do_check_global,
};
static ModuleImpl *
module_new (PinosCore *core,
@ -138,12 +101,7 @@ module_new (PinosCore *core,
impl->core = core;
impl->properties = properties;
pinos_signal_add (&core->access.check_send,
&impl->check_send,
do_check_send);
pinos_signal_add (&core->access.check_dispatch,
&impl->check_dispatch,
do_check_dispatch);
core->access = &access_checks;
return impl;
}

View file

@ -110,6 +110,7 @@ make_node (ModuleImpl *impl)
spa_clock = iface;
node = pinos_node_new (impl->core,
NULL,
"audiomixer",
false,
spa_node,

View file

@ -183,7 +183,7 @@ client_new (PinosProtocolNative *impl,
this->fd = fd;
this->source = pinos_loop_add_io (impl->core->main_loop->loop,
this->fd,
SPA_IO_IN | SPA_IO_ERR | SPA_IO_HUP,
SPA_IO_ERR | SPA_IO_HUP,
false,
connection_data,
this);
@ -336,6 +336,7 @@ socket_data (SpaSource *source,
void *data)
{
PinosProtocolNative *impl = data;
PinosProtocolNativeClient *client;
struct sockaddr_un name;
socklen_t length;
int client_fd;
@ -347,11 +348,16 @@ socket_data (SpaSource *source,
return;
}
if (client_new (impl, client_fd) == NULL) {
client = client_new (impl, client_fd);
if (client == NULL) {
pinos_log_error ("failed to create client");
close (client_fd);
return;
}
pinos_loop_update_io (impl->core->main_loop->loop,
client->source,
SPA_IO_IN | SPA_IO_ERR | SPA_IO_HUP);
}
static bool

View file

@ -112,6 +112,7 @@ add_item (PinosSpaMonitor *this, SpaMonitorItem *item)
mitem = calloc (1, sizeof (PinosSpaMonitorItem));
mitem->id = strdup (id);
mitem->node = pinos_node_new (impl->core,
NULL,
name,
false,
node_iface,

View file

@ -112,6 +112,7 @@ pinos_spa_node_load (PinosCore *core,
}
this->node = pinos_node_new (core,
NULL,
name,
false,
spa_node,

View file

@ -18,10 +18,3 @@
*/
#include "pinos/server/core.h"
void
pinos_access_init (PinosAccess *access)
{
pinos_signal_init (&access->check_send);
pinos_signal_init (&access->check_dispatch);
}

View file

@ -30,20 +30,18 @@ extern "C" {
#include <pinos/client/sig.h>
typedef struct _PinosAccess PinosAccess;
typedef struct _PinosAccessData PinosAccessData;
#include <pinos/server/client.h>
#include <pinos/server/resource.h>
typedef struct {
struct _PinosAccessData {
SpaResult res;
PinosClient *client;
PinosResource *resource;
uint32_t opcode;
void *message;
bool flush;
} PinosAccessData;
void (*complete_cb) (PinosAccessData *data);
void (*cancel_cb) (PinosAccessData *data);
void *user_data;
};
typedef SpaResult (*PinosAccessFunc) (PinosAccessData *data);
/**
* PinosAccess:
@ -51,16 +49,11 @@ typedef SpaResult (*PinosAccessFunc) (PinosAccessData *data);
* Pinos Access support struct.
*/
struct _PinosAccess {
PINOS_SIGNAL (check_send, (PinosListener *listener,
PinosAccessFunc func,
PinosAccessData *data));
PINOS_SIGNAL (check_dispatch, (PinosListener *listener,
PinosAccessFunc func,
PinosAccessData *data));
SpaResult (*check_global) (PinosAccess *access,
PinosClient *client,
PinosGlobal *global);
};
void pinos_access_init (PinosAccess *access);
#ifdef __cplusplus
}
#endif

View file

@ -1177,6 +1177,7 @@ pinos_client_node_new (PinosClient *client,
proxy_init (&impl->proxy, NULL, client->core->support, client->core->n_support);
this->node = pinos_node_new (client->core,
client,
name,
true,
&impl->proxy.node,

View file

@ -111,12 +111,13 @@ pinos_client_new (PinosCore *core,
spa_list_insert (core->client_list.prev, &this->link);
this->global = pinos_core_add_global (core,
pinos_core_add_global (core,
this,
core->type.client,
0,
this,
client_bind_func);
client_bind_func,
&this->global);
this->info.id = this->global->id;
this->info.props = this->properties ? &this->properties->dict : NULL;

View file

@ -38,6 +38,10 @@ typedef struct {
} PinosCoreImpl;
#define ACCESS_CHECK_GLOBAL(client,global) (client->core->access && \
client->core->access->check_global (client->core->access, \
client, global) == SPA_RESULT_OK)
static void
registry_bind (void *object,
uint32_t id,
@ -55,6 +59,9 @@ registry_bind (void *object,
if (&global->link == &core->global_list)
goto no_id;
if (!ACCESS_CHECK_GLOBAL (client, global))
goto no_id;
pinos_log_debug ("global %p: bind object id %d to %d", global, id, new_id);
pinos_global_bind (global, client, 0, new_id);
@ -121,10 +128,12 @@ core_get_registry (void *object,
spa_list_insert (this->registry_resource_list.prev, &registry_resource->link);
spa_list_for_each (global, &this->global_list, link)
spa_list_for_each (global, &this->global_list, link) {
if (ACCESS_CHECK_GLOBAL (client, global))
pinos_registry_notify_global (registry_resource,
global->id,
spa_type_map_get_type (this->type.map, global->type));
}
return;
@ -291,7 +300,6 @@ pinos_core_new (PinosMainLoop *main_loop,
this->properties = properties;
pinos_type_init (&this->type);
pinos_access_init (&this->access);
pinos_map_init (&this->objects, 128, 32);
impl->support[0].type = SPA_TYPE__TypeMap;
@ -318,12 +326,13 @@ pinos_core_new (PinosMainLoop *main_loop,
pinos_signal_init (&this->global_added);
pinos_signal_init (&this->global_removed);
this->global = pinos_core_add_global (this,
pinos_core_add_global (this,
NULL,
this->type.core,
0,
this,
core_bind_func);
core_bind_func,
&this->global);
this->info.id = this->global->id;
this->info.change_mask = 0;
@ -358,13 +367,14 @@ pinos_core_destroy (PinosCore *core)
free (impl);
}
PinosGlobal *
bool
pinos_core_add_global (PinosCore *core,
PinosClient *owner,
uint32_t type,
uint32_t version,
void *object,
PinosBindFunc bind)
PinosBindFunc bind,
PinosGlobal **global)
{
PinosGlobalImpl *impl;
PinosGlobal *this;
@ -373,7 +383,7 @@ pinos_core_add_global (PinosCore *core,
impl = calloc (1, sizeof (PinosGlobalImpl));
if (impl == NULL)
return NULL;
return false;
this = &impl->this;
impl->bind = bind;
@ -383,6 +393,7 @@ pinos_core_add_global (PinosCore *core,
this->type = type;
this->version = version;
this->object = object;
*global = this;
pinos_signal_init (&this->destroy_signal);
@ -392,14 +403,15 @@ pinos_core_add_global (PinosCore *core,
pinos_signal_emit (&core->global_added, core, this);
type_name = spa_type_map_get_type (core->type.map, this->type);
pinos_log_debug ("global %p: new %u %s", this, this->id, type_name);
pinos_log_debug ("global %p: new %u %s, owner %p", this, this->id, type_name, owner);
spa_list_for_each (registry, &core->registry_resource_list, link)
if (ACCESS_CHECK_GLOBAL (registry->client, this))
pinos_registry_notify_global (registry,
this->id,
type_name);
return this;
return true;
}
SpaResult
@ -433,6 +445,7 @@ pinos_global_destroy (PinosGlobal *global)
pinos_signal_emit (&global->destroy_signal, global);
spa_list_for_each (registry, &core->registry_resource_list, link)
if (ACCESS_CHECK_GLOBAL (registry->client, global))
pinos_registry_notify_global_remove (registry, global->id);
pinos_map_remove (&core->objects, global->id);

View file

@ -69,7 +69,7 @@ struct _PinosCore {
PinosProperties *properties;
PinosType type;
PinosAccess access;
PinosAccess *access;
PinosMap objects;
@ -105,12 +105,13 @@ void pinos_core_destroy (PinosCore *core);
void pinos_core_update_properties (PinosCore *core,
const SpaDict *dict);
PinosGlobal * pinos_core_add_global (PinosCore *core,
bool pinos_core_add_global (PinosCore *core,
PinosClient *owner,
uint32_t type,
uint32_t version,
void *object,
PinosBindFunc bind);
PinosBindFunc bind,
PinosGlobal **global);
SpaResult pinos_global_bind (PinosGlobal *global,
PinosClient *client,

View file

@ -891,12 +891,13 @@ pinos_link_new (PinosCore *core,
spa_list_insert (core->link_list.prev, &this->link);
this->global = pinos_core_add_global (core,
pinos_core_add_global (core,
NULL,
core->type.link,
0,
this,
link_bind_func);
link_bind_func,
&this->global);
return this;
}

View file

@ -192,12 +192,13 @@ pinos_module_load (PinosCore *core,
if (!init_func (this, (char *) args))
goto init_failed;
this->global = pinos_core_add_global (core,
pinos_core_add_global (core,
NULL,
core->type.module,
0,
impl,
module_bind_func);
module_bind_func,
&this->global);
this->info.id = this->global->id;
this->info.name = name ? strdup (name) : NULL;

View file

@ -485,15 +485,16 @@ init_complete (PinosNode *this)
pinos_log_debug ("node %p: init completed", this);
impl->async_init = false;
pinos_node_update_state (this, PINOS_NODE_STATE_SUSPENDED, NULL);
spa_list_insert (this->core->node_list.prev, &this->link);
this->global = pinos_core_add_global (this->core,
NULL,
pinos_core_add_global (this->core,
this->owner,
this->core->type.node,
0,
this,
node_bind_func);
node_bind_func,
&this->global);
pinos_node_update_state (this, PINOS_NODE_STATE_SUSPENDED, NULL);
}
void
@ -506,6 +507,7 @@ pinos_node_set_data_loop (PinosNode *node,
PinosNode *
pinos_node_new (PinosCore *core,
PinosClient *owner,
const char *name,
bool async,
SpaNode *node,
@ -521,7 +523,8 @@ pinos_node_new (PinosCore *core,
this = &impl->this;
this->core = core;
pinos_log_debug ("node %p: new", this);
this->owner = owner;
pinos_log_debug ("node %p: new, owner %p", this, owner);
impl->work = pinos_work_queue_new (this->core->main_loop->loop);

View file

@ -51,6 +51,7 @@ struct _PinosNode {
SpaList link;
PinosGlobal *global;
PinosClient *owner;
char *name;
PinosProperties *properties;
PinosNodeState state;
@ -109,6 +110,7 @@ struct _PinosNode {
};
PinosNode * pinos_node_new (PinosCore *core,
PinosClient *owner,
const char *name,
bool async,
SpaNode *node,

View file

@ -101,7 +101,7 @@ core_marshal_info (void *object,
}
spa_pod_builder_add (&b.b, -SPA_POD_TYPE_STRUCT, &f, 0);
pinos_connection_end_write (connection, resource->id, 0, b.b.offset);
pinos_connection_end_write (connection, resource->id, PINOS_CORE_EVENT_INFO, b.b.offset);
}
static void
@ -118,7 +118,7 @@ core_marshal_done (void *object,
spa_pod_builder_struct (&b.b, &f,
SPA_POD_TYPE_INT, seq);
pinos_connection_end_write (connection, resource->id, 1, b.b.offset);
pinos_connection_end_write (connection, resource->id, PINOS_CORE_EVENT_DONE, b.b.offset);
}
static void
@ -145,7 +145,7 @@ core_marshal_error (void *object,
SPA_POD_TYPE_INT, res,
SPA_POD_TYPE_STRING, buffer);
pinos_connection_end_write (connection, resource->id, 2, b.b.offset);
pinos_connection_end_write (connection, resource->id, PINOS_CORE_EVENT_ERROR, b.b.offset);
}
static void
@ -162,7 +162,7 @@ core_marshal_remove_id (void *object,
spa_pod_builder_struct (&b.b, &f,
SPA_POD_TYPE_INT, id);
pinos_connection_end_write (connection, resource->id, 3, b.b.offset);
pinos_connection_end_write (connection, resource->id, PINOS_CORE_EVENT_REMOVE_ID, b.b.offset);
}
static void
@ -189,7 +189,7 @@ core_marshal_update_types (void *object,
spa_pod_builder_add (&b.b,
-SPA_POD_TYPE_STRUCT, &f, 0);
pinos_connection_end_write (connection, resource->id, 4, b.b.offset);
pinos_connection_end_write (connection, resource->id, PINOS_CORE_EVENT_UPDATE_TYPES, b.b.offset);
}
static bool
@ -375,7 +375,7 @@ registry_marshal_global (void *object,
SPA_POD_TYPE_INT, id,
SPA_POD_TYPE_STRING, type);
pinos_connection_end_write (connection, resource->id, 0, b.b.offset);
pinos_connection_end_write (connection, resource->id, PINOS_REGISTRY_EVENT_GLOBAL, b.b.offset);
}
static void
@ -392,7 +392,7 @@ registry_marshal_global_remove (void *object,
spa_pod_builder_struct (&b.b, &f,
SPA_POD_TYPE_INT, id);
pinos_connection_end_write (connection, resource->id, 1, b.b.offset);
pinos_connection_end_write (connection, resource->id, PINOS_REGISTRY_EVENT_GLOBAL_REMOVE, b.b.offset);
}
static bool
@ -446,7 +446,7 @@ module_marshal_info (void *object,
}
spa_pod_builder_add (&b.b, -SPA_POD_TYPE_STRUCT, &f, 0);
pinos_connection_end_write (connection, resource->id, 0, b.b.offset);
pinos_connection_end_write (connection, resource->id, PINOS_MODULE_EVENT_INFO, b.b.offset);
}
static void
@ -495,7 +495,7 @@ node_marshal_info (void *object,
}
spa_pod_builder_add (&b.b, -SPA_POD_TYPE_STRUCT, &f, 0);
pinos_connection_end_write (connection, resource->id, 0, b.b.offset);
pinos_connection_end_write (connection, resource->id, PINOS_NODE_EVENT_INFO, b.b.offset);
}
static void
@ -525,7 +525,7 @@ client_marshal_info (void *object,
}
spa_pod_builder_add (&b.b, -SPA_POD_TYPE_STRUCT, &f, 0);
pinos_connection_end_write (connection, resource->id, 0, b.b.offset);
pinos_connection_end_write (connection, resource->id, PINOS_CLIENT_EVENT_INFO, b.b.offset);
}
static void
@ -542,7 +542,7 @@ client_node_marshal_done (void *object,
spa_pod_builder_struct (&b.b, &f,
SPA_POD_TYPE_INT, pinos_connection_add_fd (connection, datafd));
pinos_connection_end_write (connection, resource->id, 0, b.b.offset);
pinos_connection_end_write (connection, resource->id, PINOS_CLIENT_NODE_EVENT_DONE, b.b.offset);
}
static void
@ -559,7 +559,7 @@ client_node_marshal_event (void *object,
spa_pod_builder_struct (&b.b, &f,
SPA_POD_TYPE_POD, event);
pinos_connection_end_write (connection, resource->id, 1, b.b.offset);
pinos_connection_end_write (connection, resource->id, PINOS_CLIENT_NODE_EVENT_EVENT, b.b.offset);
}
static void
@ -580,7 +580,7 @@ client_node_marshal_add_port (void *object,
SPA_POD_TYPE_INT, direction,
SPA_POD_TYPE_INT, port_id);
pinos_connection_end_write (connection, resource->id, 2, b.b.offset);
pinos_connection_end_write (connection, resource->id, PINOS_CLIENT_NODE_EVENT_ADD_PORT, b.b.offset);
}
static void
@ -601,7 +601,7 @@ client_node_marshal_remove_port (void *object,
SPA_POD_TYPE_INT, direction,
SPA_POD_TYPE_INT, port_id);
pinos_connection_end_write (connection, resource->id, 3, b.b.offset);
pinos_connection_end_write (connection, resource->id, PINOS_CLIENT_NODE_EVENT_REMOVE_PORT, b.b.offset);
}
static void
@ -626,7 +626,7 @@ client_node_marshal_set_format (void *object,
SPA_POD_TYPE_INT, flags,
SPA_POD_TYPE_POD, format);
pinos_connection_end_write (connection, resource->id, 4, b.b.offset);
pinos_connection_end_write (connection, resource->id, PINOS_CLIENT_NODE_EVENT_SET_FORMAT, b.b.offset);
}
static void
@ -648,7 +648,7 @@ client_node_marshal_set_property (void *object,
SPA_POD_TYPE_INT, id,
SPA_POD_TYPE_BYTES, value, size);
pinos_connection_end_write (connection, resource->id, 5, b.b.offset);
pinos_connection_end_write (connection, resource->id, PINOS_CLIENT_NODE_EVENT_SET_PROPERTY, b.b.offset);
}
static void
@ -679,7 +679,7 @@ client_node_marshal_add_mem (void *object,
SPA_POD_TYPE_INT, offset,
SPA_POD_TYPE_INT, size);
pinos_connection_end_write (connection, resource->id, 6, b.b.offset);
pinos_connection_end_write (connection, resource->id, PINOS_CLIENT_NODE_EVENT_ADD_MEM, b.b.offset);
}
static void
@ -734,7 +734,7 @@ client_node_marshal_use_buffers (void *object,
}
spa_pod_builder_add (&b.b, -SPA_POD_TYPE_STRUCT, &f, 0);
pinos_connection_end_write (connection, resource->id, 7, b.b.offset);
pinos_connection_end_write (connection, resource->id, PINOS_CLIENT_NODE_EVENT_USE_BUFFERS, b.b.offset);
}
static void
@ -753,7 +753,7 @@ client_node_marshal_node_command (void *object,
SPA_POD_TYPE_INT, seq,
SPA_POD_TYPE_POD, command);
pinos_connection_end_write (connection, resource->id, 8, b.b.offset);
pinos_connection_end_write (connection, resource->id, PINOS_CLIENT_NODE_EVENT_NODE_COMMAND, b.b.offset);
}
static void
@ -772,7 +772,7 @@ client_node_marshal_port_command (void *object,
SPA_POD_TYPE_INT, port_id,
SPA_POD_TYPE_POD, command);
pinos_connection_end_write (connection, resource->id, 9, b.b.offset);
pinos_connection_end_write (connection, resource->id, PINOS_CLIENT_NODE_EVENT_PORT_COMMAND, b.b.offset);
}
static void
@ -793,7 +793,7 @@ client_node_marshal_transport (void *object,
SPA_POD_TYPE_INT, offset,
SPA_POD_TYPE_INT, size);
pinos_connection_end_write (connection, resource->id, 10, b.b.offset);
pinos_connection_end_write (connection, resource->id, PINOS_CLIENT_NODE_EVENT_TRANSPORT, b.b.offset);
}
static bool
@ -949,7 +949,7 @@ link_marshal_info (void *object,
SPA_POD_TYPE_INT, info->input_node_id,
SPA_POD_TYPE_INT, info->input_port_id);
pinos_connection_end_write (connection, resource->id, 0, b.b.offset);
pinos_connection_end_write (connection, resource->id, PINOS_LINK_EVENT_INFO, b.b.offset);
}
static const PinosDemarshalFunc pinos_protocol_native_server_core_demarshal[] = {
@ -970,8 +970,8 @@ static const PinosCoreEvents pinos_protocol_native_server_core_events = {
};
const PinosInterface pinos_protocol_native_server_core_interface = {
6, pinos_protocol_native_server_core_demarshal,
5, &pinos_protocol_native_server_core_events,
PINOS_CORE_METHOD_NUM, pinos_protocol_native_server_core_demarshal,
PINOS_CORE_EVENT_NUM, &pinos_protocol_native_server_core_events,
};
static const PinosDemarshalFunc pinos_protocol_native_server_registry_demarshal[] = {
@ -984,8 +984,8 @@ static const PinosRegistryEvents pinos_protocol_native_server_registry_events =
};
const PinosInterface pinos_protocol_native_server_registry_interface = {
1, pinos_protocol_native_server_registry_demarshal,
2, &pinos_protocol_native_server_registry_events,
PINOS_REGISTRY_METHOD_NUM, pinos_protocol_native_server_registry_demarshal,
PINOS_REGISTRY_EVENT_NUM, &pinos_protocol_native_server_registry_events,
};
static const PinosModuleEvents pinos_protocol_native_server_module_events = {
@ -994,7 +994,7 @@ static const PinosModuleEvents pinos_protocol_native_server_module_events = {
const PinosInterface pinos_protocol_native_server_module_interface = {
0, NULL,
1, &pinos_protocol_native_server_module_events,
PINOS_MODULE_EVENT_NUM, &pinos_protocol_native_server_module_events,
};
static const PinosNodeEvents pinos_protocol_native_server_node_events = {
@ -1003,7 +1003,7 @@ static const PinosNodeEvents pinos_protocol_native_server_node_events = {
const PinosInterface pinos_protocol_native_server_node_interface = {
0, NULL,
1, &pinos_protocol_native_server_node_events,
PINOS_NODE_EVENT_NUM, &pinos_protocol_native_server_node_events,
};
static const PinosClientEvents pinos_protocol_native_server_client_events = {
@ -1012,7 +1012,7 @@ static const PinosClientEvents pinos_protocol_native_server_client_events = {
const PinosInterface pinos_protocol_native_server_client_interface = {
0, NULL,
2, &pinos_protocol_native_server_client_events,
PINOS_CLIENT_EVENT_NUM, &pinos_protocol_native_server_client_events,
};
static const PinosDemarshalFunc pinos_protocol_native_server_client_node_demarshal[] = {
@ -1037,8 +1037,8 @@ static const PinosClientNodeEvents pinos_protocol_native_server_client_node_even
};
const PinosInterface pinos_protocol_native_server_client_node_interface = {
4, &pinos_protocol_native_server_client_node_demarshal,
11, &pinos_protocol_native_server_client_node_events,
PINOS_CLIENT_NODE_METHOD_NUM, &pinos_protocol_native_server_client_node_demarshal,
PINOS_CLIENT_NODE_EVENT_NUM, &pinos_protocol_native_server_client_node_events,
};
static const PinosLinkEvents pinos_protocol_native_server_link_events = {
@ -1047,7 +1047,7 @@ static const PinosLinkEvents pinos_protocol_native_server_link_events = {
const PinosInterface pinos_protocol_native_server_link_interface = {
0, NULL,
1, &pinos_protocol_native_server_link_events,
PINOS_LINK_EVENT_NUM, &pinos_protocol_native_server_link_events,
};
bool