rego-cpp 0.4.5
A C++ implementation of the Rego language and runtime
|
#include "version.h"
Go to the source code of this file.
Typedefs | |
typedef void | regoInterpreter |
typedef void | regoNode |
typedef void | regoOutput |
typedef unsigned int | regoEnum |
typedef unsigned char | regoBoolean |
typedef unsigned int | regoSize |
Functions | |
regoEnum | regoSetLogLevel (regoEnum level) |
regoEnum | regoSetLogLevelFromString (const char *level) |
regoEnum | regoSetTZDataPath (const char *path) |
regoInterpreter * | regoNew (void) |
regoInterpreter * | regoNewV1 (void) |
void | regoFree (regoInterpreter *rego) |
regoEnum | regoAddModuleFile (regoInterpreter *rego, const char *path) |
regoEnum | regoAddModule (regoInterpreter *rego, const char *name, const char *contents) |
regoEnum | regoAddDataJSONFile (regoInterpreter *rego, const char *path) |
regoEnum | regoAddDataJSON (regoInterpreter *rego, const char *contents) |
regoEnum | regoSetInputJSONFile (regoInterpreter *rego, const char *path) |
regoEnum | regoSetInputJSON (regoInterpreter *rego, const char *contents) |
regoEnum | regoSetInputTerm (regoInterpreter *rego, const char *contents) |
void | regoSetDebugEnabled (regoInterpreter *rego, regoBoolean enabled) |
regoBoolean | regoGetDebugEnabled (regoInterpreter *rego) |
regoEnum | regoSetDebugPath (regoInterpreter *rego, const char *path) |
void | regoSetWellFormedChecksEnabled (regoInterpreter *rego, regoBoolean enabled) |
regoBoolean | regoGetWellFormedChecksEnabled (regoInterpreter *rego) |
regoOutput * | regoQuery (regoInterpreter *rego, const char *query_expr) |
void | regoSetStrictBuiltInErrors (regoInterpreter *rego, regoBoolean enabled) |
regoBoolean | regoGetStrictBuiltInErrors (regoInterpreter *rego) |
const char * | regoGetError (regoInterpreter *rego) |
regoBoolean | regoOutputOk (regoOutput *output) |
regoSize | regoOutputSize (regoOutput *output) |
regoNode * | regoOutputExpressionsAtIndex (regoOutput *output, regoSize index) |
regoNode * | regoOutputExpressions (regoOutput *output) |
regoNode * | regoOutputNode (regoOutput *output) |
regoNode * | regoOutputBindingAtIndex (regoOutput *output, regoSize index, const char *name) |
regoNode * | regoOutputBinding (regoOutput *output, const char *name) |
const char * | regoOutputString (regoOutput *output) |
void | regoFreeOutput (regoOutput *output) |
regoEnum | regoNodeType (regoNode *node) |
const char * | regoNodeTypeName (regoNode *node) |
regoSize | regoNodeValueSize (regoNode *node) |
regoEnum | regoNodeValue (regoNode *node, char *buffer, regoSize size) |
regoSize | regoNodeSize (regoNode *node) |
regoNode * | regoNodeGet (regoNode *node, regoSize index) |
regoSize | regoNodeJSONSize (regoNode *node) |
regoEnum | regoNodeJSON (regoNode *node, char *buffer, regoSize size) |
regoEnum regoAddDataJSON | ( | regoInterpreter * | rego, |
const char * | contents ) |
Adds a base document from the specified string.
The string should contain a single JSON object. The object will be parsed and merged with the interpreter's base document.
If an error code is returned, more error information can be obtained by calling regoGetError.
rego | The interpreter. |
contents | The contents of the JSON object. |
regoEnum regoAddDataJSONFile | ( | regoInterpreter * | rego, |
const char * | path ) |
Adds a base document from the file at the specified path.
The file should contain a single JSON object. The object will be parsed and merged with the interpreter's base document.
If an error code is returned, more error information can be obtained by calling regoGetError.
rego | The interpreter. |
path | The path to the JSON file. |
regoEnum regoAddModule | ( | regoInterpreter * | rego, |
const char * | name, | ||
const char * | contents ) |
Adds a module (e.g. virtual document) from the specified string.
If an error code is returned, more error information can be obtained by calling regoGetError.
rego | The interpreter. |
name | The name of the module. |
contents | The contents of the module. |
regoEnum regoAddModuleFile | ( | regoInterpreter * | rego, |
const char * | path ) |
Adds a module (e.g. virtual document) from the file at the specified path.
If an error code is returned, more error information can be obtained by calling regoGetError.
rego | The interpreter. |
path | The path to the policy file. |
void regoFree | ( | regoInterpreter * | rego | ) |
Frees a Rego interpreter.
This pointer must have been allocated with regoNew.
rego | The interpreter to free. |
void regoFreeOutput | ( | regoOutput * | output | ) |
Frees a Rego output.
This pointer must have been allocated with regoQuery.
output | The output to free. |
regoBoolean regoGetDebugEnabled | ( | regoInterpreter * | rego | ) |
Gets the debug mode of the interpreter.
rego | The interpreter. |
const char * regoGetError | ( | regoInterpreter * | rego | ) |
Returns the most recently thrown error.
If an error code is returned from an interface function, more error information can be obtained by calling this function.
rego | The interpreter. |
regoBoolean regoGetStrictBuiltInErrors | ( | regoInterpreter * | rego | ) |
Gets whether strict built-in errors are enabled.
rego | The interpreter. |
regoBoolean regoGetWellFormedChecksEnabled | ( | regoInterpreter * | rego | ) |
Gets whether well-formed checks are enabled.
rego | The interpreter. |
regoInterpreter * regoNew | ( | void | ) |
Allocates and initializes a new Rego interpreter.
The caller is responsible for freeing the interpreter with regoFree.
regoInterpreter * regoNewV1 | ( | void | ) |
Allocates and initializes a new V1 Rego interpreter.
The caller is responsible for freeing the interpreter with regoFree.
regoNode * regoNodeGet | ( | regoNode * | node, |
regoSize | index ) |
Returns the child node at the specified index.
node | The node. |
index | The index of the child. |
regoEnum regoNodeJSON | ( | regoNode * | node, |
char * | buffer, | ||
regoSize | size ) |
Populate a buffer with the JSON representation of the node.
The buffer must be large enough to hold the value. The size of the buffer can be determined by calling regoNodeJSONSize.
node | The node. |
buffer | The buffer to populate. |
size | The size of the buffer. |
regoSize regoNodeJSONSize | ( | regoNode * | node | ) |
Returns the number of bytes needed to store a 0-terminated string representing the JSON representation of the node.
The value returned by this function can be used to allocate a buffer to pass to regoNodeJSON.
node | The node. |
regoSize regoNodeSize | ( | regoNode * | node | ) |
Returns the number of children of the node.
node | The node. |
regoEnum regoNodeType | ( | regoNode * | node | ) |
Returns an enumeration value indicating the nodes type.
This type will be one of the following values:
Name | Description |
---|---|
REGO_NODE_BINDING | A binding. Will have two children, a REGO_NODE_VAR and a REGO_NODE_TERM |
REGO_NODE_VAR | A variable name. |
REGO_NODE_TERM | A term. Will have one child of: REGO_NODE_SCALAR, REGO_NODE_ARRAY, REGO_NODE_SET, REGO_NODE_OBJECT |
REGO_NODE_SCALAR | A scalar value. Will have one child of: REGO_NODE_INT, REGO_NODE_FLOAT, REGO_NODE_STRING, REGO_NODE_TRUE, REGO_NODE_FALSE, REGO_NODE_NULL, REGO_NODE_UNDEFINED |
REGO_NODE_ARRAY | An array. Will have one or more children of: REGO_NODE_TERM |
REGO_NODE_SET | A set. Will have one or more children of: REGO_NODE_TERM |
REGO_NODE_OBJECT | An object. Will have one or more children of: REGO_NODE_OBJECT_ITEM |
REGO_NODE_OBJECT_ITEM | An object item. Will have two children, a REGO_NODE_TERM (the key) and a REGO_NODE_TERM (the value) |
REGO_NODE_INT | An integer value. |
REGO_NODE_FLOAT | A floating point value. |
REGO_NODE_STRING | A string value. |
REGO_NODE_TRUE | A true value. |
REGO_NODE_FALSE | A false value. |
REGO_NODE_NULL | A null value. |
REGO_NODE_UNDEFINED | An undefined value. |
REGO_NODE_ERROR | An error. Will have three children: REGO_NODE_ERROR_MESSAGE, REGO_NODE_ERROR_AST, and REGO_NODE_ERROR_CODE |
REGO_NODE_ERROR_MESSAGE | An error message. |
REGO_NODE_ERROR_AST | An error AST. |
REGO_NODE_ERROR_CODE | An error code. |
REGO_NODE_ERROR_SEQ | An error sequence. Will have one or more children of: REGO_NODE_ERROR |
REGO_NODE_INTERNAL | An internal node. Use regoNodeTypeName to get the full value. |
const char * regoNodeTypeName | ( | regoNode * | node | ) |
Returns the name of the node type as a human-readable string.
This function supports arbitrary nodes (i.e. it will always produce a value) including internal nodes which appear in error messages.
node | The node. |
regoEnum regoNodeValue | ( | regoNode * | node, |
char * | buffer, | ||
regoSize | size ) |
Populate a buffer with the node value.
The buffer must be large enough to hold the value. The size of the buffer can be determined by calling regoNodeValueSize.
node | The node. |
buffer | The buffer to populate. |
size | The size of the buffer. |
regoSize regoNodeValueSize | ( | regoNode * | node | ) |
Returns the number of bytes needed to store a 0-terminated string representing the text value of the node.
The value returned by this function can be used to allocate a buffer to pass to regoNodeValue.
node | The node. |
regoNode * regoOutputBinding | ( | regoOutput * | output, |
const char * | name ) |
Returns the bound value for a given variable name at the first index.
If the variable is not bound, then this function will return NULL.
output | The output. |
name | The variable name. |
regoNode * regoOutputBindingAtIndex | ( | regoOutput * | output, |
regoSize | index, | ||
const char * | name ) |
Returns the bound value for a given variable name.
If the variable is not bound, then this function will return NULL.
output | The output. |
index | The result index. |
name | The variable name. |
regoNode * regoOutputExpressions | ( | regoOutput * | output | ) |
Returns a node containing a list of terms resulting from the query at the default index.
output | The output. |
regoNode * regoOutputExpressionsAtIndex | ( | regoOutput * | output, |
regoSize | index ) |
Returns a node containing a list of terms resulting from the query at the specified index.
output | The output. |
index | The result index. |
regoNode * regoOutputNode | ( | regoOutput * | output | ) |
Returns the node containing the output of the query.
This will either be a node which contains one or more results, or an error sequence.
output | The output. |
regoBoolean regoOutputOk | ( | regoOutput * | output | ) |
Returns whether the output is ok.
If the output resulted in a valid query result, then this function will return true. Otherwise, it will return false, indicating that the output contains an error sequence.
output | The output. |
regoSize regoOutputSize | ( | regoOutput * | output | ) |
Returns the number of results in the output.
Each query can potentially generate multiple results. This function returns the number of results in the output.
const char * regoOutputString | ( | regoOutput * | output | ) |
Returns the output represented as a human-readable string.
output | The output. |
regoOutput * regoQuery | ( | regoInterpreter * | rego, |
const char * | query_expr ) |
Performs a query against the current base and virtual documents.
The query expression should be a Rego query. The output of the query will be returned as a regoOutput object. The caller is responsible for freeing the output object with regoFreeOutput.
rego | The interpreter. |
query_expr | The query expression. |
void regoSetDebugEnabled | ( | regoInterpreter * | rego, |
regoBoolean | enabled ) |
Sets the debug mode of the interpreter.
When debug mode is enabled, the interpreter will output intermediary ASTs after each compiler pass to the debug directory and output pass information to stdout. This is mostly useful for creating reports for compiler issues, but can also be of use in understanding why a policy is invalid or is behaving unexpectedly.
rego | The interpreter. |
enabled | Whether debug mode should be enabled. |
regoEnum regoSetDebugPath | ( | regoInterpreter * | rego, |
const char * | path ) |
Sets the path to the debug directory.
If set, then (when in debug mode) the interpreter will output intermediary ASTs after each compiler pass to the debug directory. If the directory does not exist, it will be created.
If an error code is returned, more error information can be obtained by calling regoGetError.
rego | The interpreter. |
path | The path to the debug directory. |
regoEnum regoSetInputJSON | ( | regoInterpreter * | rego, |
const char * | contents ) |
Sets the current input document from the specified string.
The string should contain a single JSON value. The value will be parsed and set as the interpreter's input document.
If an error code is returned, more error information can be obtained by calling regoGetError.
regoSetInputTerm
. rego | The interpreter. |
contents | The contents of the JSON value. |
regoEnum regoSetInputJSONFile | ( | regoInterpreter * | rego, |
const char * | path ) |
Sets the current input document from the file at the specified path.
The file should contain a single JSON value. The value will be parsed and set as the interpreter's input document.
If an error code is returned, more error information can be obtained by calling regoGetError.
rego | The interpreter. |
path | The path to the JSON file. |
regoEnum regoSetInputTerm | ( | regoInterpreter * | rego, |
const char * | contents ) |
Sets the current input document from the specified string.
The string should contain a single Rego data term. The value will be parsed and set as the interpreter's input document.
If an error code is returned, more error information can be obtained by calling regoGetError.
rego | The interpreter. |
contents | The contents of the Rego data term. |
regoEnum regoSetLogLevel | ( | regoEnum | level | ) |
Sets the level of logging.
This setting controls the amount of logging that will be output to stdout. The default level is REGO_LOG_LEVEL_NONE.
level | One of the following values: REGO_LOG_LEVEL_NONE, REGO_LOG_LEVEL_ERROR, REGO_LOG_LEVEL_OUTPUT, REGO_LOG_LEVEL_WARN, REGO_LOG_LEVEL_INFO, REGO_LOG_LEVEL_DEBUG, REGO_LOG_LEVEL_TRACE. |
regoEnum regoSetLogLevelFromString | ( | const char * | level | ) |
Sets the level of logging.
This setting controls the amount of logging that will be output to stdout. The default level is REGO_LOG_LEVEL_NONE.
level | One of the following strings: "None", "Error", "Output", "Warn", "Info", "Debug", "Trace". |
void regoSetStrictBuiltInErrors | ( | regoInterpreter * | rego, |
regoBoolean | enabled ) |
Sets whether the built-ins should throw errors.
When strict built-in errors are enabled, built-in functions will throw errors when they encounter invalid input. When disabled, built-in functions will return undefined when they encounter invalid input.
rego | The interpreter. |
enabled | Whether strict built-in errors should be enabled. |
regoEnum regoSetTZDataPath | ( | const char * | path | ) |
Sets the location where rego-cpp will look for timezone database information.
The timezone database will be interpreted as one obtained from the IANA (https://www.iana.org/time-zones) which has been downloaded and unpacked into at the path provided. If the library was built without manual tzdata support, this function will return an error code.
path | The path to the timezone database. |
void regoSetWellFormedChecksEnabled | ( | regoInterpreter * | rego, |
regoBoolean | enabled ) |
Sets whether to perform well-formed checks after each compiler pass.
The interpreter has a set of well-formness definitions which indicate the expected form of the AST before and after each compiler pass. This setting determines whether the interpreter will perform these intermediary checks.
rego | The interpreter. |
enabled | Whether well-formed checks should be enabled. |