This source file includes following definitions.
- bus_endpoint_new
- bus_endpoint_add_policy
- bus_endpoint_free
#include <stdlib.h>
#include "bus-endpoint.h"
int bus_endpoint_new(BusEndpoint **ep)
{
assert(ep);
*ep = new0(BusEndpoint, 1);
if (!*ep)
return -ENOMEM;
return 0;
}
int bus_endpoint_add_policy(BusEndpoint *ep, const char *name, BusPolicyAccess access)
{
_cleanup_free_ BusEndpointPolicy *po = NULL;
_cleanup_free_ char *key = NULL;
int r;
assert(ep);
assert(name);
assert(access > _BUS_POLICY_ACCESS_INVALID && access < _BUS_POLICY_ACCESS_MAX);
if (ep->policy_hash) {
po = hashmap_get(ep->policy_hash, name);
if (po) {
if (po->access < access)
po->access = access;
return 0;
}
} else {
ep->policy_hash = hashmap_new(&string_hash_ops);
if (!ep->policy_hash)
return -ENOMEM;
}
po = new0(BusEndpointPolicy, 1);
if (!po)
return -ENOMEM;
key = strdup(name);
if (!key)
return -ENOMEM;
po->name = key;
po->access = access;
r = hashmap_put(ep->policy_hash, key, po);
if (r < 0)
return r;
po = NULL;
key = NULL;
return 0;
}
void bus_endpoint_free(BusEndpoint *endpoint)
{
if (!endpoint)
return;
hashmap_free_free_free(endpoint->policy_hash);
free(endpoint);
}