library/src/utility/BP-StringUtilities.cc
BP_BOOL BP_StringIsReasonableForJSONPropertyNameString
(
		char * json_propname_string_to_analyze,
		size_t json_propname_string_len
)
{

	// attempt to verify that the string is reasonable first
	if(!BP_StringIsReasonablePrintableString(json_propname_string_to_analyze, json_propname_string_len, BP_FALSE, BP_FALSE))
		return BP_FALSE;

	// ensure the first position is alphanumeric
	if(!isalnum(json_propname_string_to_analyze[0]))
		return BP_FALSE;

	// ensure the last position is alphanumeric
	if(!isalnum(json_propname_string_to_analyze[bpstrlen(json_propname_string_to_analyze)-1]))
		return BP_FALSE;

	// create ascii configuration
	BP_BUFFER_ANALYSIS_ASCII_CONFIGURATION ascii_config;
	BP_ZERO_STACK(ascii_config);

	// set some flags in the structure to count ascii (we already counted invalid with our initial check)
	ascii_config.count_ascii                      = BP_TRUE;

	// attempt to generate analysis
	P_BP_BUFFER_ANALYSIS buff_analysis = BP_CreateBufferAnalysis
	(
			(unsigned char *) json_propname_string_to_analyze,
			(size_t)          json_propname_string_len,
			&ascii_config
	);

	// ensure we h ave a buffer analysis
	if(!buff_analysis)
		return BP_FALSE;


	// ensure buffer doesn't have any special chars which could
	// play havoc with later parsing.
	if
	(
			buff_analysis->ascii->char_counts['\\'] ||
			buff_analysis->ascii->char_counts['`' ] ||
			buff_analysis->ascii->char_counts['"' ] ||
			buff_analysis->ascii->char_counts['\'']

	)
	{

		// destroy the buffer analysis
		BP_DestroyBufferAnalysis(buff_analysis);

		// return indicating the path is bad
		return BP_FALSE;

	}

	// destroy the buffer analysis
	BP_DestroyBufferAnalysis(buff_analysis);

	// return indicating success
	return BP_TRUE;

}
// checks to ensure that a string is reasonable for a json property name
checks to ensure that a string is reasonable for a json property name
checks to ensure that a string is reasonable for a json property name
BP_BOOL BP_StringIsReasonableForJSONPropertyNameString
(
		char * json_propname_string_to_analyze,
		size_t json_propname_string_len
)
{
	if(!BP_StringIsReasonablePrintableString(json_propname_string_to_analyze, json_propname_string_len, BP_FALSE, BP_FALSE))
		return BP_FALSE;
	if(!isalnum(json_propname_string_to_analyze[0]))
		return BP_FALSE;
	if(!isalnum(json_propname_string_to_analyze[bpstrlen(json_propname_string_to_analyze)-1]))
		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 *) json_propname_string_to_analyze,
			(size_t)          json_propname_string_len,
			&ascii_config
	);
	if(!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['\'']
	)
	{
		BP_DestroyBufferAnalysis(buff_analysis);
		return BP_FALSE;
	}
	BP_DestroyBufferAnalysis(buff_analysis);
	return BP_TRUE;
}
BP_BOOL BP_StringIsReasonableForJSONPropertyNameString ( char * json_propname_string_to_analyze , size_t json_propname_string_len ) { if ( ! BP_StringIsReasonablePrintableString ( json_propname_string_to_analyze , json_propname_string_len , BP_FALSE , BP_FALSE ) ) return BP_FALSE ; if ( ! isalnum ( json_propname_string_to_analyze [ 0 ] ) ) return BP_FALSE ; if ( ! isalnum ( json_propname_string_to_analyze [ bpstrlen ( json_propname_string_to_analyze ) - 1 ] ) ) 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 * ) json_propname_string_to_analyze , ( size_t ) json_propname_string_len , & ascii_config ) ; if ( ! 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 [ ' \' ' ] ) { BP_DestroyBufferAnalysis ( buff_analysis ) ; return BP_FALSE ; } BP_DestroyBufferAnalysis ( buff_analysis ) ; return BP_TRUE ; }
checks to ensure that a string is reasonable for a json property name
checks to ensure that a string is reasonable for a json property name
// attempt to verify that the string is reasonable first // ensure the first position is alphanumeric // ensure the last position is alphanumeric // create ascii configuration // 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 buffer doesn't have any special chars which could // play havoc with later parsing. // destroy the buffer analysis // return indicating the path is bad // destroy the buffer analysis // return indicating success