library/src/javascript/JSON/BP-JSON.cc
// add a parse notice to the parse output hash table registry
add a parse notice to the parse output hash table registry
add a parse notice to the parse output hash table registry
BP_ERROR_T BP_JSONParseAddNoticeMsg(P_BP_JSON json, P_BP_JSON_PARSE_TOKEN_ELEMENT token_element, char *message, int buff_position, char bad_char)
{
	if(!json)
		return ERR_FAILURE;
	if(!message)
		return ERR_FAILURE;
	char * table_str = "/notices";
	char * msg_str = message;
	if(!BP_StringIsReasonablePrintableString(msg_str, bpstrlen(msg_str), BP_FALSE, BP_FALSE))
		return ERR_FAILURE;
	if(!json->parse_messages_reg)
		json->parse_messages_reg = BP_CreateHashTableRegistry();
	P_BP_HTKE notice_table = BP_HashRegLookupTableByPathQuery(json->parse_messages_reg, table_str);
	if(!notice_table)
	{
		BP_HashRegAddTableByPathQuery(json->parse_messages_reg, table_str);
		notice_table = BP_HashRegLookupTableByPathQuery(json->parse_messages_reg, table_str);
		if(!notice_table)
			return ERR_FAILURE;
	}
	char * random_sha1_key = BP_GenRandomSHA1();
	char *add_new_table_path[] =
	{
		"notices",
		random_sha1_key,
		NULL
	};
	char * inner_table_path = BP_HashRegPathArrayToStringLookup(add_new_table_path);
	if(!inner_table_path)
		return ERR_FAILURE;
	if(!BP_HashRegAddTableByPathQuery(json->parse_messages_reg, inner_table_path))
		return ERR_FAILURE;
	if(!BP_HashRegAddDataToTableByPathQuery(json->parse_messages_reg, inner_table_path, "msg", BP_HASH_TABLE_KEYED_ENTRY_TYPE_UTF8_STRING, msg_str, bpstrlen(msg_str)))
	{
		bpfree(random_sha1_key);
		return ERR_FAILURE;
	}
	char position_buff[64];
	BP_ZERO_STACK(position_buff);
	sprintf((char *)&position_buff, "%i", buff_position);
	if(!BP_HashRegAddDataToTableByPathQuery(json->parse_messages_reg, inner_table_path, "buff_pos", BP_HASH_TABLE_KEYED_ENTRY_TYPE_UTF8_STRING, &position_buff, bpstrlen(position_buff)))
	{
		bpfree(random_sha1_key);
		return ERR_FAILURE;
	}
	if(!BP_HashRegAddDataToTableByPathQuery(json->parse_messages_reg, inner_table_path, "bad_char", BP_HASH_TABLE_KEYED_ENTRY_TYPE_UTF8_STRING, &bad_char, 1))
	{
		bpfree(random_sha1_key);
		return ERR_FAILURE;
	}
	bpfree(random_sha1_key);
	return ERR_SUCCESS;
}
BP_ERROR_T BP_JSONParseAddNoticeMsg ( P_BP_JSON json , P_BP_JSON_PARSE_TOKEN_ELEMENT token_element , char * message , int buff_position , char bad_char ) { if ( ! json ) return ERR_FAILURE ; if ( ! message ) return ERR_FAILURE ; char * table_str = " " ; char * msg_str = message ; if ( ! BP_StringIsReasonablePrintableString ( msg_str , bpstrlen ( msg_str ) , BP_FALSE , BP_FALSE ) ) return ERR_FAILURE ; if ( ! json -> parse_messages_reg ) json -> parse_messages_reg = BP_CreateHashTableRegistry ( ) ; P_BP_HTKE notice_table = BP_HashRegLookupTableByPathQuery ( json -> parse_messages_reg , table_str ) ; if ( ! notice_table ) { BP_HashRegAddTableByPathQuery ( json -> parse_messages_reg , table_str ) ; notice_table = BP_HashRegLookupTableByPathQuery ( json -> parse_messages_reg , table_str ) ; if ( ! notice_table ) return ERR_FAILURE ; } char * random_sha1_key = BP_GenRandomSHA1 ( ) ; char * add_new_table_path [ ] = { " " , random_sha1_key , NULL } ; char * inner_table_path = BP_HashRegPathArrayToStringLookup ( add_new_table_path ) ; if ( ! inner_table_path ) return ERR_FAILURE ; if ( ! BP_HashRegAddTableByPathQuery ( json -> parse_messages_reg , inner_table_path ) ) return ERR_FAILURE ; if ( ! BP_HashRegAddDataToTableByPathQuery ( json -> parse_messages_reg , inner_table_path , " " , BP_HASH_TABLE_KEYED_ENTRY_TYPE_UTF8_STRING , msg_str , bpstrlen ( msg_str ) ) ) { bpfree ( random_sha1_key ) ; return ERR_FAILURE ; } char position_buff [ 64 ] ; BP_ZERO_STACK ( position_buff ) ; sprintf ( ( char * ) & position_buff , " " , buff_position ) ; if ( ! BP_HashRegAddDataToTableByPathQuery ( json -> parse_messages_reg , inner_table_path , " " , BP_HASH_TABLE_KEYED_ENTRY_TYPE_UTF8_STRING , & position_buff , bpstrlen ( position_buff ) ) ) { bpfree ( random_sha1_key ) ; return ERR_FAILURE ; } if ( ! BP_HashRegAddDataToTableByPathQuery ( json -> parse_messages_reg , inner_table_path , " " , BP_HASH_TABLE_KEYED_ENTRY_TYPE_UTF8_STRING , & bad_char , 1 ) ) { bpfree ( random_sha1_key ) ; return ERR_FAILURE ; } bpfree ( random_sha1_key ) ; return ERR_SUCCESS ; }
add a parse notice to the parse output hash table registry
add a parse notice to the parse output hash table registry
// run basic null checks // table string for lookup // msg string for add // ensure string is reasonable/printable // create registry jit if necessary // attempt to lookup notices table by path // attempt to add the notices table // attempt lookup again // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Add Table For New Notice %%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // create random sha1 key // set the addition path // inner table path with table index set // create new table // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Add Data To Table %%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // -- add /notices/sha1/msg // add data to table path by query // -- add /notices/sha1/buff_pos // allocate space on the stack to hold our position // copy in the buffer position // add data to table path by query // -- add /notices/sha1/bad_char // add data to table path by query // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Destroy Dangling Data and Exit %%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // destroy the sha1 key // --- attach // return indicating success