Ejemplo n.º 1
0
HEADER *headersDepth(const char *t, time_t time, int depth)
{
	HEADER hdr, *h = &hdr;
	LIST *l;
	const char* cachekey=t;

	/* D support (doesn't affect C(++), because a source file is never included) */
	if(depth == 0)
	{
		cachekey=malloc(strlen(t)+sizeof("source:"));
		strcpy((char*)cachekey,"source:");
		strcpy((char*)cachekey+7,t);
	}
	
	if (!headerhash)
		headerhash = hashinit(sizeof(HEADER), "headers");

	h->key = cachekey;
	h->includes = 0;
	h->time = time;
	h->headers = 0;
	h->newest = 0;
	if (!hashenter(headerhash, (HASHDATA **)&h))
		return h;

	h->key = newstr(t);
#ifdef USE_CACHE
	if (!cache_check(cachekey, time, &h->includes))
	{
		h->includes = headers1(t, depth);
		cache_enter(cachekey, time, h->includes);
	}
#else
	h->includes = headers1(t, depth);
#endif
	if(depth == 0)
		free((char*)cachekey);

	l = h->includes;
	while (l)
	{
		const char *t2 = search(t, l->string, &time);
		if (time)
			h->headers = headerentry(h->headers, headersDepth(t2, time, depth+1));
		l = list_next(l);
	}

	return h;
}
Ejemplo n.º 2
0
void
headers( TARGET *t )
{
	LIST	*hdrscan;
	LIST	*hdrrule;
	LIST	*hdrcache;
	LOL	lol;

	if( !( hdrscan = var_get( "HDRSCAN" ) ) || 
	    !( hdrrule = var_get( "HDRRULE" ) ) )
	        return;

	/* Doctor up call to HDRRULE rule */
	/* Call headers1() to get LIST of included files. */

	if( DEBUG_HEADER )
	    printf( "header scan %s\n", t->name );

	lol_init( &lol );

	lol_add( &lol, list_new( L0, t->name, 1 ) );
	lol_add( &lol, headers1( t->boundname, hdrscan ) );

	if( lol_get( &lol, 1 ) )
	    list_free( evaluate_rule( 0, hdrrule->string, &lol, L0 ) );

	/* Clean up */

	lol_free( &lol );
}
Ejemplo n.º 3
0
void
headers( TARGET * t )
{
    LIST   * hdrscan;
    LIST   * hdrrule;
	#ifndef OPT_HEADER_CACHE_EXT
    LIST   * headlist = L0;
	#endif
    regexp * re[ MAXINC ];
    int rec = 0;
    LISTITER iter, end;

    hdrscan = var_get( root_module(), constant_HDRSCAN );
    if ( list_empty( hdrscan ) )
        return;

    hdrrule = var_get( root_module(), constant_HDRRULE );
    if ( list_empty( hdrrule ) )
        return;

    if ( DEBUG_HEADER )
        printf( "header scan %s\n", object_str( t->name ) );

    /* Compile all regular expressions in HDRSCAN */
    iter = list_begin( hdrscan ), end = list_end( hdrscan );
    for ( ; ( rec < MAXINC ) && iter != end; iter = list_next( iter ) )
    {
        re[ rec++ ] = regex_compile( list_item( iter ) );
    }

    /* Doctor up call to HDRRULE rule */
    /* Call headers1() to get LIST of included files. */
    {
        FRAME   frame[1];
        frame_init( frame );
        lol_add( frame->args, list_new( object_copy( t->name ) ) );
#ifdef OPT_HEADER_CACHE_EXT
        lol_add( frame->args, hcache( t, rec, re, hdrscan ) );
#else
        lol_add( frame->args, headers1( headlist, t->boundname, rec, re ) );
#endif

        if ( lol_get( frame->args, 1 ) )
        {
            /* The third argument to HDRRULE is the bound name of
             * $(<) */
            lol_add( frame->args, list_new( object_copy( t->boundname ) ) );

            list_free( evaluate_rule( list_front( hdrrule ), frame ) );
        }

        /* Clean up. */
        frame_free( frame );
    }
}
Ejemplo n.º 4
0
void
headers( TARGET *t )
{
    LIST	*hdrscan;
    LIST	*hdrrule;
    LIST	*headlist = 0;
    regexp	*re[ MAXINC ];
    int	rec = 0;
        
    if( !( hdrscan = var_get( "HDRSCAN" ) ) || 
        !( hdrrule = var_get( "HDRRULE" ) ) )
        return;

    if( DEBUG_HEADER )
        printf( "header scan %s\n", t->name );

    /* Compile all regular expressions in HDRSCAN */

    while( rec < MAXINC && hdrscan )
    {
        re[rec++] = regex_compile( hdrscan->string );
        hdrscan = list_next( hdrscan );
    }

    /* Doctor up call to HDRRULE rule */
    /* Call headers1() to get LIST of included files. */
    {
        FRAME	frame[1];
        frame_init( frame );
        lol_add( frame->args, list_new( L0, t->name ) );
#ifdef OPT_HEADER_CACHE_EXT
        lol_add( frame->args, hcache( t, rec, re, hdrscan ) );
#else
        lol_add( frame->args, headers1( headlist, t->boundname, rec, re ) );
#endif

        if( lol_get( frame->args, 1 ) )
        {
            /* The third argument to HDRRULE is the bound name of
             * $(<) */
            lol_add( frame->args, list_new( L0, t->boundname ) );

            list_free( evaluate_rule( hdrrule->string, frame ) );
        }

        /* Clean up */

        frame_free( frame );
    }
}
Ejemplo n.º 5
0
void
headers( TARGET *t )
{
	LIST	*hdrscan;
	LIST	*hdrrule;
	LOL	lol;

	if( !list_first( hdrscan = var_get( "HDRSCAN" ) ) ||
	    !list_first( hdrrule = var_get( "HDRRULE" ) ) )
	        return;

	/* Doctor up call to HDRRULE rule */
	/* Call headers1() to get LIST of included files. */

	if( DEBUG_HEADER )
	    printf( "header scan %s\n", t->name );

	lol_init( &lol );

	lol_add( &lol, list_append( L0, t->name, 1 ) );
#ifdef OPT_HEADER_CACHE_EXT
	lol_add( &lol, hcache( t, hdrscan ) );
#else
	lol_add( &lol, headers1( t->boundname, hdrscan ) );
#endif

	if( list_first(lol_get( &lol, 1 )) )
	{
#ifdef OPT_HDRRULE_BOUNDNAME_ARG_EXT
	    /* The third argument to HDRRULE is the bound name of
	     * $(<) */
	    lol_add( &lol, list_append( L0, t->boundname, 0 ) );
#endif
	    list_free( evaluate_rule( list_value(list_first(hdrrule)), &lol, L0 ) );
	}

	/* Clean up */

	lol_free( &lol );
}
Ejemplo n.º 6
0
LIST *
	hcache( TARGET *t, LIST *hdrscan )
{
	HCACHEDATA	cachedata, *c = &cachedata;
	HCACHEFILE	*file;
	LIST	*l = 0;
	int		use_cache = 1;
	const char *target;
# ifdef DOWNSHIFT_PATHS
	char path[ MAXJPATH ];
	char *p;
# endif

	target = t->boundname;

# ifdef DOWNSHIFT_PATHS
	p = path;

	do *p++ = (char)tolower( *target );
	while( *target++ );

	target = path;
# endif

	++queries;

	c->boundname = target;

	file = hcachefile_get( t );
	//    if ( file )
	{
		if( hashcheck( file->hcachehash, (HASHDATA **) &c ) )
		{
#ifdef OPT_BUILTIN_MD5CACHE_EXT
			if( c->time == t->time  &&  md5matchescommandline( t ) )
#else
			if( c->time == t->time )
#endif
			{
				LIST *l1 = hdrscan, *l2 = c->hdrscan;
				while( l1 && l2 ) {
					if( l1->string != l2->string ) {
						l1 = 0;
					} else {
						l1 = list_next( l1 );
						l2 = list_next( l2 );
					}
				}
				if( l1 || l2 )
					use_cache = 0;
			}
			else
				use_cache = 0;

			if( use_cache ) {
				if( DEBUG_HEADER )
					printf( "using header cache for %s\n", t->boundname );
				c->age = 0; /* The entry has been used, its young again */
				++hits;
				l = list_copy( 0, c->includes );
				{
					LIST *hdrfilter = var_get( "HDRFILTER" );
					if ( hdrfilter )
					{
						LOL lol;
						lol_init( &lol );
						lol_add( &lol, list_new( L0, t->name, 1 ) );
						lol_add( &lol, l );
						lol_add( &lol, list_new( L0, t->boundname, 0 ) );
						l = evaluate_rule( hdrfilter->string, &lol, L0 );
						lol_free( &lol );
					}
				}
				return l;
			}
			else {
				if( DEBUG_HEADER )
					printf( "header cache out of date for %s\n", t->boundname );
				list_free( c->includes );
				list_free( c->hdrscan );
				c->includes = 0;
				c->hdrscan = 0;
			}
		} else {
			if( hashenter( file->hcachehash, (HASHDATA **)&c ) ) {
				c->boundname = newstr( c->boundname );
				c->next = file->hcachelist;
				file->hcachelist = c;
#ifdef OPT_BUILTIN_MD5CACHE_EXT
				c->mtime = 0;
				memset( &c->rulemd5sum, 0, MD5_SUMSIZE );
				memset( &c->currentrulemd5sum, 0, MD5_SUMSIZE );
				memset( &c->contentmd5sum, 0, MD5_SUMSIZE );
				memset( &c->currentcontentmd5sum, 0, MD5_SUMSIZE );
#endif
			}
		}
	}

	file->dirty = 1;

	/* 'c' points at the cache entry.  Its out of date. */

	l = headers1( c->boundname, hdrscan );

	l = list_append( list_copy( 0, var_get( "HDREXTRA" ) ), l );

	c->includes = list_copy( 0, l );

	{
		LIST *hdrfilter = var_get( "HDRFILTER" );
		if ( hdrfilter )
		{
			LOL lol;
			lol_init( &lol );
			lol_add( &lol, list_new( L0, t->name, 1 ) );
			lol_add( &lol, l );
			lol_add( &lol, list_new( L0, t->boundname, 0 ) );
			l = evaluate_rule( hdrfilter->string, &lol, L0 );
			lol_free( &lol );
		}
	}

	c->time = t->time;
	c->age = 0;

	c->hdrscan = list_copy( 0, hdrscan );

	return l;
}
Ejemplo n.º 7
0
LIST *
hcache (TARGET *t, int rec, regexp *re[], LIST *hdrscan)
{
    HCACHEDATA  cachedata, *c = &cachedata;
    LIST 	*l = 0;

    ++queries;

    c->boundname = t->boundname;

    if (hashcheck (hcachehash, (HASHDATA **) &c))
    {
	if (c->time == t->time)
	{
	    LIST *l1 = hdrscan, *l2 = c->hdrscan;
	    while (l1 && l2) {
		if (l1->string != l2->string) {
		    l1 = NULL;
		} else {
		    l1 = list_next(l1);
		    l2 = list_next(l2);
		}
	    }
	    if (l1 || l2) {
		if (DEBUG_HEADER)
		    printf("HDRSCAN out of date in cache for %s\n",
			   t->boundname);

		printf("HDRSCAN out of date for %s\n", t->boundname);
		printf(" real  : ");
		list_print(hdrscan);
		printf("\n cached: ");
		list_print(c->hdrscan);
		printf("\n");

		list_free(c->includes);
		list_free(c->hdrscan);
		c->includes = 0;
		c->hdrscan = 0;
	    } else {
		if (DEBUG_HEADER)
		    printf ("using header cache for %s\n", t->boundname);
		c->age = 0;
		++hits;
		l = list_copy (0, c->includes);
		return l;
	    }
	} else {
	    if (DEBUG_HEADER)
	        printf ("header cache out of date for %s\n", t->boundname);
	    list_free (c->includes);
	    list_free(c->hdrscan);
	    c->includes = 0;
	    c->hdrscan = 0;
	}
    } else {
	if (hashenter (hcachehash, (HASHDATA **)&c)) {
	    c->boundname = newstr (c->boundname);
	    c->next = hcachelist;
	    hcachelist = c;
	}
    }

    /* 'c' points at the cache entry.  Its out of date. */

    l = headers1 (0, t->boundname, rec, re);

    c->time = t->time;
    c->age = 0;
    c->includes = list_copy (0, l);
    c->hdrscan = list_copy(0, hdrscan);

    return l;
}
Ejemplo n.º 8
0
LIST * hcache( TARGET * t, int rec, regexp * re[], LIST * hdrscan )
{
    HCACHEDATA * c;

    LIST * l = 0;

    ++queries;

    if ( ( c = (HCACHEDATA *)hash_find( hcachehash, t->boundname ) ) )
    {
        if ( c->time == t->time )
        {
            LIST *l1 = hdrscan, *l2 = c->hdrscan;
            LISTITER iter1 = list_begin( l1 ), end1 = list_end( l1 ),
                iter2 = list_begin( l2 ), end2 = list_end( l2 );
            while ( iter1 != end1 && iter2 != end2 )
            {
                if ( !object_equal( list_item( iter1 ), list_item( iter2 ) ) )
                {
                    iter1 = end1;
                }
                else
                {
                    iter1 = list_next( iter1 );
                    iter2 = list_next( iter2 );
                }
            }
            if ( iter1 != end1 || iter2 != end2 )
            {
                if (DEBUG_HEADER)
                    printf( "HDRSCAN out of date in cache for %s\n",
                        object_str( t->boundname ) );

                printf( "HDRSCAN out of date for %s\n",
                    object_str( t->boundname ) );
                printf(" real  : ");
                list_print( hdrscan );
                printf( "\n cached: " );
                list_print( c->hdrscan );
                printf( "\n" );

                list_free( c->includes );
                list_free( c->hdrscan );
                c->includes = L0;
                c->hdrscan = L0;
            }
            else
            {
                if (DEBUG_HEADER)
                    printf( "using header cache for %s\n",
                        object_str( t->boundname ) );
                c->age = 0;
                ++hits;
                l = list_copy( c->includes );
                return l;
            }
        }
        else
        {
            if (DEBUG_HEADER)
                printf ("header cache out of date for %s\n",
                    object_str( t->boundname ) );
            list_free( c->includes );
            list_free( c->hdrscan );
            c->includes = L0;
            c->hdrscan = L0;
        }
    }
    else
    {
        int found;
        c = (HCACHEDATA *)hash_insert( hcachehash, t->boundname, &found );
        if ( !found )
        {
            c->boundname = object_copy( t->boundname );
            c->next = hcachelist;
            hcachelist = c;
        }
    }

    /* 'c' points at the cache entry. Its out of date. */

    l = headers1( L0, t->boundname, rec, re );

    c->time = t->time;
    c->age = 0;
    c->includes = list_copy( l );
    c->hdrscan = list_copy( hdrscan );

    return l;
}