int rm_endofrule(junc_t * jp, element_t * ep, ruleinst_t * rt) { branch_t *bp; spocp_index_t *inx; DEBUG(SPOCP_DSTORE) traceLog(LOG_DEBUG,"rm end_of_rule"); bp = ARRFIND(jp, SPOC_ENDOFRULE); bp->count--; DEBUG(SPOCP_DSTORE) traceLog(LOG_DEBUG,"Branch count=%d", bp->count); inx = bp->val.id; index_rm(inx, rt); if (inx->n == 0) { branch_free(bp); return 0; } /* * there is no next element */ return 1; }
static int ssn_rm(branch_t * bp, ssn_t * ssn, char *sp, int direction, element_t * ep, ruleinst_t * rt) { junc_t *jp; int r; jp = ssn_delete(&ssn, sp, direction); if (ssn == 0) { branch_free(bp); return 0; } if (jp) { r = rm_next(jp, ep, rt); if (r == 0) { /* one branch gone from the junction */ /* * could this really happen ?? */ if (junction_index(jp) == 0) { DEBUG(SPOCP_DSTORE) traceLog(LOG_DEBUG, "Junction without any branches"); junc_free(jp); return -1; } } } return 1; }
int range_rm(branch_t * bp, element_t * ep, ruleinst_t * rt) { junc_t *jp; int rc, dtype = ep->e.range->lower.type & 0x07; jp = sl_range_rm(bp->val.range[dtype], ep->e.range, &rc); if (rc == 1) { junc_free(jp); branch_free(bp); return 0; } rc = rm_next(jp, ep, rt); if (rc == 0) { /* one branch gone from the junction */ /* * could this really happen ?? */ if (junction_index(jp) == 0) { DEBUG(SPOCP_DSTORE) traceLog(LOG_DEBUG,"Junction without any branches"); junc_free(jp); return -1; } } return 1; }
void cmd_branch_fini(fmd_hdl_t *hdl) { cmd_branch_t *branch; fmd_hdl_debug(hdl, "cmd_branch_fini\n"); while ((branch = cmd_list_next(&cmd.cmd_branches)) != NULL) branch_free(hdl, branch, FMD_B_FALSE); }
int rm_endoflist(junc_t * jp, element_t * ep, ruleinst_t * rt) { branch_t *bp; junc_t *rjp; int r; bp = ARRFIND(jp, SPOC_ENDOFLIST); bp->count--; DEBUG(SPOCP_DSTORE) traceLog(LOG_DEBUG,"EOL Branch [%d]", bp->count); rjp = bp->val.list; if (bp->count == 0) { DEBUG(SPOCP_DSTORE) traceLog(LOG_DEBUG,"Get rid of the rest of this branch"); branch_free(bp); DEBUG(SPOCP_DSTORE) traceLog(LOG_DEBUG,"No type %d branch at this junction any more", SPOC_ENDOFLIST); jp->item[SPOC_ENDOFLIST] = 0; return 0; } r = rm_next(rjp, ep, rt); if (r == 0) { /* one branch gone from the junction */ if (junction_index(rjp) == 0) { DEBUG(SPOCP_DSTORE) traceLog(LOG_DEBUG,"Junction without any branches"); junc_free(rjp); bp->val.list = 0; } } return 1; }
int atom_rm(branch_t * bp, element_t * elemp, ruleinst_t * rt) { buck_t *bucket = 0; junc_t *jp; atom_t *ap = elemp->e.atom; int r; if (bp->val.atom == 0) return 0; bucket = phash_search(bp->val.atom, ap, ap->hash); /* * bucket == 0 should be impossible, should I still check ? */ if (bucket == 0) return 0; bucket->refc--; DEBUG(SPOCP_DSTORE) { char *tmp; tmp = oct2strdup(&ap->val, '\\'); traceLog(LOG_DEBUG,"atom_rm: bucket [%s] [%d]", tmp, bucket->refc); Free(tmp); } jp = bucket->next; if (bucket->refc == 0) { DEBUG(SPOCP_DSTORE) traceLog(LOG_DEBUG, "bucket reference down to zero"); bucket_rm(bp->val.atom, bucket); /* * last in hashtable ? */ if (phash_index(bp->val.atom) == 0) { phash_free(bp->val.atom); bp->val.atom = 0; DEBUG(SPOCP_DSTORE) traceLog(LOG_DEBUG,"Get rid of the rest of this branch"); branch_free(bp); return 0; } else { /* * remove remaining references */ DEBUG(SPOCP_DSTORE) traceLog(LOG_DEBUG, "junc_free"); junc_free(jp); return 1; } } r = rm_next(jp, elemp, rt); DEBUG(SPOCP_DSTORE) traceLog( LOG_DEBUG, "rm_next returned %d", r ); if (r == 0) { /* one branch gone from the junction */ if (junction_index(jp) == 0) { DEBUG(SPOCP_DSTORE) traceLog(LOG_DEBUG,"Junction without any branches"); junc_free(jp); bucket->next = 0; } } else if (r == -1) /* the junctions is gone */ bucket->next = 0; return 1; }
int element_rm(junc_t * jp, element_t * ep, ruleinst_t * rt) { branch_t *bp; int r = 0, n; bp = ARRFIND(jp, ep->type); if (bp == 0) { /* Ooops, how did that happen, can't delete * something that isn't there */ DEBUG(SPOCP_DSTORE) traceLog(LOG_DEBUG,"missing branch where there shold be one"); return -2; } bp->count--; DEBUG(SPOCP_DSTORE) traceLog(LOG_DEBUG,"Branch: [%d]", bp->count); if (bp->count == 0) { DEBUG(SPOCP_DSTORE) traceLog(LOG_DEBUG,"element_rm; branch counter down to zero"); branch_free(bp); /* * have to do the junction handling here since the type is * unknown further up */ jp->item[ep->type] = 0; return 1; } /* * type dependent part */ switch (ep->type) { case SPOC_ATOM: r = atom_rm(bp, ep, rt); break; case SPOC_PREFIX: r = prefix_rm(bp, ep, rt); break; case SPOC_SUFFIX: r = suffix_rm(bp, ep, rt); break; case SPOC_RANGE: break; case SPOC_LIST: r = list_rm(bp, ep, rt); break; case SPOC_SET: break; } if (r == 0) { /* * that branch is gone */ DEBUG(SPOCP_DSTORE) traceLog(LOG_DEBUG,"rm element; no type %d branch anymore", ep->type); jp->item[ep->type] = 0; n = junction_index(jp); DEBUG(SPOCP_DSTORE) traceLog(LOG_DEBUG,"rm element; junction index %d", n); if (n == 0) junc_free(jp); } return 1; }
void cmd_branch_destroy(fmd_hdl_t *hdl, cmd_branch_t *branch) { branch_free(hdl, branch, FMD_B_TRUE); }