ARPA2 Common Libraries  2.6.2
rules.h
1 
45 /* SPDX-FileCopyrightText: Copyright 2021 Rick van Rein <rick@openfortress.nl>
46  * SPDX-License-Identifier: BSD-2-Clause
47  */
48 
49 
50 #ifndef ARPA2_RULES_H
51 #define ARPA2_RULES_H
52 
53 
54 #include <stdbool.h>
55 #include <stdint.h>
56 
57 #include <arpa2/identity.h>
58 
59 
60 #ifdef __cplusplus
61 extern "C" {
62 #endif
63 
64 
99 typedef char *rules_domain;
100 
101 
134 typedef uint8_t rules_type [16];
135 
136 
139 typedef uint8_t *rules_typeref;
140 
141 
167 typedef char *rules_name;
168 
169 
188 typedef char const *rules_varray_ptr [26];
189 
192 typedef unsigned rules_varray_len [26];
193 
194 
203 #define RULES_VARINDEX(c) (c - 'a')
204 
205 
214 typedef uint32_t rules_flags;
215 
216 
225 #define RULES_FLAG(c) ( 1 << (c - 'A') )
226 
227 
238 typedef char const *rules_trigger;
239 
240 
284 void rules_init (void);
285 
286 
291 void rules_fini (void);
292 
293 
294 /* Forward reference. */
295 struct rules_request;
296 
297 
302 typedef bool (*rules_flags_upcall) (
303  struct rules_request *self);
304 
305 
310 typedef bool (*rules_trigger_upcall) (
311  struct rules_request *self,
312  rules_trigger trigger_name,
313  unsigned tigger_namelen);
314 
315 
320 typedef bool (*rules_selector_upcall) (
321  struct rules_request *self,
322  const a2sel_t *selector);
323 
324 
340 typedef bool (*rules_endrule_upcall) (
341  struct rules_request *self);
342 
343 
360 typedef bool (*rules_endruleset_upcall) (
361  struct rules_request *self);
362 
363 
400  /* Override rules_process() for use in rules_dbiterate() */
401  bool (*rules_process_override) (struct rules_request *req,
402  const char *ruleset, unsigned rulesetlen,
403  bool permit_selector);
404  /* Context fields for the rules_process functions */
405  rules_domain opt_domain;
406  rules_typeref opt_type;
407  rules_name opt_name;
408  a2sel_quickiter opt_qiter;
409  /* Callback functions, inasfar as supported by the Access Type */
410  rules_flags_upcall optcb_flags;
411  rules_trigger_upcall optcb_trigger;
412  rules_selector_upcall optcb_selector;
413  rules_endrule_upcall optcb_endrule;
414  rules_endruleset_upcall optcb_endruleset;
415  /* Output fields to upcalls (cleared at the end) */
416  char const *flags_rawstr;
417  rules_flags flags;
418  rules_varray_ptr varray_str;
419  rules_varray_len varray_strlen;
420 };
421 
422 
442 bool rules_process (struct rules_request *req,
443  const char *ruleset, unsigned rulesetlen,
444  bool permit_selector);
445 
446 
477 bool rules_dbiterate (struct rules_request *req,
478  const uint8_t *svckey, unsigned svckeylen,
479  const rules_name name,
480  const a2sel_t *iter0);
481 
482 
485 #ifdef __cplusplus
486 }
487 #endif
488 
489 #endif /* ARPA2_RULES_H */
490 
bool(* rules_selector_upcall)(struct rules_request *self, const a2sel_t *selector)
Rules upcall for selectors; used when ~sel is encountered in a Rule.
Definition: rules.h:320
bool(* rules_flags_upcall)(struct rules_request *self)
Rules upcall for flags; used when FLAGS are encountered in a Rule.
Definition: rules.h:302
void rules_init(void)
Initialise the ARPA2 Rules system.
bool(* rules_endruleset_upcall)(struct rules_request *self)
Rules upcall for the end of a Ruleset.
Definition: rules.h:360
bool rules_process(struct rules_request *req, const char *ruleset, unsigned rulesetlen, bool permit_selector)
Process a Ruleset, causing upcalls as specified in the rules_request. The ruleset is the ext to proce...
void rules_fini(void)
Finalise the ARPA2 Rules system.
bool(* rules_endrule_upcall)(struct rules_request *self)
Rules upcall for the end of a Rule.
Definition: rules.h:340
bool(* rules_trigger_upcall)(struct rules_request *self, rules_trigger trigger_name, unsigned tigger_namelen)
Rules upcall for triggers; used ^trigger is encountered in a Rule.
Definition: rules.h:310
bool rules_dbiterate(struct rules_request *req, const uint8_t *svckey, unsigned svckeylen, const rules_name name, const a2sel_t *iter0)
Iterate over an ARPA2 Selector for an identity to find the most concrete Ruleset; once found,...
uint8_t * rules_typeref
A reference to the 16-byte array of a rules_type.
Definition: rules.h:139
char const * rules_trigger
Triggers reference a ^trigger name.
Definition: rules.h:238
unsigned rules_varray_len[26]
The corresponding lengths for rules_varray_ptr.
Definition: rules.h:192
char const * rules_varray_ptr[26]
Rules Variables form a set of 26 variables named a through z that never have value NULL but may be em...
Definition: rules.h:188
uint32_t rules_flags
Flags in a bit mask.
Definition: rules.h:214
char * rules_domain
Rules Domains are UTF-8 representations of a Fully Qualified Domain Name.
Definition: rules.h:99
uint8_t rules_type[16]
Rules Types are 128-bit "well-known service identities".
Definition: rules.h:134
char * rules_name
Rules Names represent instances of a Rules Type.
Definition: rules.h:167
Storage structure for Quick Iteration.
Definition: identity.h:526
ARPA2 Selector.
Definition: identity.h:165
Definition: rules.h:399