#[no_mangle]
pub unsafe extern "C" fn expression_validate(
atc: *const u8,
schema: &Schema,
fields_buf: *mut u8,
fields_buf_len: *mut usize,
fields_total: *mut usize,
operators: *mut u64,
errbuf: *mut u8,
errbuf_len: *mut usize,
) -> i64
Expand description
Validates an ATC expression against a schema and get its elements.
§Arguments
atc
: a C-style string representing the ATC expression.schema
: a valid pointer to aSchema
object, as returned by [schema_new
].fields_buf
: a buffer for storing the fields used in the expression.fields_buf_len
: a pointer to the length offields_buf
.fields_total
: a pointer for storing the total number of unique fields used in the expression.operators
: a pointer for storing the bitflags representing used operators.errbuf
: a buffer to store any error messages.errbuf_len
: a pointer to the length of the error message buffer.
§Returns
An integer indicating the validation result:
ATC_ROUTER_EXPRESSION_VALIDATE_OK
(0): Validation succeeded.ATC_ROUTER_EXPRESSION_VALIDATE_FAILED
(1): Validation failed;errbuf
anderrbuf_len
will be updated with an error message.ATC_ROUTER_EXPRESSION_VALIDATE_BUF_TOO_SMALL
(2): The providedfields_buf
is too small.
If fields_buf_len
indicates that fields_buf
is sufficient, this function writes the used fields to fields_buf
, each field terminated by \0
.
It stores the total number of fields in fields_total
.
If fields_buf_len
indicates that fields_buf
is insufficient, it returns ATC_ROUTER_EXPRESSION_VALIDATE_BUF_TOO_SMALL
.
It writes the used operators as bitflags to operators
.
Bitflags are defined by BinaryOperatorFlags
and must exclude bits from BinaryOperatorFlags::UNUSED
.
§Safety
Violating any of the following constraints results in undefined behavior:
atc
must be a valid pointer to a C-style string, properly aligned, and must not contain an internal\0
.schema
must be a valid pointer returned by [schema_new
].fields_buf
, must be valid for writingfields_buf_len * size_of::<u8>()
bytes and properly aligned.fields_buf_len
must be a valid pointer to writesize_of::<usize>()
bytes and properly aligned.fields_total
must be a valid pointer to writesize_of::<usize>()
bytes and properly aligned.operators
must be a valid pointer to writesize_of::<u64>()
bytes and properly aligned.errbuf
must be valid for reading and writingerrbuf_len * size_of::<u8>()
bytes and properly aligned.errbuf_len
must be a valid pointer for reading and writingsize_of::<usize>()
bytes and properly aligned.