atc_router::ffi::context

Function context_get_result

Source
#[no_mangle]
pub unsafe extern "C" fn context_get_result(
    context: &Context<'_>,
    uuid_hex: *mut u8,
    matched_field: *const i8,
    matched_value: *mut *const u8,
    matched_value_len: *mut usize,
    capture_names: *mut *const u8,
    capture_names_len: *mut usize,
    capture_values: *mut *const u8,
    capture_values_len: *mut usize,
) -> isize
Expand description

Get the result of the context.

§Arguments

  • context: a pointer to the Context object.
  • uuid_hex: If not NULL, the UUID of the matched matcher will be stored.
  • matched_field: If not NULL, the field name (C-style string) of the matched value will be stored.
  • matched_value: If the matched_field is not NULL, the value of the matched field will be stored.
  • matched_value_len: If the matched_field is not NULL, the length of the value of the matched field will be stored.
  • capture_names: A pointer to an array of pointers to the capture names, each element is a non-C-style string pointer.
  • capture_names_len: A pointer to an array of the length of each capture name.
  • capture_values: A pointer to an array of pointers to the capture values, each element is a non-C-style string pointer.
  • capture_values_len: A pointer to an array of the length of each capture value.

§Returns

Returns the number of captures that are stored in the context.

§Lifetimes

The string pointers stored in matched_value, capture_names, and capture_values might be invalidated if any of the following operations are happened:

  • The context was deallocated.
  • The context was reset by context_reset.

§Panics

This function will panic if the matched_field is not a valid UTF-8 string.

§Safety

Violating any of the following constraints will result in undefined behavior:

  • context must be a valid pointer returned by context_new, must be passed to [router_execute] before calling this function, and must not be reset by context_reset before calling this function.
  • If uuid_hex is not NULL, uuid_hex must be valid to read and write for 16 * size_of::<u8>() bytes, and it must be properly aligned.
  • If matched_field is not NULL, matched_field must be a vlaid pointer to a C-style string, must be properly aligned, and must not have ‘\0’ in the middle.
  • If matched_value is not NULL, matched_value must be valid to read and write for mem::size_of::<*const u8>() bytes, and it must be properly aligned.
  • If matched_value is not NULL, matched_value_len must be valid to read and write for size_of::<usize>() bytes, and it must be properly aligned.
  • If uuid_hex is not NULL, capture_names must be valid to read and write for <captures> * size_of::<*const u8>() bytes, and it must be properly aligned.
  • If uuid_hex is not NULL, capture_names_len must be valid to read and write for <captures> * size_of::<usize>() bytes, and it must be properly aligned.
  • If uuid_hex is not NULL, capture_values must be valid to read and write for <captures> * size_of::<*const u8>() bytes, and it must be properly aligned.
  • If uuid_hex is not NULL, capture_values_len must be valid to read and write for <captures> * size_of::<usize>() bytes, and it must be properly aligned.

Note: You should get the <captures> by calling this function and set every pointer except the context to NULL to get the number of captures.