library/src/webchat/BP-WebChat.cc
// Convert a command to an event type so we can switch() on it easily.
Convert a command to an event type so we can switch() on it easily.
Convert a command to an event type so we can switch () on it easily .
BP_WEBCHAT_EVENT_TYPE BP_WebChatRequestCommandToEventType
(
	P_BP_WEBCHAT webchat,
	char        *cmd,
	size_t       cmd_len
)
{
	if(!webchat)
		return BP_WEBCHAT_EVENT_UNSET;
	if(!webchat->command_reg)
		return BP_WEBCHAT_EVENT_UNSET;
	if(!cmd)
		return BP_WEBCHAT_EVENT_UNSET;
	if(!cmd_len)
		return BP_WEBCHAT_EVENT_UNSET;
	if(!BP_StringIsReasonablePrintableString(cmd, cmd_len, BP_FALSE, BP_FALSE))
		return BP_WEBCHAT_EVENT_UNSET;
	char *entry_lookup_path[10];
	BP_ZERO_STACK(entry_lookup_path);
	entry_lookup_path[0] = "commands";
	entry_lookup_path[1] = cmd;
	P_BP_HASH_TABLE_KEYED_ENTRY command_entry = BP_HashRegLookupTableEntryByPath(webchat->command_reg, (char **) &entry_lookup_path);
	if(!command_entry)
	{
		return BP_WEBCHAT_EVENT_UNSET;
	}
	if(!command_entry->data)
	{
		return BP_WEBCHAT_EVENT_UNSET;
	}
	BP_WEBCHAT_EVENT_TYPE * event_type_ptr = NULL;
	BP_WEBCHAT_EVENT_TYPE   event_type     = BP_WEBCHAT_EVENT_UNSET;
	event_type_ptr = (BP_WEBCHAT_EVENT_TYPE *) command_entry->data;
	event_type = *event_type_ptr;
	return event_type;
}
BP_WEBCHAT_EVENT_TYPE BP_WebChatRequestCommandToEventType ( P_BP_WEBCHAT webchat , char * cmd , size_t cmd_len ) { if ( ! webchat ) return BP_WEBCHAT_EVENT_UNSET ; if ( ! webchat -> command_reg ) return BP_WEBCHAT_EVENT_UNSET ; if ( ! cmd ) return BP_WEBCHAT_EVENT_UNSET ; if ( ! cmd_len ) return BP_WEBCHAT_EVENT_UNSET ; if ( ! BP_StringIsReasonablePrintableString ( cmd , cmd_len , BP_FALSE , BP_FALSE ) ) return BP_WEBCHAT_EVENT_UNSET ; char * entry_lookup_path [ 10 ] ; BP_ZERO_STACK ( entry_lookup_path ) ; entry_lookup_path [ 0 ] = " " ; entry_lookup_path [ 1 ] = cmd ; P_BP_HASH_TABLE_KEYED_ENTRY command_entry = BP_HashRegLookupTableEntryByPath ( webchat -> command_reg , ( char * * ) & entry_lookup_path ) ; if ( ! command_entry ) { return BP_WEBCHAT_EVENT_UNSET ; } if ( ! command_entry -> data ) { return BP_WEBCHAT_EVENT_UNSET ; } BP_WEBCHAT_EVENT_TYPE * event_type_ptr = NULL ; BP_WEBCHAT_EVENT_TYPE event_type = BP_WEBCHAT_EVENT_UNSET ; event_type_ptr = ( BP_WEBCHAT_EVENT_TYPE * ) command_entry -> data ; event_type = * event_type_ptr ; return event_type ; }
Convert a command to an event type so we can switch() on it easily.
Convert a command to an event type so we can switch () on it easily .
// run basic null checks // create entry lookup path // set the entry lookup path // attempt to lookup entry by path // ensure we have data // declare value reference // set the event type from data // set the event type // return the looked up event type