library/src/databases/bpdb/BP-DBStringFilters.cc
// checks to see if a string is reasonable for a field specifier (should be: tablename.fieldname)
checks to see if a string is reasonable for a field specifier (should be: tablename.fieldname)
checks to see if a string is reasonable for a field specifier ( should be : tablename . fieldname )
BP_BOOL BP_StringIsReasonableForSelectFieldSpecifierDB(char * buffer, size_t len)
{
	if(!buffer || !len)
		return BP_FALSE;
	if(len == 1)
	if(buffer[0] == '*')
		return BP_TRUE;
	if(!BP_StringIsReasonablePrintableString(buffer, len, BP_FALSE, BP_FALSE))
		return BP_FALSE;
	BP_BUFFER_ANALYSIS_ASCII_CONFIGURATION ascii_config;
	BP_ZERO_STACK(ascii_config);
	ascii_config.count_ascii = BP_TRUE;
	P_BP_BUFFER_ANALYSIS buff_analysis = BP_CreateBufferAnalysis
	(
			(unsigned char *) buffer,
			(size_t) len,
			&ascii_config
	);
	if(!buff_analysis)
		return BP_FALSE;
	if(buff_analysis->ascii->char_counts['.'] != 1)
	{
		BP_DestroyBufferAnalysis(buff_analysis);
		return BP_FALSE;
	}
	if(buffer[0] == '.')
	{
		BP_DestroyBufferAnalysis(buff_analysis);
		return BP_FALSE;
	}
	if(buffer[len-1] == '.')
	{
		BP_DestroyBufferAnalysis(buff_analysis);
		return BP_FALSE;
	}
	if
	(
			buff_analysis->ascii->char_counts[' ']  ||
			buff_analysis->ascii->char_counts['\\'] ||
			buff_analysis->ascii->char_counts['`' ] ||
			buff_analysis->ascii->char_counts['|' ] ||
			buff_analysis->ascii->char_counts['}' ] ||
			buff_analysis->ascii->char_counts['{' ] ||
			buff_analysis->ascii->char_counts[']' ] ||
			buff_analysis->ascii->char_counts['[' ] ||
			buff_analysis->ascii->char_counts[')' ] ||
			buff_analysis->ascii->char_counts['(' ] ||
			buff_analysis->ascii->char_counts['>' ] ||
			buff_analysis->ascii->char_counts['<' ] ||
			buff_analysis->ascii->char_counts[';' ] ||
			buff_analysis->ascii->char_counts[':' ] ||
			buff_analysis->ascii->char_counts[',' ] ||
			buff_analysis->ascii->char_counts['*' ] || 
			buff_analysis->ascii->char_counts['^' ] ||
			buff_analysis->ascii->char_counts['%' ] ||
			buff_analysis->ascii->char_counts['#' ] ||
			buff_analysis->ascii->char_counts['@' ] ||
			buff_analysis->ascii->char_counts['!' ] ||
			buff_analysis->ascii->char_counts['=' ] ||
			buff_analysis->ascii->char_counts['+' ] ||
			buff_analysis->ascii->char_counts['?' ] ||
			buff_analysis->ascii->char_counts['"' ] ||
			buff_analysis->ascii->char_counts['\''] ||
			buff_analysis->ascii->char_counts['$' ] ||
			buff_analysis->ascii->char_counts['&' ]
	)
	{
		BP_DestroyBufferAnalysis(buff_analysis);
		return BP_FALSE;
	}
	BP_DestroyBufferAnalysis(buff_analysis);
	return BP_TRUE;
}
BP_BOOL BP_StringIsReasonableForSelectFieldSpecifierDB ( char * buffer , size_t len ) { if ( ! buffer || ! len ) return BP_FALSE ; if ( len == 1 ) if ( buffer [ 0 ] == ' ' ) return BP_TRUE ; if ( ! BP_StringIsReasonablePrintableString ( buffer , len , BP_FALSE , BP_FALSE ) ) return BP_FALSE ; BP_BUFFER_ANALYSIS_ASCII_CONFIGURATION ascii_config ; BP_ZERO_STACK ( ascii_config ) ; ascii_config . count_ascii = BP_TRUE ; P_BP_BUFFER_ANALYSIS buff_analysis = BP_CreateBufferAnalysis ( ( unsigned char * ) buffer , ( size_t ) len , & ascii_config ) ; if ( ! buff_analysis ) return BP_FALSE ; if ( buff_analysis -> ascii -> char_counts [ ' ' ] != 1 ) { BP_DestroyBufferAnalysis ( buff_analysis ) ; return BP_FALSE ; } if ( buffer [ 0 ] == ' ' ) { BP_DestroyBufferAnalysis ( buff_analysis ) ; return BP_FALSE ; } if ( buffer [ len - 1 ] == ' ' ) { BP_DestroyBufferAnalysis ( buff_analysis ) ; return BP_FALSE ; } if ( buff_analysis -> ascii -> char_counts [ ' ' ] || buff_analysis -> ascii -> char_counts [ ' \\ ' ] || buff_analysis -> ascii -> char_counts [ ' ' ] || buff_analysis -> ascii -> char_counts [ ' ' ] || buff_analysis -> ascii -> char_counts [ ' ' ] || buff_analysis -> ascii -> char_counts [ ' ' ] || buff_analysis -> ascii -> char_counts [ ' ' ] || buff_analysis -> ascii -> char_counts [ ' ' ] || buff_analysis -> ascii -> char_counts [ ' ' ] || buff_analysis -> ascii -> char_counts [ ' ' ] || buff_analysis -> ascii -> char_counts [ ' ' ] || buff_analysis -> ascii -> char_counts [ ' ' ] || buff_analysis -> ascii -> char_counts [ ' ' ] || buff_analysis -> ascii -> char_counts [ ' ' ] || buff_analysis -> ascii -> char_counts [ ' ' ] || buff_analysis -> ascii -> char_counts [ ' ' ] || buff_analysis -> ascii -> char_counts [ ' ' ] || buff_analysis -> ascii -> char_counts [ ' ' ] || buff_analysis -> ascii -> char_counts [ ' ' ] || buff_analysis -> ascii -> char_counts [ ' ' ] || buff_analysis -> ascii -> char_counts [ ' ' ] || buff_analysis -> ascii -> char_counts [ ' ' ] || buff_analysis -> ascii -> char_counts [ ' ' ] || buff_analysis -> ascii -> char_counts [ ' ' ] || buff_analysis -> ascii -> char_counts [ ' ' ] || buff_analysis -> ascii -> char_counts [ ' \' ' ] || buff_analysis -> ascii -> char_counts [ ' ' ] || buff_analysis -> ascii -> char_counts [ ' ' ] ) { BP_DestroyBufferAnalysis ( buff_analysis ) ; return BP_FALSE ; } BP_DestroyBufferAnalysis ( buff_analysis ) ; return BP_TRUE ; }
checks to see if a string is reasonable for a field specifier (should be: tablename.fieldname)
checks to see if a string is reasonable for a field specifier ( should be : tablename . fieldname )
// ensure we have a directory and a length // if it's a star selector we can return immediately without // running verifications. // attempt to verify that the string is reasonable first // create ascii configuration // zero out the structure (automagic macro) // set some flags in the structure to count ascii (we already counted invalid with our initial check) // attempt to generate analysis // ensure we h ave a buffer analysis // ensure we only have one '.' count // destroy the buffer analysis before exiting // return indicating mismatch // string cannot start with a peiriod // destroy the buffer analysis before exiting // return indicating mismatch // string cannot end with a peiriod // destroy the buffer analysis before exiting // return indicating mismatch // ensure buffer doesn't have any special chars which could // play havoc with later parsing. /* note, star selectors ARE forbidden at the time of this check */ // destroy the buffer analysis // return indicating the path is bad // destroy the buffer analysis // return indicating that the path is suitable