コード例 #1
0
ファイル: hcache.c プロジェクト: larus/jamplus
void hcache_finalizerulemd5sum( TARGET *t )
{
	HCACHEDATA cachedata, *c = &cachedata;
	const char *target = t->name;
# ifdef DOWNSHIFT_PATHS
	char path[ MAXJPATH ];
	char *p;
# endif

	HCACHEFILE	*file = hcachefile_get( t );
	if ( !file->cachefilename )
		return;

# ifdef DOWNSHIFT_PATHS
	p = path;

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

	target = path;
# endif

	c->boundname = target;

	if( hashcheck( file->hcachehash, (HASHDATA **) &c )  &&  memcmp( &c->rulemd5sum, &c->currentrulemd5sum, MD5_SUMSIZE ) != 0 )
	{
		memcpy( &c->rulemd5sum, &c->currentrulemd5sum, MD5_SUMSIZE );
		file->dirty = 1;
	}
}
コード例 #2
0
ファイル: hcache.c プロジェクト: r1chi3x/jamplus
int hcache_getrulemd5sum( TARGET *t )
{
	HCACHEDATA cachedata, *c = &cachedata;
	const char *target = t->name;
# ifdef DOWNSHIFT_PATHS
	char path[ MAXJPATH ];
	char *p;
# endif

	HCACHEFILE	*file = hcachefile_get( t );
	if ( !file->cachefilename )
		return 1;

# ifdef DOWNSHIFT_PATHS
	p = path;

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

	target = path;
# endif

	c->boundname = target;

	if( hashcheck( hcachehash, (HASHDATA **) &c ) )
	{
		if( memcmp( &c->currentrulemd5sum, &t->rulemd5sum, MD5_SUMSIZE ) == 0 )
			return 1;

		memcpy( &c->currentrulemd5sum, &t->rulemd5sum, MD5_SUMSIZE );
	}
	else
	{
		// Enter it into the cache.
		if( hashenter( hcachehash, (HASHDATA **)&c ) )
		{
			c->boundname = newstr( c->boundname );
			c->file = file;
			c->next = c->file->hcachelist;
			c->file->hcachelist = c;
			c->mtime = 0;
			memcpy( &c->currentrulemd5sum, &t->rulemd5sum, MD5_SUMSIZE );
			memset( &c->rulemd5sum, 0, MD5_SUMSIZE );
			memset( &c->currentcontentmd5sum, 0, MD5_SUMSIZE );
			memset( &c->contentmd5sum, 0, MD5_SUMSIZE );
			c->time = 0;
			c->age = 0;
			c->includes = NULL;
			c->hdrscan = NULL;
		}
	}

	c->file->dirty = 1;

	return 0;
}
コード例 #3
0
ファイル: hcache.c プロジェクト: r1chi3x/jamplus
/*
 * Set cached md5sum of a file.
 */
void setcachedmd5sum( TARGET *t )
{
	HCACHEDATA cachedata, *c = &cachedata;
	const char *target = t->boundname;
# ifdef DOWNSHIFT_PATHS
	char path[ MAXJPATH ];
	char *p;
#endif

	HCACHEFILE	*file = hcachefile_get( t );

# ifdef DOWNSHIFT_PATHS
	p = path;

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

	target = path;
# endif

	c->boundname = target;

	if( !hashcheck( hcachehash, (HASHDATA **) &c ) )
	{
		if( hashenter( hcachehash, (HASHDATA **)&c ) ) {
			c->boundname = newstr( c->boundname );
			c->file = file;
			c->next = c->file->hcachelist;
			c->file->hcachelist = c;
			c->time = t->time;
			c->includes = NULL;
			c->hdrscan = NULL;
		}
	}

	c->file->dirty = 1;

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

	memcpy(c->rulemd5sum, t->rulemd5sum, sizeof(MD5SUM));
	memcpy(c->currentrulemd5sum, t->rulemd5sum, sizeof(MD5SUM));
	memcpy(c->contentmd5sum, t->contentmd5sum, sizeof(MD5SUM));
	memcpy(c->currentcontentmd5sum, t->contentmd5sum, sizeof(MD5SUM));
	c->mtime = t->time;
	c->age = 0;
}
コード例 #4
0
ファイル: hcache.c プロジェクト: larus/jamplus
/*
 * Get cached md5sum of a file. If none found, or not up to date, if the file is source
 * try to recalculate the sum. If not, then return empty sum (all zeroes).
 */
int getcachedmd5sum( TARGET *t, int source )
{
	HCACHEDATA cachedata, *c = &cachedata;
	int  use_cache = 1;
	HCACHEFILE *file;
	const char *target = t->boundname;
# ifdef DOWNSHIFT_PATHS
	char path[ MAXJPATH ];
	char *p;
#endif

	if ( t->contentmd5sum_calculated )
		return t->contentmd5sum_changed;

	if (!source) {
		memset(&t->buildmd5sum, 0, sizeof(t->buildmd5sum));
		memset(&t->contentmd5sum, 0, sizeof(t->contentmd5sum));
		t->contentmd5sum_calculated = 1;
		t->contentmd5sum_changed = 0;
		return t->contentmd5sum_changed;
	}

	file = hcachefile_get( t );

	++queries;

# ifdef DOWNSHIFT_PATHS
	p = path;

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

	target = path;
# endif

	c->boundname = target;

	if( hashcheck( file->hcachehash, (HASHDATA **) &c ) )
	{
		if ( t->time == 0 ) {
			/* This file was generated.  Grab its timestamp. */
			file_time( c->boundname, &c->mtime );
		} else if( c->mtime != t->time )
			use_cache = 0;

		if ( use_cache ) {
			use_cache = memcmp(md5sumempty, &c->contentmd5sum, sizeof(c->contentmd5sum)) != 0;
		}

		if( use_cache ) {
			if( DEBUG_MD5HASH )
				printf( "- content md5: %s (%s)\n", t->boundname, md5tostring(c->contentmd5sum));
			c->age = 0; /* The entry has been used, its young again */
			++hits;
			t->contentmd5sum_changed = 0;
			memcpy(&t->contentmd5sum, &c->contentmd5sum, sizeof(t->contentmd5sum));
			t->contentmd5sum_calculated = 1;
			return t->contentmd5sum_changed;
		}
		else {
			if( DEBUG_MD5HASH )
				printf( "md5 cache out of date for %s (time %d, md5time %d)\n", t->boundname , (int)t->time, (int)c->mtime );
		}
	} else {
		if( hashenter( file->hcachehash, (HASHDATA **)&c ) ) {
			c->boundname = newstr( c->boundname );
			c->next = file->hcachelist;
			file->hcachelist = c;
			c->time = 0;
			c->includes = NULL;
			c->hdrscan = NULL;
		}
	}

	file->dirty = 1;

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

	{
		MD5SUM origmd5sum;
#ifdef OPT_BUILTIN_LUA_SUPPORT_EXT
		LIST *md5callback;
#endif

		memcpy( &origmd5sum, &c->contentmd5sum, sizeof( MD5SUM ) );
#ifdef OPT_BUILTIN_LUA_SUPPORT_EXT
		pushsettings( t->settings );
		md5callback = var_get( "MD5CALLBACK" );
		popsettings( t->settings );

		if ( md5callback )
		{
			luahelper_md5callback(t->boundname, c->contentmd5sum, md5callback->string);
		}
		else
		{
#endif
			md5file( t->boundname, c->contentmd5sum );
#ifdef OPT_BUILTIN_LUA_SUPPORT_EXT
		}
#endif
		t->contentmd5sum_changed = memcmp( &origmd5sum, &c->contentmd5sum, sizeof( MD5SUM ) ) != 0;
	}
	if( DEBUG_MD5HASH )
		printf( "- content md5: %s (%s)\n", t->boundname, md5tostring(c->contentmd5sum));

	c->mtime = t->time;
	if ( c->mtime == 0 ) {
		/* This file was generated.  Grab its timestamp. */
		file_time( c->boundname, &c->mtime );
	}
	c->age = 0;
	memcpy(&t->contentmd5sum, &c->contentmd5sum, sizeof(t->contentmd5sum));
	t->contentmd5sum_calculated = (char)(memcmp(md5sumempty, &t->contentmd5sum, sizeof(t->contentmd5sum)) != 0);
	memset(&t->buildmd5sum, 0, sizeof(t->buildmd5sum));

	return t->contentmd5sum_changed;
}
コード例 #5
0
ファイル: hcache.c プロジェクト: larus/jamplus
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;
}