1 #ifndef ACL_TOKEN_TREE_INCLUDE_H 2 #define ACL_TOKEN_TREE_INCLUDE_H 11 #define ACL_PRINT_CHAR(x) \ 12 ((((x) >= 'a' && (x) <='z') \ 13 || ((x) >= 'A' && (x) <= 'Z') \ 14 || ((x) >= '0' && (x) <= '9') \ 15 || (x) == ';' || (x) == '!' \ 16 || (x) == ':' || (x) == ',' \ 17 || (x) == '.' || (x) == '@' \ 18 || (x) == '#' || (x) == '$' \ 19 || (x) == '%' || (x) == '^' \ 20 || (x) == '&' || (x) == '*' \ 21 || (x) == '(' || (x) == ')' \ 22 || (x) == '-' || (x) == '=' \ 23 || (x) == '|' || (x) == '\\' \ 24 || (x) == '[' || (x) == ']' \ 25 || (x) == '{' || (x) == '}' \ 26 || (x) == '\'' || (x) == '"') \ 34 #define ACL_TOKEN_F_NONE 0 35 #define ACL_TOKEN_F_STOP (1 << 0) 36 #define ACL_TOKEN_F_PASS (1 << 1) 37 #define ACL_TOKEN_F_DENY (1 << 2) 38 #define ACL_TOKEN_F_UTF8 (1 << 3) 40 #define ACL_TOKEN_WIDTH 256 49 #define ACL_TOKEN_TREE_WORD_MATCH(acl_token_tree_in, word_in, acl_token_out) \ 51 const unsigned char *_ptr = (const unsigned char*) word_in; \ 52 ACL_TOKEN *_token_iter = acl_token_tree_in, *_token = NULL; \ 54 _token = _token_iter->tokens[*_ptr]; \ 57 _token_iter = _token; \ 60 if (_token && (_token->flag & ACL_TOKEN_F_STOP)) \ 61 acl_token_out = _token; \ 63 acl_token_out = NULL; \ 66 #define ACL_TOKEN_TREE_MATCH(acl_token_tree_in, s_in, delim_in, delim_tab_in, acl_token_out) do \ 68 ACL_TOKEN *acl_token_iter = (acl_token_tree_in), *acl_token_tmp; \ 69 (acl_token_out) = NULL; \ 70 if (((const char*) delim_in)) { \ 73 for (_i = 0; ((const char*) delim_in)[_i]; _i++) { \ 74 if (*(s_in) == ((const char*) delim_in)[_i]) \ 77 acl_token_tmp = acl_token_iter->tokens[*((const unsigned char*)(s_in))]; \ 78 if (acl_token_tmp == NULL) { \ 79 if ((acl_token_out)) \ 81 acl_token_iter = (acl_token_tree_in); \ 82 acl_token_tmp = acl_token_iter->tokens[*((const unsigned char*)(s_in))]; \ 83 if (acl_token_tmp == NULL) { \ 88 if ((acl_token_tmp->flag & ACL_TOKEN_F_STOP)) \ 89 (acl_token_out) = acl_token_tmp; \ 90 acl_token_iter = acl_token_tmp; \ 95 } else if (((char*) delim_tab_in)) { \ 97 if (((char*) delim_tab_in)[*((const unsigned char*)(s_in))]) \ 99 acl_token_tmp = acl_token_iter->tokens[*((const unsigned char*)(s_in))]; \ 100 if (acl_token_tmp == NULL) { \ 101 if ((acl_token_out)) \ 103 acl_token_iter = (acl_token_tree_in); \ 104 acl_token_tmp = acl_token_iter->tokens[*((const unsigned char*)(s_in))]; \ 105 if (acl_token_tmp == NULL) { \ 110 if ((acl_token_tmp->flag & ACL_TOKEN_F_STOP)) \ 111 (acl_token_out) = acl_token_tmp; \ 112 acl_token_iter = acl_token_tmp; \ 117 acl_token_tmp = acl_token_iter->tokens[*((const unsigned char*)(s_in))]; \ 118 if (acl_token_tmp == NULL) { \ 119 if ((acl_token_out)) \ 121 acl_token_iter = (acl_token_tree_in); \ 122 acl_token_tmp = acl_token_iter->tokens[*((const unsigned char*)(s_in))]; \ 123 if (acl_token_tmp == NULL) { \ 128 if ((acl_token_tmp->flag & ACL_TOKEN_F_STOP)) \ 129 (acl_token_out) = acl_token_tmp; \ 130 acl_token_iter = acl_token_tmp; \ 143 const char *word,
unsigned int flag,
const void *
ctx);
145 const char *word,
const char *word_map,
unsigned int flag);
150 const char **ptr,
const char *delim,
const char *delim_tab);
152 void (*walk_fn)(
ACL_TOKEN*,
void*),
void *arg);
ACL_API const char * acl_token_name1(ACL_TOKEN *token)
ACL_API ACL_TOKEN * acl_token_tree_add(ACL_TOKEN *tree, const char *word, unsigned int flag, const void *ctx)
ACL_API ACL_TOKEN * acl_token_tree_add_word_map(ACL_TOKEN *tree, const char *word, const char *word_map, unsigned int flag)
ACL_API void * acl_token_tree_word_remove(ACL_TOKEN *tree, const char *word)
ACL_API void acl_token_tree_walk(ACL_TOKEN *tree, void(*walk_fn)(ACL_TOKEN *, void *), void *arg)
ACL_API void acl_token_name(ACL_TOKEN *token, ACL_VSTRING *buf)
ACL_API ACL_TOKEN * acl_token_tree_create(const char *s)
ACL_API ACL_TOKEN * acl_token_tree_match(ACL_TOKEN *tree, const char **ptr, const char *delim, const char *delim_tab)
struct ACL_TOKEN * parent
ACL_API void acl_token_tree_destroy(ACL_TOKEN *tree)
ACL_API void acl_token_delim_tab_free(char *delim_tab)
ACL_API ACL_TOKEN * acl_token_tree_create2(const char *s, const char *sep)
struct ACL_TOKEN * tokens[ACL_TOKEN_WIDTH]
ACL_API ACL_TOKEN * acl_token_new(void)
ACL_API void acl_token_tree_print(ACL_TOKEN *tree)
ACL_API ACL_TOKEN * acl_token_tree_word_match(ACL_TOKEN *tree, const char *word)
ACL_API char * acl_token_delim_tab_new(const char *delim)
ACL_API void acl_token_free(ACL_TOKEN *token)
ACL_API void acl_token_tree_load_deny(const char *filepath, ACL_TOKEN *tree)
ACL_API void acl_token_tree_load_pass(const char *filepath, ACL_TOKEN *tree)