library/src/datastructures/BP-HashTable.cc
// Tests to see if a hash registry index passes filter tests
Tests to see if a hash registry index passes filter tests
Tests to see if a hash registry index passes filter tests
BP_ERROR_T BP_HashRegPathArrayIndexFilterTest(char *index_str, size_t index_str_len)
{
	if(!index_str)
		return ERR_FAILURE;
	if(!index_str_len)
		return ERR_FAILURE;
	BP_BUFFER_ANALYSIS_ASCII_CONFIGURATION ascii_config;
	BP_ZERO_STACK(ascii_config);
	ascii_config.count_ascii                      = BP_TRUE;
	ascii_config.count_extended                   = BP_TRUE;
	ascii_config.count_individual_characters      = BP_TRUE;
	P_BP_BUFFER_ANALYSIS buff_analysis = BP_CreateBufferAnalysis
	(
		(unsigned char *) index_str,
		(size_t)          index_str_len,
		&ascii_config
	);
	unsigned char filter_char_stop_idx = 0xff;
	unsigned char filter_iter = 0x00;
	for
	(
		;
		filter_iter < filter_char_stop_idx;
		filter_iter++
	)
	{
		if(filter_iter >= '0' && filter_iter <= '9')
			continue;
		if(filter_iter >= 'A' && filter_iter <= 'Z')
			continue;
		if(filter_iter >= 'a' && filter_iter <= 'z')
			continue;
		switch((char) filter_iter)
		{
			case '!':
			case '#':
			case '$':
			case '&':
			case '(':
			case ')':
			case '{':
			case '}':
			case ' ':
			case '_':
			case '-':
			case '.':
			case '~':
			case '=':
			case '`':
			case '\'':
			case '"':
			case '\\':
				continue;
				break;
			default:
				break;
		}
		if(buff_analysis->ascii->char_counts[filter_iter])
		{
			BP_DestroyBufferAnalysis(buff_analysis);
			return ERR_FAILURE;
		}
	}
	BP_DestroyBufferAnalysis(buff_analysis);
	return ERR_SUCCESS;
}
BP_ERROR_T BP_HashRegPathArrayIndexFilterTest ( char * index_str , size_t index_str_len ) { if ( ! index_str ) return ERR_FAILURE ; if ( ! index_str_len ) return ERR_FAILURE ; BP_BUFFER_ANALYSIS_ASCII_CONFIGURATION ascii_config ; BP_ZERO_STACK ( ascii_config ) ; ascii_config . count_ascii = BP_TRUE ; ascii_config . count_extended = BP_TRUE ; ascii_config . count_individual_characters = BP_TRUE ; P_BP_BUFFER_ANALYSIS buff_analysis = BP_CreateBufferAnalysis ( ( unsigned char * ) index_str , ( size_t ) index_str_len , & ascii_config ) ; unsigned char filter_char_stop_idx = 0xff ; unsigned char filter_iter = 0x00 ; for ( ; filter_iter < filter_char_stop_idx ; filter_iter ++ ) { if ( filter_iter >= ' ' && filter_iter <= ' ' ) continue ; if ( filter_iter >= ' ' && filter_iter <= ' ' ) continue ; if ( filter_iter >= ' ' && filter_iter <= ' ' ) continue ; switch ( ( char ) filter_iter ) { case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' \' ' : case ' ' : case ' \\ ' : continue ; break ; default : break ; } if ( buff_analysis -> ascii -> char_counts [ filter_iter ] ) { BP_DestroyBufferAnalysis ( buff_analysis ) ; return ERR_FAILURE ; } } BP_DestroyBufferAnalysis ( buff_analysis ) ; return ERR_SUCCESS ; }
Tests to see if a hash registry index passes filter tests
Tests to see if a hash registry index passes filter tests
// basic zero/null checks // create ascii configuration // zero out the structure (automagic macro) // set some flags in the structure (default is BP_FALSE aka 0) // attempt to generate analysis // this is where the filter index will stop searching // this is where the filter iter starts // loop through all filter combinations and identify if we have ANY bad characters // dbg display // printf("\n filter_iter: %u | filter_char_stop_idx: %u", filter_iter, filter_char_stop_idx); // allow filter bypass for 0 - 9 // skip past A-Z // skip past a-z // perform special character allow exceptions // skip all allowed chars // if we have a disallowed filter, destroy analysis and exit // printf("\n Filter Failed on: %s", index_str); // destroy the buffer analysis // return indicating that the key has passed the filter checks