C Extension API
Native modules
Implement trusted native filters, join planners and deferred domain installers.Add trusted native filter and join-planning callbacks, or install domain declarations when a policy loads. The Modules guide applies these callbacks to document-access decisions and shows the required startup order.
Handle: domain_builder_t
#include <maelys/datalog_module.h>
typedef struct maelys_datalog_domain_builder maelys_datalog_domain_builder_t;Creation
domain_register_advanced()
#include <maelys/datalog_module.h>
maelys_datalog_status_t
maelys_datalog_domain_register_advanced(
const maelys_datalog_domain_t *domain,
const char *description,
maelys_datalog_domain_installer_t installer
);maelys_datalog_status_t — OK on success.
Returns OK after registration, including compatible repeat registration. Invalid argument combinations return INVALID_ARGUMENT; incompatible repeat registration returns INVALID_FIELD. Invalid declarations or a full bounded registry fail. Domains are process-global and are not isolated by explicit contexts.
maelys_datalog_status_t status = maelys_datalog_domain_register_advanced(&domain,
"Document access with a native file-suffix filter", install_document_predicates);
printf("status: %s\n", maelys_datalog_status_name(status));
check_status(status);status: ok
Functions
domain_builder_add()
#include <maelys/datalog_module.h>
maelys_datalog_status_t
maelys_datalog_domain_builder_add(
maelys_datalog_domain_builder_t *builder,
const maelys_datalog_predicate_t *predicate
);maelys_datalog_status_t — OK on success.
Returns OK after adding the declaration. A NULL builder or predicate, or invalid flag bits, returns INVALID_ARGUMENT; registry validation and capacity errors are propagated. The first builder failure remains sticky, so policy loading rejects the candidate even if the installer ignores that failure.
const maelys_datalog_predicate_t predicate = MAELYS_DATALOG_IDB_QUERY("allow", 2);
maelys_datalog_status_t status = maelys_datalog_domain_builder_add(builder, &predicate);
printf("status: %s\n", maelys_datalog_status_name(status));
check_status(status);
return status;status: ok
Type: domain_installer_t
#include <maelys/datalog_module.h>
Typedef
typedef maelys_datalog_status_t (*maelys_datalog_domain_installer_t)(maelys_datalog_domain_builder_t *builder);Type: filter_cost_fn
#include <maelys/datalog_module.h>
Typedef
typedef maelys_datalog_status_t (*maelys_datalog_filter_cost_fn)(size_t value_length,
size_t pattern_length,
size_t *out_cost);| Used by | filter_module_t — cost |
|---|
Type: filter_evaluate_fn
#include <maelys/datalog_module.h>
Typedef
typedef maelys_datalog_status_t (*maelys_datalog_filter_evaluate_fn)(const unsigned char *value,
size_t value_length,
const unsigned char *pattern,
size_t pattern_length,
int *out_matched);| Used by | filter_module_t — evaluate |
|---|
Struct: filter_module_t
#include <maelys/datalog_module.h>
Typedef
typedef struct maelys_datalog_filter_module_t {
uint32_t abi_version;
size_t struct_size;
const char *name; /* lower-case predicate identifier, max 63 bytes */
const char *semantic_id; /* ASCII letters/digits/dot/hyphen/underscore */
maelys_datalog_filter_validate_fn validate_pattern;
/* Conservative work bound, charged BEFORE evaluate; >= 1 for external
* filters. Overflow/unsupported inputs must return an error. */
maelys_datalog_filter_cost_fn cost;
maelys_datalog_filter_evaluate_fn evaluate;
} maelys_datalog_filter_module_t;Functions
register_filter_module()
#include <maelys/datalog_module.h>
maelys_datalog_status_t
maelys_datalog_register_filter_module(
const maelys_datalog_filter_module_t *module
);maelys_datalog_status_t — OK on success.
Returns OK after copying the descriptor. Invalid descriptors return INVALID_ARGUMENT; a duplicate name or semantic identity returns INVALID_FIELD; exceeding the additional-filter capacity returns PAYLOAD_TOO_LARGE. Registration after the module registry is sealed returns INVALID_STATE.
maelys_datalog_status_t status = maelys_datalog_register_filter_module(&suffix_module);
printf("status: %s\n", maelys_datalog_status_name(status));
check_status(status);status: ok
Constants
Module contract
MODULE_ABI_VERSION
#define MAELYS_DATALOG_MODULE_ABI_VERSION 1uABI version required by native filter and join-planner descriptors.
1
MODULE_NAME_BYTES
#define MAELYS_DATALOG_MODULE_NAME_BYTES 64uStorage size for a module name, including its terminating NUL.
64
MODULE_SEMANTIC_ID_BYTES
#define MAELYS_DATALOG_MODULE_SEMANTIC_ID_BYTES 128uStorage size for a semantic identity, including its terminating NUL.
128
MODULE_MAX_FILTERS
#define MAELYS_DATALOG_MODULE_MAX_FILTERS 16u /* additional to standard filters */Maximum number of external filters in addition to the standard filters.
16
Type: filter_validate_fn
#include <maelys/datalog_module.h>
Typedef
typedef maelys_datalog_status_t (*maelys_datalog_filter_validate_fn)(const unsigned char *pattern,
size_t pattern_length);Struct: join_candidate_t
#include <maelys/datalog_module.h>
Typedef
typedef struct {
size_t body_index;
maelys_datalog_join_kind_t kind;
const char *predicate_name;
unsigned predicate_flags;
size_t arity;
uint64_t variable_mask;
uint64_t bound_variable_mask;
size_t constant_terms;
size_t bound_terms;
int64_t default_score;
} maelys_datalog_join_candidate_t;Type: join_choose_fn
#include <maelys/datalog_module.h>
Typedef
typedef maelys_datalog_status_t (*maelys_datalog_join_choose_fn)(
const maelys_datalog_join_candidate_t *candidates, size_t candidate_count,
size_t *out_candidate_index);| Used by | planner_module_t — choose |
|---|
Enum: join_kind_t
#include <maelys/datalog_module.h>
Typedef
typedef enum {
MAELYS_DATALOG_JOIN_ATOM = 1,
MAELYS_DATALOG_JOIN_COMPARISON = 2,
MAELYS_DATALOG_JOIN_NEGATED_ATOM = 3,
MAELYS_DATALOG_JOIN_FILTER = 4
} maelys_datalog_join_kind_t;| Used by | join_candidate_t — kind |
|---|
Struct: planner_module_t
#include <maelys/datalog_module.h>
Typedef
typedef struct maelys_datalog_planner_module_t {
uint32_t abi_version;
size_t struct_size;
const char *name;
const char *semantic_id;
maelys_datalog_join_choose_fn choose;
} maelys_datalog_planner_module_t;Functions
register_planner_module()
#include <maelys/datalog_module.h>
maelys_datalog_status_t
maelys_datalog_register_planner_module(
const maelys_datalog_planner_module_t *module
);maelys_datalog_status_t — OK on success.
Returns OK after copying the descriptor. Invalid descriptors return INVALID_ARGUMENT. A planner already registered, or registration after the module registry is sealed, returns INVALID_STATE.
maelys_datalog_status_t status = maelys_datalog_register_planner_module(&planner_module);
printf("status: %s\n", maelys_datalog_status_name(status));
check_status(status);status: ok