Esempio n. 1
0
/*
 * Read a string from the file.	 Handle quoted characters.  The
 * returned value is as returned by newstr(), so it need not be freed.
 */
const char *
read_string( BUFFER* buff )
{
	int ch, i = 0;
	char filename[ MAXJPATH ];

	ch = skip_spaces( buff );
	if( ch != '@' )
		return 0;

	ch = buffer_getchar( buff );
	while( ch != '@' && ch != EOF && i < MAXJPATH ) {
		if( ch == '#' ) /* Quote */
			filename[ i++ ] = buffer_getchar( buff );
		else
			filename[ i++ ] = (char)ch;
		ch = buffer_getchar( buff );
	}

	if( ch != '@' )
		return 0;

	filename[ i ] = 0;
	return newstr( filename );
}
Esempio n. 2
0
/*
 * Read any spaces we're on.  Return the first non-space character
 */
static int
skip_spaces( BUFFER *buff )
{
	int ch = buffer_getchar( buff );

	while( ch == ' ' )
		ch = buffer_getchar( buff );

	return ch;
}
Esempio n. 3
0
/*
 * Read a md5sum.
 */
void read_md5sum( BUFFER *buff, MD5SUM sum )
{
	int ch, i, val;
	memset(sum, 0, sizeof(*sum));

	ch = skip_spaces( buff );
	val = 0;
	i = 0;
	while( i < MD5_SUMSIZE*2 ) {
		ch = tolower( ch );
		if (ch >= '0' && ch <='9') {
			val = val*16 + ch-'0';
		} else if (ch >= 'a' && ch <='f') {
			val = val*16 + ch-'a'+0xa;
		} else {
			break;
		}
		if ( i&1 ) {
			sum[i/2] = (char)val;
			val = 0;
		}
		i++;
		ch = buffer_getchar( buff );
	}
}
Esempio n. 4
0
static int
read_int( BUFFER *buff )
{
	int	 ch;
	//  char num[ 30 ];
	int value = 0;

	ch = skip_spaces( buff );
	while( ch >= '0' && ch <= '9' ) {
		//	num[ i++ ] = ch;
		value = (ch - '0') + value * 10;
		ch = buffer_getchar( buff );
	}
	//    num[ i ] = 0;

	/*    return atoi( num );*/
	return value;
}
Esempio n. 5
0
struct data_item* buffer_getdata( struct buffer *b )
{
	int len;
	struct data_item* data;

	len = buffer_getint(b);
	data = xmalloc(sizeof(struct data_item) + len + 2);
	data->key_len = buffer_getint(b);
	data->value_len = buffer_getint(b);
	data->type = buffer_getchar(b);
	data->version = buffer_getlong(b);

	data->key = data->addr + 1;
	data->value = data->addr + 2 + data->key_len;
	memcpy(data->key,buffer_getnstr(b,data->key_len),data->key_len);
	memcpy(data->value,buffer_getnstr(b,data->value_len),data->value_len);
	data->addr[data->key_len + 1] = 0;
	data->addr[data->key_len + data->value_len + 2] = 0;

	data->hash_value = PMurHash32(0,data->key,data->key_len);

	return data;
}
Esempio n. 6
0
void
hcache_readfile(HCACHEFILE *file)
{
	HCACHEDATA	cachedata, *c, *last = 0;
	FILE	*f;
	int		bad_cache = 1, ch;
	const char	*version;
	BUFFER	buff;
	long	buffsize;

/*    if( ! (hcachename = hcache_filename()) )
	return;*/

	if( ! (f = fopen( file->cachefilename, "rb" )) )
		return;

	fseek( f, 0, SEEK_END );
	buffsize = ftell( f );
	fseek( f, 0, SEEK_SET );
	buffer_init( &buff );
	buffer_resize( &buff, buffsize + 1 );
	if ( fread( buffer_ptr( &buff ), buffsize, 1, f ) != 1 )
	{
		fclose( f );
		goto bail;
	}
	buffer_ptr( &buff )[buffsize] = 0;
	fclose( f );

	version = read_string( &buff );
	ch = buffer_getchar( &buff );
	if (!version || strcmp( version, CACHE_FILE_VERSION ) || ch != '\n' ) {
		goto bail;
	}

	for(;;) {
		int i, count, ch;
		LIST *l;

		c = &cachedata;

		c->boundname = read_string( &buff );
		if( !c->boundname ) /* Test for eof */
			break;

		c->time = read_int( &buff );
		c->age = read_int( &buff ) + 1; /* we're getting older... */

#ifdef OPT_BUILTIN_MD5CACHE_EXT
		c->mtime = read_int( &buff );
		read_md5sum( &buff, c->rulemd5sum );
		memcpy( &c->currentrulemd5sum, &c->rulemd5sum, MD5_SUMSIZE );
		read_md5sum( &buff, c->contentmd5sum );
		memcpy( &c->currentcontentmd5sum, &c->contentmd5sum, MD5_SUMSIZE );
#endif

		if( !c->boundname )
			goto bail;

		/* headers */
		count = read_int( &buff );
		for( l = 0, i = 0; i < count; ++i ) {
			const char *s = read_string( &buff );
			if( !s )
				goto bail;
			l = list_new( l, s, 0 );
		}
		c->includes = l;

		/* hdrscan */
		count = read_int( &buff );
		for( l = 0, i = 0; i < count; ++i ) {
			const char *s = read_string( &buff );
			if( !s )
				goto bail;
			l = list_new( l, s, 0 );
		}
		c->hdrscan = l;

		/* Read the newline */
		ch = skip_spaces( &buff );
		if( ch != '!' )
			goto bail;
		ch = skip_spaces( &buff );
		if( ch != '\n' )
			goto bail;

		if( !hashenter( file->hcachehash, (HASHDATA **)&c ) ) {
			printf( "jam: can't insert header cache item, bailing on %s\n",
				file->cachefilename );
			goto bail;
		}

		c->next = 0;
		if( last )
			last->next = c;
		else
			file->hcachelist = c;
		last = c;
	}

	bad_cache = 0;

	if( DEBUG_HEADER )
		printf( "hcache read from file %s\n", file->cachefilename );

bail:
	/* If its bad, no worries, it'll be overwritten in hcache_done() */
	if( bad_cache )
		printf( "jam: warning: the cache was invalid: %s\n", file->cachefilename );
	buffer_free( &buff );
}
Esempio n. 7
0
static void checksums_readfile() {
	CHECKSUMDATA *last;
	FILE *f;
	int bad_cache, ch;
	const char	*version;
	BUFFER buff;
	long buffsize;

	if ( checksumsfileread ) {
		return;
	}

	checksumsfileread = 1;

	checksumhash = hashinit( sizeof( CHECKSUMDATA ), "checksums" );

	if ( !( f = fopen( checksums_filename(), "rb" ) ) )
		return;

	fseek( f, 0, SEEK_END );
	buffsize = ftell( f );
	fseek( f, 0, SEEK_SET );
	buffer_init( &buff );
	buffer_resize( &buff, buffsize + 1 );
	if ( fread( buffer_ptr( &buff ), buffsize, 1, f ) != 1 )
	{
		fclose( f );
		goto bail;
	}
	buffer_ptr( &buff )[buffsize] = 0;
	fclose( f );

	version = read_string( &buff );
	ch = buffer_getchar( &buff );
	if ( !version  ||  strcmp( version, CHECKSUM_FILE_VERSION ) || ch != '\n' ) {
		goto bail;
	}

	last = 0;
	bad_cache = 1;

	for (;;) {
		CHECKSUMDATA	checksumdata, *c = &checksumdata;
		int ch;

		c->boundname = read_string( &buff );
		if ( !c->boundname ) { /* Test for eof */
			break;
		}

		c->age = read_int( &buff ) + 1; /* we're getting older... */

		c->mtime = read_int( &buff );
		read_md5sum( &buff, c->contentmd5sum );
		c->contentmd5sum_changed = 0;
		c->contentmd5sum_calculated = 0;

		/* Read the newline */
		ch = skip_spaces( &buff );
		if ( ch != '!' ) {
			goto bail;
		}
		ch = skip_spaces( &buff );
		if ( ch != '\n' ) {
			goto bail;
		}

		if ( !hashcheck( checksumhash, (HASHDATA **) &c ) ) {
			if ( !hashenter( checksumhash, (HASHDATA **)&c ) ) {
				printf( "jam: can't insert checksum cache item, bailing...\n" );
				goto bail;
			}
		}

		c->next = 0;
		if ( last ) {
			last->next = c;
		} else {
			checksumdatalist = c;
		}
		last = c;
	}

	bad_cache = 0;

	if ( DEBUG_HEADER ) {
		printf( "checksums read from file %s\n", checksums_filename() );
	}

bail:
	/* If its bad, no worries, it'll be overwritten in hcache_done() */
	if ( bad_cache )
		printf( "jam: warning: the checksum cache was invalid: %s\n", checksums_filename() );
	buffer_free( &buff );
}