static int search_cached_pattern (cache_file_contents *cache, const char *line) { int ret = -1; do { recheck_cached_file (cache, cachefile_timecheck); if (cache->wildcards) { struct list_node *entry = cache->wildcards; while (entry) { if (compare_pattern (line, entry->content) == 0) { DEBUG1 ("%s matched pattern", line); return 1; } entry = entry->next; } ret = 0; } if (allowed_ip.contents) { void *result; if (avl_get_by_key (allowed_ip.contents, (char*)line, &result) == 0) return 1; return 0; } } while (0); return ret; }
/* check specified ip against internal set of banned IPs * return -1 for no data, 0 for no match and 1 for match */ static int search_banned_ip (char *ip) { recheck_cached_file (&banned_ip, cachefile_timecheck); if (banned_ip.wildcards) { struct list_node *entry = banned_ip.wildcards; while (entry) { if (compare_pattern (ip, entry->content) == 0) return 1; entry = entry->next; } } if (banned_ip.contents) { void *result; ban_entry_removal = NULL; if (avl_get_by_key (banned_ip.contents, ip, &result) == 0) { struct banned_entry *match = result; if (match->a.timeout == 0 || match->a.timeout > cachefile_timecheck) { if (match->a.timeout && cachefile_timecheck + 300 > match->a.timeout) match->a.timeout = cachefile_timecheck + 300; return 1; } avl_delete (banned_ip.contents, ip, cache_treenode_free); } /* we may of seen another one to remove */ if (ban_entry_removal) { INFO1 ("removing %s from ban list for now", &ban_entry_removal->ip[0]); avl_delete (banned_ip.contents, &ban_entry_removal->ip[0], cache_treenode_free); ban_entry_removal = NULL; } } return 0; }
bregonig *recompile_onig_ex(bregonig *rxold, pattern_type type, const TCHAR *ptn, const TCHAR *patternp, const TCHAR *patternendp, const TCHAR *prerepp, const TCHAR *prerependp, const TCHAR *optionp, const TCHAR *optionendp, TCHAR *msg) { int flag, compare; bregonig *rx; OnigOptionType option; OnigEncoding enc; TRACE0(_T("recompile_onig_ex()\n")); TRACE2(_T("patternp: %s, len: %d\n"), patternp, patternendp-patternp); TRACE2(_T("prerepp: %s, len: %d\n"), prerepp, prerependp-prerepp); TRACE2(_T("optionp: %s, len: %d\n"), optionp, optionendp-optionp); compare = compare_pattern(rxold, type, patternp, patternendp, prerepp, prerependp, optionp, optionendp); TRACE1(_T("compare: %d\n"), compare); if (compare < 0) { // need to compile delete rxold; rxold = NULL; if (patternp == NULL || ((type == PTN_SUBST || type == PTN_TRANS) && prerepp == NULL)) { asc2tcs(msg, "invalid reg parameter", BREGEXP_MAX_ERROR_MESSAGE_LEN); return NULL; } } else { // no need to compile if (rxold->outp) { delete [] rxold->outp; rxold->outp = NULL; } if (rxold->splitp) { delete [] rxold->splitp; rxold->splitp = NULL; } } parse_option(optionp, optionendp, &option, &enc, &flag); if (type == PTN_TRANS) { if (compare == 0) { // no need to compile TRACE1(_T("rxold(1):0x%08x\n"), rxold); return rxold; } rx = trcomp(patternp, patternendp, prerepp, prerependp, flag, msg); if (rx == NULL) { return NULL; } } else { if (compare == 0) { // no need to compile TRACE1(_T("rxold(2):0x%08x\n"), rxold); return rxold; } else if (compare < 0) { // pattern string needs to compile. rx = new (std::nothrow) bregonig(); if (rx == NULL) { asc2tcs(msg, "out of space regexp", BREGEXP_MAX_ERROR_MESSAGE_LEN); return NULL; } OnigErrorInfo err_info; int err_code = onig_new(&rx->reg, (UChar*) patternp, (UChar*) patternendp, option, enc, &OnigSyntaxPerl_NG_EX, &err_info); if (err_code != ONIG_NORMAL) { onig_err_to_bregexp_msg(err_code, &err_info, msg); delete rx; return NULL; } rx->nparens = onig_number_of_captures(rx->reg); // rx->pmflags = flag; } else { // only replace string needs to compile. rx = rxold; } if (rxold != NULL && rxold->repstr != NULL) { delete rxold->repstr; rxold->repstr = NULL; } if (type == PTN_SUBST) { // substitute try { rx->pmflags |= PMf_SUBSTITUTE; rx->repstr = compile_rep(rx, prerepp, prerependp); // compile replace string } catch (std::exception& ex) { asc2tcs(msg, ex.what(), BREGEXP_MAX_ERROR_MESSAGE_LEN); delete rx; return NULL; } } } if (ptn != NULL) { size_t plen = _tcslen(ptn); delete [] rx->parap; rx->parap = new (std::nothrow) TCHAR[plen+1]; // parameter copy if (rx->parap == NULL) { asc2tcs(msg, "precompile out of space", BREGEXP_MAX_ERROR_MESSAGE_LEN); delete rx; return NULL; } memcpy(rx->parap, ptn, (plen+1)*sizeof(TCHAR)); // copy include null rx->paraendp = rx->parap + plen; } TCHAR *oldpatternp = rx->patternp; if (patternp == NULL) { patternp = rx->patternp; patternendp = rx->patternendp; optionp = rx->optionp; optionendp = rx->optionendp; } /* save pattern, replace and option string */ ptrdiff_t len1 = patternendp - patternp; ptrdiff_t len2 = prerependp - prerepp; ptrdiff_t len3 = optionendp - optionp; rx->patternp = new (std::nothrow) TCHAR[len1+1 + len2+1 + len3+1]; if (rx->patternp == NULL) { delete rx; delete [] oldpatternp; return NULL; } memcpy(rx->patternp, patternp, len1*sizeof(TCHAR)); rx->patternp[len1] = 0; rx->patternendp = rx->patternp + len1; rx->prerepp = rx->patternp + len1 + 1; memcpy(rx->prerepp, prerepp, len2*sizeof(TCHAR)); rx->prerepp[len2] = 0; rx->prerependp = rx->prerepp + len2; rx->optionp = rx->prerepp + len2 + 1; memcpy(rx->optionp, optionp, len3*sizeof(TCHAR)); rx->optionp[len3] = 0; rx->optionendp = rx->optionp + len3; delete [] oldpatternp; TRACE1(_T("rx:0x%08x\n"), rx); return rx; }