static int KTrieBuildMatchStateNodeWithSnortConf(struct _SnortConfig *sc, KTRIENODE *root, int (*build_tree)(struct _SnortConfig *, void * id, void **existing_tree), int (*neg_list_func)(void *id, void **list)) { int cnt = 0; KTRIEPATTERN *p; if (!root) return 0; /* each and every prefix match at this root*/ if (root->pkeyword) { for (p = root->pkeyword; p; p = p->mnext) { if (p->id) { if (p->negative) { neg_list_func(p->id, &root->pkeyword->neg_list); } else { build_tree(sc, p->id, &root->pkeyword->rule_option_tree); } } cnt++; } /* Last call to finalize the tree for this root */ build_tree(sc, NULL, &root->pkeyword->rule_option_tree); } /* for child of this root */ if (root->child) { cnt += KTrieBuildMatchStateNodeWithSnortConf(sc, root->child, build_tree, neg_list_func); } /* 1st sibling of this root -- other siblings will be processed from * within the processing for root->sibling. */ if (root->sibling) { cnt += KTrieBuildMatchStateNodeWithSnortConf(sc, root->sibling, build_tree, neg_list_func); } return cnt; }
static int acsmBuildMatchStateTrees( ACSM_STRUCT * acsm, int (*build_tree)(void * id, void **existing_tree), int (*neg_list_func)(void *id, void **list) ) { int i, cnt = 0; ACSM_PATTERN * mlist; /* Find the states that have a MatchList */ for (i = 0; i < acsm->acsmMaxStates; i++) { for ( mlist=acsm->acsmStateTable[i].MatchList; mlist!=NULL; mlist=mlist->next ) { if (mlist->udata->id) { if (mlist->negative) { neg_list_func(mlist->udata->id, &acsm->acsmStateTable[i].MatchList->neg_list); } else { build_tree(mlist->udata->id, &acsm->acsmStateTable[i].MatchList->rule_option_tree); } } cnt++; } if (acsm->acsmStateTable[i].MatchList) { /* Last call to finalize the tree */ build_tree(NULL, &acsm->acsmStateTable[i].MatchList->rule_option_tree); } } return cnt; }