C API
Domain
Declare and register a closed domain through the stable opaque C API.Declarations from <maelys/datalog.h> and its optional C11 builders <maelys/datalog_builders.h>. For explanations and complete examples, see the Registries guide.
| Used by | domain_register_advanced() |
|---|
Struct: domain_t
#include <maelys/datalog.h>
Typedef
typedef struct {
const char *name;
const maelys_datalog_predicate_t *predicates;
size_t predicate_count;
const char *const *atoms;
size_t atom_count;
} maelys_datalog_domain_t;/* predicates is the document-access declaration array in the Registries guide. */
const maelys_datalog_domain_t domain = {
"documents", predicates,
sizeof(predicates) / sizeof(predicates[0]), NULL, 0u,
};
printf("domain: %s\n", domain.name);
printf("predicates: %zu, atoms: %zu\n", domain.predicate_count, domain.atom_count);domain: documents predicates: 7, atoms: 0
Creation
DOMAIN_NO_ATOMS()
#include <maelys/datalog_builders.h>
MAELYS_DATALOG_DOMAIN_NO_ATOMS(
name,
predicates
)Declares a domain when policy source contains no quoted symbolic constants.
Uses sizeof to count the predicate array and declares zero policy-source atoms. Registration remains a separate call.
const maelys_datalog_domain_t domain =
MAELYS_DATALOG_DOMAIN_NO_ATOMS("documents", predicates);
printf("domain: %s\n", domain.name);
printf("predicates: %zu, atoms: %zu\n", domain.predicate_count, domain.atom_count);domain: documents predicates: 7, atoms: 0
DOMAIN_WITH_ATOMS()
#include <maelys/datalog_builders.h>
MAELYS_DATALOG_DOMAIN_WITH_ATOMS(
name,
predicates,
atoms
)Declares a domain with an explicit array of allowed policy-source atoms.
Uses sizeof to count both arrays. It declares allowed policy-source atoms but does not add facts or register the domain.
const char *const atoms[] = {"mallory"};
const maelys_datalog_domain_t domain =
MAELYS_DATALOG_DOMAIN_WITH_ATOMS("documents", predicates, atoms);
printf("domain: %s\n", domain.name);
printf("predicates: %zu, atoms: %zu\n", domain.predicate_count, domain.atom_count);domain: documents predicates: 7, atoms: 1
Functions
domain_register()
Register a domain.
#include <maelys/datalog.h>
maelys_datalog_status_t
maelys_datalog_domain_register(
const maelys_datalog_domain_t *domain
);maelys_datalog_status_t — OK on success.
A public error status on failure. Do not load a policy for a domain whose registration failed.
/* domain contains the document-access declarations in the Registries guide. */
maelys_datalog_status_t status = maelys_datalog_domain_register(&domain);
printf("status: %s\n", maelys_datalog_status_name(status));
check_status(status);
/* Load a policy only after registration succeeds. */status: ok
Struct: predicate_t
#include <maelys/datalog.h>
Typedef
typedef struct {
const char *name;
size_t arity;
unsigned flags;
} maelys_datalog_predicate_t;const maelys_datalog_predicate_t owns = {
"owns", 2u, MAELYS_DATALOG_PREDICATE_EDB,
};
printf("predicate: %s\n", owns.name);
printf("arity: %zu, flags: 0x%x\n", owns.arity, owns.flags);predicate: owns arity: 2, flags: 0x1
Creation
EDB()
#include <maelys/datalog_builders.h>
MAELYS_DATALOG_EDB(
name,
arity
)Declares a runtime-input predicate.
Constructs a predicate declaration with EDB origin. It does not insert a fact or register the domain.
static const maelys_datalog_predicate_t predicates[] = {
MAELYS_DATALOG_EDB("owns", 2),
};
printf("predicate: %s\n", predicates[0].name);
printf("arity: %zu, flags: 0x%x\n", predicates[0].arity, predicates[0].flags);predicate: owns arity: 2, flags: 0x1
EDB_QUERY()
#include <maelys/datalog_builders.h>
MAELYS_DATALOG_EDB_QUERY(
name,
arity
)Declares a runtime-input predicate that may also be queried.
Constructs an EDB-origin declaration with query permission. It does not insert or query a fact.
static const maelys_datalog_predicate_t predicates[] = {
MAELYS_DATALOG_EDB_QUERY("owns", 2),
};
printf("predicate: %s\n", predicates[0].name);
printf("arity: %zu, flags: 0x%x\n", predicates[0].arity, predicates[0].flags);predicate: owns arity: 2, flags: 0x5
IDB()
#include <maelys/datalog_builders.h>
MAELYS_DATALOG_IDB(
name,
arity
)Declares a relation derived by policy rules.
Constructs an IDB-origin declaration for rule-derived facts. It does not evaluate rules.
static const maelys_datalog_predicate_t predicates[] = {
MAELYS_DATALOG_IDB("can_read", 2),
};
printf("predicate: %s\n", predicates[0].name);
printf("arity: %zu, flags: 0x%x\n", predicates[0].arity, predicates[0].flags);predicate: can_read arity: 2, flags: 0x2
IDB_QUERY()
#include <maelys/datalog_builders.h>
MAELYS_DATALOG_IDB_QUERY(
name,
arity
)Declares a derived relation that may also be queried.
Constructs an IDB-origin declaration with query permission. It does not run a query.
static const maelys_datalog_predicate_t predicates[] = {
MAELYS_DATALOG_IDB_QUERY("allow", 2),
};
printf("predicate: %s\n", predicates[0].name);
printf("arity: %zu, flags: 0x%x\n", predicates[0].arity, predicates[0].flags);predicate: allow arity: 2, flags: 0x6
POLICY_FACT()
#include <maelys/datalog_builders.h>
MAELYS_DATALOG_POLICY_FACT(
name,
arity
)Declares a predicate whose ground facts come from policy source.
Constructs a POLICY_FACT-origin declaration. The policy source supplies its facts when loaded.
static const maelys_datalog_predicate_t predicates[] = {
MAELYS_DATALOG_POLICY_FACT("trusted", 1),
};
printf("predicate: %s\n", predicates[0].name);
printf("arity: %zu, flags: 0x%x\n", predicates[0].arity, predicates[0].flags);predicate: trusted arity: 1, flags: 0x8
POLICY_FACT_QUERY()
#include <maelys/datalog_builders.h>
MAELYS_DATALOG_POLICY_FACT_QUERY(
name,
arity
)Declares policy-source facts that may also be queried.
Constructs a POLICY_FACT-origin declaration with query permission. It does not add a source fact.
static const maelys_datalog_predicate_t predicates[] = {
MAELYS_DATALOG_POLICY_FACT_QUERY("trusted", 1),
};
printf("predicate: %s\n", predicates[0].name);
printf("arity: %zu, flags: 0x%x\n", predicates[0].arity, predicates[0].flags);predicate: trusted arity: 1, flags: 0xc
Enum: predicate_flags_t
#include <maelys/datalog.h>
Typedef
typedef enum {
MAELYS_DATALOG_PREDICATE_EDB = 1u << 0,
MAELYS_DATALOG_PREDICATE_IDB = 1u << 1,
MAELYS_DATALOG_PREDICATE_QUERY = 1u << 2,
MAELYS_DATALOG_PREDICATE_POLICY_FACT = 1u << 3
} maelys_datalog_predicate_flags_t;| Used by | predicate_t — flags |
|---|