library/src/webchat/BP-WebChat.cc
// initialize command registry if it hasn't already been initialized
initialize command registry if it hasn't already been initialized
initialize command registry if it hasn ' t already been initialized
BP_ERROR_T BP_WebChatInitCommandRegistry(P_BP_WEBCHAT webchat)
{
	if(!webchat)
		return ERR_FAILURE;
	if(webchat->command_reg)
		return ERR_FAILURE;
	webchat->command_reg = BP_CreateHashTableRegistry();
	if(!webchat->command_reg)
	{
		return ERR_FAILURE;
	}
	char *table_path[10];
	BP_ZERO_STACK(table_path);
	table_path[0] = "commands";
	BP_HashRegAddTableByPath(webchat->command_reg, (char **) &table_path);
	BP_HashRegAddDataToTableByPath
	(
		webchat->command_reg,
		(char **) &table_path,
		"user_add_to_channel",
		BP_HASH_TABLE_KEYED_ENTRY_TYPE_BINARY_BLOB,
		NULL,
		sizeof(BP_WEBCHAT_EVENT_TYPE)
	);
	BP_HashRegAddDataToTableByPath
	(
		webchat->command_reg,
		(char **) &table_path,
		"user_remove_from_channel",
		BP_HASH_TABLE_KEYED_ENTRY_TYPE_BINARY_BLOB,
		NULL,
		sizeof(BP_WEBCHAT_EVENT_TYPE)
	);
	BP_HashRegAddDataToTableByPath
	(
		webchat->command_reg,
		(char **) &table_path,
		"user_get_metadata",
		BP_HASH_TABLE_KEYED_ENTRY_TYPE_BINARY_BLOB,
		NULL,
		sizeof(BP_WEBCHAT_EVENT_TYPE)
	);
	BP_HashRegAddDataToTableByPath
	(
		webchat->command_reg,
		(char **) &table_path,
		"channel_add",
		BP_HASH_TABLE_KEYED_ENTRY_TYPE_BINARY_BLOB,
		NULL,
		sizeof(BP_WEBCHAT_EVENT_TYPE)
	);
	BP_HashRegAddDataToTableByPath
	(
		webchat->command_reg,
		(char **) &table_path,
		"channel_remove",
		BP_HASH_TABLE_KEYED_ENTRY_TYPE_BINARY_BLOB,
		NULL,
		sizeof(BP_WEBCHAT_EVENT_TYPE)
	);
	BP_HashRegAddDataToTableByPath
	(
		webchat->command_reg,
		(char **) &table_path,
		"channel_add_message_from_user",
		BP_HASH_TABLE_KEYED_ENTRY_TYPE_BINARY_BLOB,
		NULL,
		sizeof(BP_WEBCHAT_EVENT_TYPE)
	);
	BP_HashRegAddDataToTableByPath
	(
		webchat->command_reg,
		(char **) &table_path,
		"system_get_hreg",
		BP_HASH_TABLE_KEYED_ENTRY_TYPE_BINARY_BLOB,
		NULL,
		sizeof(BP_WEBCHAT_EVENT_TYPE)
	);
	P_BP_HASH_TABLE_KEYED_ENTRY entry_lookup = NULL;
	BP_WEBCHAT_EVENT_TYPE * event_type = NULL;
	char *entry_lookup_path[10];
	BP_ZERO_STACK(entry_lookup_path);
	entry_lookup_path[0] = "commands";
	entry_lookup_path[1] = "user_add_to_channel";
	entry_lookup = BP_HashRegLookupTableEntryByPath
	(
		webchat->command_reg,
		(char **) &entry_lookup_path
	);
	if(!entry_lookup)
		return ERR_FAILURE;
	event_type = (BP_WEBCHAT_EVENT_TYPE *) entry_lookup->data;
	*event_type = BP_WEBCHAT_EVENT_USER_ADD_TO_CHANNEL;
	entry_lookup_path[0] = "commands";
	entry_lookup_path[1] = "user_remove_from_channel";
	entry_lookup = BP_HashRegLookupTableEntryByPath
	(
		webchat->command_reg,
		(char **) &entry_lookup_path
	);
	if(!entry_lookup)
		return ERR_FAILURE;
	event_type = (BP_WEBCHAT_EVENT_TYPE *) entry_lookup->data;
	*event_type = BP_WEBCHAT_EVENT_USER_REMOVE_FROM_CHANNEL;
	entry_lookup_path[0] = "commands";
	entry_lookup_path[1] = "user_get_metadata";
	entry_lookup = BP_HashRegLookupTableEntryByPath
	(
		webchat->command_reg,
		(char **) &entry_lookup_path
	);
	if(!entry_lookup)
		return ERR_FAILURE;
	event_type = (BP_WEBCHAT_EVENT_TYPE *) entry_lookup->data;
	*event_type = BP_WEBCHAT_EVENT_USER_GET_METADATA;
	entry_lookup_path[0] = "commands";
	entry_lookup_path[1] = "channel_add";
	entry_lookup = BP_HashRegLookupTableEntryByPath
	(
		webchat->command_reg,
		(char **) &entry_lookup_path
	);
	if(!entry_lookup)
		return ERR_FAILURE;
	event_type = (BP_WEBCHAT_EVENT_TYPE *) entry_lookup->data;
	*event_type = BP_WEBCHAT_EVENT_CHANNEL_ADD;
	entry_lookup_path[0] = "commands";
	entry_lookup_path[1] = "channel_remove";
	entry_lookup = BP_HashRegLookupTableEntryByPath
	(
		webchat->command_reg,
		(char **) &entry_lookup_path
	);
	if(!entry_lookup)
		return ERR_FAILURE;
	event_type = (BP_WEBCHAT_EVENT_TYPE *) entry_lookup->data;
	*event_type = BP_WEBCHAT_EVENT_CHANNEL_REMOVE;
	entry_lookup_path[0] = "commands";
	entry_lookup_path[1] = "channel_add_message_from_user";
	entry_lookup = BP_HashRegLookupTableEntryByPath
	(
		webchat->command_reg,
		(char **) &entry_lookup_path
	);
	if(!entry_lookup)
		return ERR_FAILURE;
	event_type = (BP_WEBCHAT_EVENT_TYPE *) entry_lookup->data;
	*event_type = BP_WEBCHAT_EVENT_CHANNEL_ADD_MESSAGE_FROM_USER;
	entry_lookup_path[0] = "commands";
	entry_lookup_path[1] = "system_get_hreg";
	entry_lookup = BP_HashRegLookupTableEntryByPath
	(
		webchat->command_reg,
		(char **) &entry_lookup_path
	);
	if(!entry_lookup)
		return ERR_FAILURE;
	event_type = (BP_WEBCHAT_EVENT_TYPE *) entry_lookup->data;
	*event_type = BP_WEBCHAT_EVENT_SYSTEM_GET_HREG;
	return ERR_SUCCESS;
}
BP_ERROR_T BP_WebChatInitCommandRegistry ( P_BP_WEBCHAT webchat ) { if ( ! webchat ) return ERR_FAILURE ; if ( webchat -> command_reg ) return ERR_FAILURE ; webchat -> command_reg = BP_CreateHashTableRegistry ( ) ; if ( ! webchat -> command_reg ) { return ERR_FAILURE ; } char * table_path [ 10 ] ; BP_ZERO_STACK ( table_path ) ; table_path [ 0 ] = " " ; BP_HashRegAddTableByPath ( webchat -> command_reg , ( char * * ) & table_path ) ; BP_HashRegAddDataToTableByPath ( webchat -> command_reg , ( char * * ) & table_path , " " , BP_HASH_TABLE_KEYED_ENTRY_TYPE_BINARY_BLOB , NULL , sizeof ( BP_WEBCHAT_EVENT_TYPE ) ) ; BP_HashRegAddDataToTableByPath ( webchat -> command_reg , ( char * * ) & table_path , " " , BP_HASH_TABLE_KEYED_ENTRY_TYPE_BINARY_BLOB , NULL , sizeof ( BP_WEBCHAT_EVENT_TYPE ) ) ; BP_HashRegAddDataToTableByPath ( webchat -> command_reg , ( char * * ) & table_path , " " , BP_HASH_TABLE_KEYED_ENTRY_TYPE_BINARY_BLOB , NULL , sizeof ( BP_WEBCHAT_EVENT_TYPE ) ) ; BP_HashRegAddDataToTableByPath ( webchat -> command_reg , ( char * * ) & table_path , " " , BP_HASH_TABLE_KEYED_ENTRY_TYPE_BINARY_BLOB , NULL , sizeof ( BP_WEBCHAT_EVENT_TYPE ) ) ; BP_HashRegAddDataToTableByPath ( webchat -> command_reg , ( char * * ) & table_path , " " , BP_HASH_TABLE_KEYED_ENTRY_TYPE_BINARY_BLOB , NULL , sizeof ( BP_WEBCHAT_EVENT_TYPE ) ) ; BP_HashRegAddDataToTableByPath ( webchat -> command_reg , ( char * * ) & table_path , " " , BP_HASH_TABLE_KEYED_ENTRY_TYPE_BINARY_BLOB , NULL , sizeof ( BP_WEBCHAT_EVENT_TYPE ) ) ; BP_HashRegAddDataToTableByPath ( webchat -> command_reg , ( char * * ) & table_path , " " , BP_HASH_TABLE_KEYED_ENTRY_TYPE_BINARY_BLOB , NULL , sizeof ( BP_WEBCHAT_EVENT_TYPE ) ) ; P_BP_HASH_TABLE_KEYED_ENTRY entry_lookup = NULL ; BP_WEBCHAT_EVENT_TYPE * event_type = NULL ; char * entry_lookup_path [ 10 ] ; BP_ZERO_STACK ( entry_lookup_path ) ; entry_lookup_path [ 0 ] = " " ; entry_lookup_path [ 1 ] = " " ; entry_lookup = BP_HashRegLookupTableEntryByPath ( webchat -> command_reg , ( char * * ) & entry_lookup_path ) ; if ( ! entry_lookup ) return ERR_FAILURE ; event_type = ( BP_WEBCHAT_EVENT_TYPE * ) entry_lookup -> data ; * event_type = BP_WEBCHAT_EVENT_USER_ADD_TO_CHANNEL ; entry_lookup_path [ 0 ] = " " ; entry_lookup_path [ 1 ] = " " ; entry_lookup = BP_HashRegLookupTableEntryByPath ( webchat -> command_reg , ( char * * ) & entry_lookup_path ) ; if ( ! entry_lookup ) return ERR_FAILURE ; event_type = ( BP_WEBCHAT_EVENT_TYPE * ) entry_lookup -> data ; * event_type = BP_WEBCHAT_EVENT_USER_REMOVE_FROM_CHANNEL ; entry_lookup_path [ 0 ] = " " ; entry_lookup_path [ 1 ] = " " ; entry_lookup = BP_HashRegLookupTableEntryByPath ( webchat -> command_reg , ( char * * ) & entry_lookup_path ) ; if ( ! entry_lookup ) return ERR_FAILURE ; event_type = ( BP_WEBCHAT_EVENT_TYPE * ) entry_lookup -> data ; * event_type = BP_WEBCHAT_EVENT_USER_GET_METADATA ; entry_lookup_path [ 0 ] = " " ; entry_lookup_path [ 1 ] = " " ; entry_lookup = BP_HashRegLookupTableEntryByPath ( webchat -> command_reg , ( char * * ) & entry_lookup_path ) ; if ( ! entry_lookup ) return ERR_FAILURE ; event_type = ( BP_WEBCHAT_EVENT_TYPE * ) entry_lookup -> data ; * event_type = BP_WEBCHAT_EVENT_CHANNEL_ADD ; entry_lookup_path [ 0 ] = " " ; entry_lookup_path [ 1 ] = " " ; entry_lookup = BP_HashRegLookupTableEntryByPath ( webchat -> command_reg , ( char * * ) & entry_lookup_path ) ; if ( ! entry_lookup ) return ERR_FAILURE ; event_type = ( BP_WEBCHAT_EVENT_TYPE * ) entry_lookup -> data ; * event_type = BP_WEBCHAT_EVENT_CHANNEL_REMOVE ; entry_lookup_path [ 0 ] = " " ; entry_lookup_path [ 1 ] = " " ; entry_lookup = BP_HashRegLookupTableEntryByPath ( webchat -> command_reg , ( char * * ) & entry_lookup_path ) ; if ( ! entry_lookup ) return ERR_FAILURE ; event_type = ( BP_WEBCHAT_EVENT_TYPE * ) entry_lookup -> data ; * event_type = BP_WEBCHAT_EVENT_CHANNEL_ADD_MESSAGE_FROM_USER ; entry_lookup_path [ 0 ] = " " ; entry_lookup_path [ 1 ] = " " ; entry_lookup = BP_HashRegLookupTableEntryByPath ( webchat -> command_reg , ( char * * ) & entry_lookup_path ) ; if ( ! entry_lookup ) return ERR_FAILURE ; event_type = ( BP_WEBCHAT_EVENT_TYPE * ) entry_lookup -> data ; * event_type = BP_WEBCHAT_EVENT_SYSTEM_GET_HREG ; return ERR_SUCCESS ; }
initialize command registry if it hasn't already been initialized
initialize command registry if it hasn ' t already been initialized
// ensure we have a webchat structure // ensure we don't already have a command registry // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Setup Command Registry %%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // create new command registry // set table path // set table path // add table // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Add Commands to Registry %%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // add data to table by path // remove user from channel // retrieve user metadata // add a channel to the webchat // add a channel to the webchat // add a channel to the webchat // get hash table registry // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% lookup each event and set values %%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // declare entry lookup // declare value reference // set entry lookup path // ==== Add User Add To Channel Command ================= // set the lookup path // attempt to lookup table entry by path // ensure we have a lookup // set the event type // set the event type // ==== Add User Add To Channel Command ================= // set the lookup path // attempt to lookup table entry by path // ensure we have a lookup // set the event type // set the event type // ==== Retrieve User Metadata Command ================= // set the lookup path // attempt to lookup table entry by path // ensure we have a lookup // set the event type // set the event type // ==== Channel Add Command ================= // set the lookup path // attempt to lookup table entry by path // ensure we have a lookup // set the event type // set the event type // ==== Channel Remove Command ================= // set the lookup path // attempt to lookup table entry by path // ensure we have a lookup // set the event type // set the event type // ==== Channel Add Message From User ================= // set the lookup path // attempt to lookup table entry by path // ensure we have a lookup // set the event type // set the event type // === Get System Hreg as Json ================ // set the lookup path // attempt to lookup table entry by path // ensure we have a lookup // set the event type // set the event type // return indicating success