Structure for traits of policy resources (such as URLs) to be evaluated.
The traits are used by the policy interfaces in the C SDK to determine how to compare and canonicalize policy resources to reach a policy decision during policy evaluation.
#include "am_policy.h" typedef struct am_resource_traits { am_resource_match_t (*cmp_func_ptr)(const struct am_resource_traits v*rsrc_traits, const char *policy_res_name, const char *resource_name, boolean_t use_patterns); boolean_t (*has_patterns)(const char *resource_name); boolean_t (*get_resource_root)(const char *resource_name, char *root_resource_name, size_t buflength); boolean_t ignore_case; char separator; void (*canonicalize)(const char *resource, char **c_resource); void (*str_free)(void *resource_str); } am_resource_traits_t;
This structure has the following members:
A function that compares the policy_res_name and resource_name and returns a resource match result.
Inputs:
rsrc_traits - the resource traits structure to use.
policy_res_name - name of a resource in the policy tree.
resource_name - name of the resource in policy evaluation.
use_patterns - whether to use or recognize patterns when comparing resources.
Returns:
Return one of AM_SUB_RESOURCE_MATCH, AM_EXACT_MATCH , AM_SUPER_RESOURCE_MATCH, AM_NO_MATCH, or AM_EXACT_PATTERN_MATCH.
Example:
am_policy_compare_urls() can be used for URL resources.
A function to determine whether a resource has patterns.
Inputs:
resource_name - name of the resource.
Returns:
True if resource_name has patterns and false otherwise.
Example:
am_policy_resource_has_patterns can be used for URL resources.
A function to get the root of a resource.
Inputs:
Resource_name - name of the resource.
Root_resource_name - a buffer to contain the name of the resource root.
Buflength - length of the root_resource_name buffer passed to this function.
Returns:
True if the name of the resource root was successfully inserted into the given root_resource_name buffer, false otherwise.
Examples:
am_policy_get_url_resource_root() can be used for URL resources.
Whether case should be ignored for all functions in this structure.
Resource separator. For URLs ’/’ should be used as the separator.
A function to canonicalize a resource name.
Inputs:
resource - the resource name.
Outputs:
c_resource - the canonicalized resource name. Memory for the canonicalized name must be allocated by the caller. A function to free the memory allocated for the canonicalized must be set in the str_free field.
A function to free the c_resource string returned in the canonicalize function above, after policy results have been evaluated by am_policy_evaluate().
This field cannot be set to null.
Inputs:
The resource_str - the string to be freed.
Examples:
Method free() should be used if the canonicalize field is set to the am_policy_resource_canonicalize() function.
See am_policy_test.c in the C SDK samples for an example of how this structure is used.