コード例 #1
0
ファイル: filters.c プロジェクト: OS2World/LIB-libasvtools
/*******************************************************
 check 'str' against NULL-terminated exclusion list 'excl'.
 if first symbol of exclusion pattern is ^, treat as
 exclude pattern, otherwise treat as include pattern.
 returns '1' if item is to be processed, and '0' if ignored.
 result depends on the order of pattern entries! this version
 supports pattern groups (lines beginning with '+' are treated
 as separators) */
int check_list (char **excl, char *str)
{
    int  i, skip;

    /* we have two states while scanning the list of rules:
     1. we are looking at the patterns
     2. we are skipping to the next group terminator.
     Skipping occurs when we hit exclusion pattern. */
    skip = FALSE;
    for (i=0; excl[i]; i++)
    {
        switch (excl[i][0])
        {
        case '^':
            /* exclusion pattern */
            if (skip) continue;
            if (!fnmatch2 (excl[i]+1, str, 0)) skip = TRUE;
            break;

        case '+':
            /* group terminator */
            skip = FALSE;
            break;

        default:
            /* inclusion pattern */
            if (skip) continue;
            if (!fnmatch2 (excl[i], str, 0)) return 1;
        }
    }

    /* did not match any inclusion pattern; return 'ignore' */
    return 0;
}
コード例 #2
0
ファイル: filters.c プロジェクト: OS2World/LIB-libasvtools
/*******************************************************
 check 'str' against exclusion list 'excl' which has 'n'
 elements (see check_list). pattern groups are NOT supported.
 returns '1' if 'str' is included, and '0' if not. */
int check_nlist (char **excl, int n, char *str)
{
    int  i;

    for (i=0; i<n; i++)
    {
        switch (excl[i][0])
        {
        case '^':
            /* exclusion pattern */
            if (!fnmatch2 (excl[i]+1, str, 0)) return 0;
            break;

        default:
            /* inclusion pattern */
            if (!fnmatch2 (excl[i], str, 0)) return 1;
        }
    }

    /* did not match any inclusion pattern; return 'ignore' */
    return 0;
}
コード例 #3
0
ファイル: dump_file.c プロジェクト: roderickmackenzie/gpvdm
void dumpfiles_process(struct simulation* sim,struct istruct *in,char *name)
{
	int i;
	for (i=0;i<sim->dumpfiles;i++)
	{

		if (fnmatch2(sim->dumpfile[i].filename, name)==0)
		{
			if (sim->dumpfile[i].ynorm==TRUE)
			{
				inter_norm(in,1.0);
			}

			return;
		}


	}

}
コード例 #4
0
ファイル: dump_file.c プロジェクト: roderickmackenzie/gpvdm
int dumpfiles_should_dump(struct simulation* sim,char *name)
{
	int i;
	for (i=0;i<sim->dumpfiles;i++)
	{
 	
		if (fnmatch2(sim->dumpfile[i].filename, name)==0)
		{
			if (sim->dumpfile[i].dump==TRUE)
			{
				return 0;
			}else
			{
				return -1;
			}
		}
	}

return 0;
}
コード例 #5
0
ファイル: filters.c プロジェクト: OS2World/LIB-libasvtools
/* returns list of categories assigned to given URL. uses fast
 representation */
int fast_category_check (fastlist_t *fl, char *str, int **categories)
{
    int  /*included, excluded,*/ rc, left, right;
    int  ncats, ncats_a, *cats;
    int  i, j, n, skip, icr;
    int  rulehit[MAXNUMHITS], n_included, n_excluded;
    /* double t1, t_simple, t_complex; */

    ncats_a = 8;
    ncats   = 0;
    cats    = xmalloc (sizeof(int) * ncats_a);

    /* if we are analyzing ruleset which mostly consists of complex rules
     do not try optimizations */
    if (fl->n_simple < fl->n_complex)
    {
        /* printf ("going to straightforward check; %d < %d\n", */
        /*        fl->n_simple, fl->n_complex); */
        goto straightforward_check;
    }

    n_excluded = 0;
    n_included = 0;

    /* first we run our string through simple and complex rules */
    /* t1 = clock1 (); */
    if (fl->n_simple > 0)
    {
        fl1 = fl;
        str1 = str;
        icr = -1;
        rc = bracket (&icr, fl->simple, fl->n_simple, sizeof(int),
                      cmp_simple2, &left, &right);
        switch (rc)
        {
        case -2: left = right = fl->n_simple-1; break;
        case -1: left = right = 0; break;
        case 0:
        case 1:  break;
        }
        for (i=left; i<=right; i++)
        {
            switch (fl->rules[fl->simple[i]].type)
            {
            case RULETYPE_MATCH:
                if (strcmp (fl->rules[fl->simple[i]].rule, str) == 0 &&
                    fl->rules[fl->simple[i]].category != 0)
                {
                    if (n_included+n_excluded == MAXNUMHITS) goto straightforward_check;
                    rulehit[n_included++ + n_excluded] = fl->simple[i];
                }
                break;
    
            case RULETYPE_MATCH_NEG:
                if (strcmp (fl->rules[fl->simple[i]].rule, str) == 0 &&
                    fl->rules[fl->simple[i]].category != 0)
                {
                    if (n_included+n_excluded == MAXNUMHITS) goto straightforward_check;
                    rulehit[n_included + n_excluded++] = - fl->simple[i];
                }
                break;
    
            case RULETYPE_SIMPLE:
                if (memcmp (fl->rules[fl->simple[i]].rule, str,
                            fl->rules[fl->simple[i]].len) == 0 &&
                    fl->rules[fl->simple[i]].category != 0)
                {
                    if (n_included+n_excluded == MAXNUMHITS) goto straightforward_check;
                    rulehit[n_included++ + n_excluded] = fl->simple[i];
                }
                break;
    
            case RULETYPE_SIMPLE_NEG:
                if (memcmp (fl->rules[fl->simple[i]].rule, str,
                            fl->rules[fl->simple[i]].len) == 0 &&
                    fl->rules[fl->simple[i]].category != 0)
                {
                    if (n_included+n_excluded == MAXNUMHITS) goto straightforward_check;
                    rulehit[n_included + n_excluded++] = - fl->simple[i];
                }
                break;
            }
        }
    }
    /* t_simple = clock1 () - t1; */

    /* then we scan complex rules */
    /* t1 = clock1 (); */
    for (i=0; i<fl->n_complex; i++)
    {
        switch (fl->rules[fl->complex[i]].type)
        {
        case RULETYPE_COMPLEX:
            if (fnmatch2 (fl->rules[fl->complex[i]].rule, str, 0) == 0 &&
                fl->rules[fl->complex[i]].category != 0)
            {
                if (n_included+n_excluded == MAXNUMHITS) goto straightforward_check;
                rulehit[n_included++ + n_excluded] = fl->complex[i];
            }
            break;

        case RULETYPE_COMPLEX_NEG:
            if (fnmatch2 (fl->rules[fl->complex[i]].rule, str, 0) == 0 &&
                fl->rules[fl->complex[i]].category != 0)
            {
                if (n_included+n_excluded == MAXNUMHITS) goto straightforward_check;
                rulehit[n_included + n_excluded++] = - fl->complex[i];
            }
            break;
        }
    }
    /* t_complex = clock1() - t1; */

    /* printf ("%d sim (%.3f sec), %d com (%.3f), %d inc, %d exc\n", */
    /*        fl->n_simple, t_simple, fl->n_complex, t_complex, n_included, n_excluded); */

    /* two simple cases */
    if (n_included == 0)
    {
        free (cats);
        return 0;
    }
    if (n_excluded == 0)
    {
        ncats = n_included + n_excluded;
        if (ncats > ncats_a)
        {
            ncats_a = ncats;
            free (cats);
            cats = xmalloc (sizeof(int) * ncats_a);
        }
        for (i=0, j=0; i<ncats; i++)
        {
            if (fl->rules[rulehit[i]].category != 0)
                cats[j++] = fl->rules[rulehit[i]].category;
        }
        ncats = j;
        if (ncats == 0) free (cats);
        else            *categories = cats;
        return ncats;
    }

    /* more complex case. both included and excluded are present */
    n = n_included+n_excluded;
    qsort (rulehit, n, sizeof(int), cmp_absintegers);
    /* for (i=0; i<n; i++) printf ("%d ", rulehit[i]); */
    /* printf ("\n"); */

    /* we have the list of rules which fit to our sample. determining
     to what categories sample belongs: we scan the list of rules. if
     current rule indicates 'true' we add its category to the list.
     if current rule indicates 'false' we skip following rules which
     have the same category as current. */
    skip = FALSE;
    for (i=0; i<n; /* don't increment!*/)
    {
        /* printf ("analyzing %d\n", rulehit[i]); */
        if (rulehit[i] > 0)
        {
            if (ncats == ncats_a)
            {
                ncats_a *= 2;
                cats = xrealloc (cats, sizeof(int)* ncats_a);
            }
            cats[ncats++] = fl->rules[rulehit[i]].category;
        }
        if (rulehit[i] < 0)
        {
            for (j=i+1; j<n; j++)
            {
                if (fl->rules[abs(rulehit[j])].category !=
                    fl->rules[abs(rulehit[i])].category) break;
                /* printf ("skipping %d\n", rulehit[j]); */
            }
            i=j;
        }
        else
        {
            i++;
        }
    }
    *categories = cats;
    return ncats;

straightforward_check:

    /* we have two states while scanning the list of rules:
     1. we are looking at the patterns
     2. we are skipping to the next group terminator.
     Skipping occurs when we hit exclusion pattern. */
    skip = FALSE;
    ncats = 0;
    for (i=0; i<fl->n; i++)
    {
        switch (fl->rules[i].type)
        {
        case RULETYPE_COMPLEX:
            if (skip) continue;
            if (fnmatch2 (fl->rules[i].rule, str, 0) == 0 &&
                fl->rules[i].category != 0)
            {
                if (ncats == ncats_a)
                {
                    ncats_a *= 2;
                    cats = xrealloc (cats, sizeof(int)* ncats_a);
                }
                cats[ncats++] = fl->rules[i].category;
            }
            break;

        case RULETYPE_COMPLEX_NEG:
            if (skip) continue;
            if (fnmatch2 (fl->rules[i].rule, str, 0) == 0) skip = TRUE;
            break;

        case RULETYPE_MATCH:
            if (skip) continue;
            if (strcmp (fl->rules[i].rule, str) == 0 &&
                fl->rules[i].category != 0)
            {
                if (ncats == ncats_a)
                {
                    ncats_a *= 2;
                    cats = xrealloc (cats, sizeof(int)* ncats_a);
                }
                cats[ncats++] = fl->rules[i].category;
            }
            break;

        case RULETYPE_MATCH_NEG:
            if (skip) continue;
            if (strcmp (fl->rules[i].rule, str) == 0) skip = TRUE;
            break;

        case RULETYPE_SIMPLE:
            if (skip) continue;
            if (memcmp (fl->rules[i].rule, str, fl->rules[i].len) == 0 &&
                fl->rules[i].category != 0)
            {
                if (ncats == ncats_a)
                {
                    ncats_a *= 2;
                    cats = xrealloc (cats, sizeof(int)* ncats_a);
                }
                cats[ncats++] = fl->rules[i].category;
            }
            break;

        case RULETYPE_SIMPLE_NEG:
            if (skip) continue;
            if (memcmp (fl->rules[i].rule, str, fl->rules[i].len) == 0) skip = TRUE;
            break;

        case RULETYPE_SEPARATOR:
            skip = FALSE;
            break;

        case RULETYPE_SUBCATS:
            break;
        }
    }

    if (ncats == 0) free (cats);
    else            *categories = cats;

    return ncats;
}
コード例 #6
0
ファイル: filters.c プロジェクト: OS2World/LIB-libasvtools
/* similar to check_list() but significantly faster on large rule lists */
int check_fastlist (fastlist_t *fl, char *str)
{
    int i, j, n, skip, icr, rc, left, right;
    int rulehit[MAXNUMHITS], n_included, n_excluded;

    /* if we are analyzing ruleset which mostly consists of complex rules
     do not try optimizations */
    if (fl->n_simple < fl->n_complex) goto straightforward_check;

    n_excluded = 0;
    n_included = 0;

    /* first we run our string through simple and complex rules */
    if (fl->n_simple > 0)
    {
        fl1 = fl;
        str1 = str;
        icr = -1;
        rc = bracket (&icr, fl->simple, fl->n_simple, sizeof(int),
                      cmp_simple2, &left, &right);
        switch (rc)
        {
        case -2: left = right = fl->n_simple-1; break;
        case -1: left = right = 0; break;
        case 0:
        case 1:  break;
        }
        for (i=left; i<=right; i++)
        {
            switch (fl->rules[fl->simple[i]].type)
            {
            case RULETYPE_MATCH:
                if (strcmp (fl->rules[fl->simple[i]].rule, str) == 0)
                {
                    if (n_included+n_excluded == MAXNUMHITS) goto straightforward_check;
                    rulehit[n_included++ + n_excluded] = fl->simple[i];
                }
                break;
    
            case RULETYPE_MATCH_NEG:
                if (strcmp (fl->rules[fl->simple[i]].rule, str) == 0)
                {
                    if (n_included+n_excluded == MAXNUMHITS) goto straightforward_check;
                    rulehit[n_included + n_excluded++] = - fl->simple[i];
                }
                break;
    
            case RULETYPE_SIMPLE:
                if (memcmp (fl->rules[fl->simple[i]].rule, str,
                            fl->rules[fl->simple[i]].len) == 0)
                {
                    if (n_included+n_excluded == MAXNUMHITS) goto straightforward_check;
                    rulehit[n_included++ + n_excluded] = fl->simple[i];
                }
                break;
    
            case RULETYPE_SIMPLE_NEG:
                if (memcmp (fl->rules[fl->simple[i]].rule, str,
                            fl->rules[fl->simple[i]].len) == 0)
                {
                    if (n_included+n_excluded == MAXNUMHITS) goto straightforward_check;
                    rulehit[n_included + n_excluded++] = - fl->simple[i];
                }
                break;
            }
        }
    }

    /* then we scan complex rules */
    for (i=0; i<fl->n_complex; i++)
    {
        switch (fl->rules[fl->complex[i]].type)
        {
        case RULETYPE_COMPLEX:
            if (fnmatch2 (fl->rules[fl->complex[i]].rule, str, 0) == 0)
            {
                if (n_included+n_excluded == MAXNUMHITS) goto straightforward_check;
                rulehit[n_included++ + n_excluded] = fl->complex[i];
            }
            break;

        case RULETYPE_COMPLEX_NEG:
            if (fnmatch2 (fl->rules[fl->complex[i]].rule, str, 0) == 0)
            {
                if (n_included+n_excluded == MAXNUMHITS) goto straightforward_check;
                rulehit[n_included + n_excluded++] = - fl->complex[i];
            }
            break;
        }
    }

    /* printf ("%d simple, %d complex, %d included, %d excluded\n", */
    /*        fl->n_simple, fl->n_complex, n_included, n_excluded); */

    /* two simple cases */
    if (n_included == 0) return FALSE;
    if (n_excluded == 0) return TRUE;

    /* more complex case. both included and excluded are present */
    n = n_included+n_excluded;
    qsort (rulehit, n, sizeof(int), cmp_absintegers);
    /* for (i=0; i<n; i++) printf ("%d ", rulehit[i]); */
    /* printf ("\n"); */

    /* we have the list of rules which fit to our sample. determining
     whether sample is included: we scan the list of rules. at first
     we have no category and sample is excluded. if current rule indicates
     'true' we signal 'included'. if current rule indicates 'false' we skip
     following rules which have the same category as current. at the end
     we signal 'excluded'. */
    skip = FALSE;
    for (i=0; i<n; /* don't increment!*/)
    {
        /* printf ("analyzing %d\n", rulehit[i]); */
        if (rulehit[i] > 0) return TRUE;
        if (rulehit[i] < 0)
        {
            for (j=i+1; j<n; j++)
            {
                if (fl->rules[abs(rulehit[j])].category !=
                    fl->rules[abs(rulehit[i])].category) break;
                /* printf ("skipping %d\n", rulehit[j]); */
            }
            i=j;
        }
        else
        {
            i++;
        }
    }
    return FALSE;

straightforward_check:

    /* we have two states while scanning the list of rules:
     1. we are looking at the patterns
     2. we are skipping to the next group terminator.
     Skipping occurs when we hit exclusion pattern. */
    skip = FALSE;
    for (i=0; i<fl->n; i++)
    {
        switch (fl->rules[i].type)
        {
        case RULETYPE_COMPLEX:
            if (skip) continue;
            if (fnmatch2 (fl->rules[i].rule, str, 0) == 0) return 1;
            break;

        case RULETYPE_COMPLEX_NEG:
            if (skip) continue;
            if (fnmatch2 (fl->rules[i].rule, str, 0) == 0) skip = TRUE;
            break;

        case RULETYPE_MATCH:
            if (skip) continue;
            if (strcmp (fl->rules[i].rule, str) == 0) return 1;
            break;

        case RULETYPE_MATCH_NEG:
            if (skip) continue;
            if (strcmp (fl->rules[i].rule, str) == 0) skip = TRUE;
            break;

        case RULETYPE_SIMPLE:
            if (skip) continue;
            if (memcmp (fl->rules[i].rule, str, fl->rules[i].len) == 0) return 1;
            break;

        case RULETYPE_SIMPLE_NEG:
            if (skip) continue;
            if (memcmp (fl->rules[i].rule, str, fl->rules[i].len) == 0) skip = TRUE;
            break;

        case RULETYPE_SEPARATOR:
            skip = FALSE;
            break;

        case RULETYPE_SUBCATS:
            /* ignored here */
            break;
        }
    }

    /* did not match any inclusion pattern; return 'ignore' */
    return 0;
}