static void xml_decode_init(void) { int i; __token_tree = acl_token_new(); for (i = 0; __tab[i].str != 0; i++) acl_token_tree_add(__token_tree, __tab[i].txt, ACL_TOKEN_F_STOP, &__tab[i]); /* 进程退出时调用 html_decode_free 释放内存资源 */ atexit(xml_decode_free); }
ACL_TOKEN *acl_token_tree_create2(const char *s, const char *sep) { const char *myname = "acl_token_tree_create"; ACL_ARGV *argv; ACL_ITER iter; unsigned int flag; ACL_TOKEN *token_tree; const ACL_TOKEN *token; ACL_VSTRING *buf; token_tree = acl_token_new(); if (s == NULL || *s == 0) return (token_tree); buf = acl_vstring_alloc(256); argv = acl_argv_split(s, sep); acl_foreach(iter, argv) { char *word = (char*) iter.ptr; char *ptr = strchr(word, '|'); flag = ACL_TOKEN_F_STOP; if (ptr) { *ptr++ = 0; if (*ptr == 'D' || *ptr == 'd') flag |= ACL_TOKEN_F_DENY; if (*ptr == 'P' || *ptr == 'p') flag |= ACL_TOKEN_F_PASS; } token = acl_token_tree_add(token_tree, word, flag, NULL); if (token == NULL) { acl_msg_info("%s(%d): word(%s) discard", myname, __LINE__, word); } else { ACL_VSTRING_RESET(buf); acl_token_name(token, buf); /* acl_msg_info("%s(%d): add word(%s) ok, token's name(%s)", myname, __LINE__, word, STR(buf)); */ } }
ACL_TOKEN *acl_token_tree_add_word_map(ACL_TOKEN *token_tree, const char *word, const char *word_map, unsigned int flag) { const char *myname = "acl_token_tree_add_word_map"; const unsigned char *ptr = (const unsigned char*) word; const unsigned char *ptr_map = (const unsigned char*) word_map; ACL_TOKEN *token_iter = token_tree, *token = NULL; if ((flag & ACL_TOKEN_F_PASS) && (flag & ACL_TOKEN_F_DENY)) { acl_msg_error("%s(%d): word(%s)'s flag(%u) is " "ACL_TOKEN_F_DENY | ACL_TOKEN_F_PASS", myname, __LINE__, word, flag); return (NULL); } while (*ptr) { token = token_iter->tokens[*ptr]; if (token == NULL) { token = acl_token_new(); token->ch = *ptr_map; token_iter->tokens[*ptr] = token; token->parent = token_iter; ptr++; ptr_map++; token_iter = token; } else if (token->ch != *ptr_map) { acl_msg_fatal("%s(%d): token->ch(%d) != %d", myname, __LINE__, token->tokens[*ptr]->ch, *ptr_map); } else { ptr++; ptr_map++; token_iter = token; } } if (token) token->flag = flag; return (token); }