library/src/events/generic_event_subsystem_helpers/BP-EventDrivenCommandAndControlGenericSessions.cc
// Create a generic event driven CNC session based on provided json, linking it into the
// provided event manager.
Create a generic event driven CNC session based on provided json, linking it into the
provided event manager.
Create a generic event driven CNC session based on provided json linking it into the provided event manager .
P_BP_EDCNC_GENERIC_SESSION BP_EdcncCreateSession
(
	P_BP_EVENT_MANAGER evm,
	char *session_creation_json
)
{
	if(!evm)
		return NULL;
	if(!session_creation_json)
		return NULL;
	if(!BP_StringIsReasonablePrintableString(session_creation_json, bpstrlen(session_creation_json), BP_TRUE, BP_TRUE))
		return NULL;
	P_BP_JSON parsed_session_creation_json = BP_JSONCreate();
	if(!parsed_session_creation_json)
		return NULL;
	P_BP_HTKE config_entry_lookup = NULL;
	P_BP_HTKE type_lookup              = BP_JSONLookupEntryByPathQuery(parsed_session_creation_json, "/type");
	P_BP_HTKE app_path_lookup          = BP_JSONLookupEntryByPathQuery(parsed_session_creation_json, "/application_path");
	P_BP_HTKE envp_lookup              = BP_JSONLookupEntryByPathQuery(parsed_session_creation_json, "/envp");
	P_BP_HTKE argv_lookup              = BP_JSONLookupEntryByPathQuery(parsed_session_creation_json, "/argv");
	P_BP_HTKE is_interactive_lookup    = BP_JSONLookupEntryByPathQuery(parsed_session_creation_json, "/is_interactive");
	P_BP_HTKE event_status_lookup      = BP_JSONLookupEntryByPathQuery(parsed_session_creation_json, "/application_event_status");
	if
	(
		!type_lookup           ||
		!app_path_lookup       ||
		!envp_lookup           ||
		!argv_lookup           ||
		!is_interactive_lookup ||
		!event_status_lookup
	)
	{
		return NULL;
	}
	if
	(
		type_lookup->type           != BP_HASH_TABLE_KEYED_ENTRY_TYPE_UTF8_STRING      ||
		app_path_lookup->type       != BP_HASH_TABLE_KEYED_ENTRY_TYPE_UTF8_STRING      ||
		is_interactive_lookup->type != BP_HASH_TABLE_KEYED_ENTRY_TYPE_UTF8_STRING      ||
		event_status_lookup->type   != BP_HASH_TABLE_KEYED_ENTRY_TYPE_NAMED_HASH_TABLE ||
		envp_lookup->type           != BP_HASH_TABLE_KEYED_ENTRY_TYPE_NAMED_HASH_TABLE ||
		argv_lookup->type           != BP_HASH_TABLE_KEYED_ENTRY_TYPE_NAMED_HASH_TABLE
	)
	{
		return NULL;
	}
	if(!ht_memmatch_entry(type_lookup, BP_EDCNC_GENERIC_SESSION_MARKER, bpstrlen(BP_EDCNC_GENERIC_SESSION_MARKER)))
	{
		return NULL;
	}
	char * app_path  = (char *) app_path_lookup->data;
	if(!BP_FileAtPathExistsAndIsExecutable(app_path))
	{
		return NULL;
	}
	BP_BOOL is_interactive = BP_FALSE;
	if(ht_memmatch_entry(is_interactive_lookup, "yes", bpstrlen("yes")))
		is_interactive = BP_TRUE;
	%
	%
	P_BP_HASH_TABLE_REGISTRY system_hreg = BP_CreateHashTableRegistry();
	if(!system_hreg)
		return NULL;
	P_BP_EDCNC_GENERIC_SESSION edcnc_generic_session = (P_BP_EDCNC_GENERIC_SESSION) ht_calloc(system_hreg, sizeof(BP_EDCNC_GENERIC_SESSION), 1);
	if(!edcnc_generic_session)
	{
		BP_DestroyHashTableRegistry(system_hreg);
		return NULL;
	}
	edcnc_generic_session->is_interactive_session = is_interactive;
	%
	%
	if(!ht_entry_is_table(envp_lookup))
	{
		BP_EdcncDestroySession(edcnc_generic_session);
		return NULL;
	}
	if(!ht_entry_is_table(argv_lookup))
	{
		BP_EdcncDestroySession(edcnc_generic_session);
		return NULL;
	}
	BP_HASH_ITER_OPEN(envp_lookup, curr_envp_lookup)
	{
		printf("\n BLAH");
	}
	BP_HASH_ITER_CLOSE;
	BP_HASH_ITER_OPEN(argv_lookup, curr_argv_lookup)
	{
		printf("\n BLAH");
	}
	BP_HASH_ITER_CLOSE;
	return NULL;
}
P_BP_EDCNC_GENERIC_SESSION BP_EdcncCreateSession ( P_BP_EVENT_MANAGER evm , char * session_creation_json ) { if ( ! evm ) return NULL ; if ( ! session_creation_json ) return NULL ; if ( ! BP_StringIsReasonablePrintableString ( session_creation_json , bpstrlen ( session_creation_json ) , BP_TRUE , BP_TRUE ) ) return NULL ; P_BP_JSON parsed_session_creation_json = BP_JSONCreate ( ) ; if ( ! parsed_session_creation_json ) return NULL ; P_BP_HTKE config_entry_lookup = NULL ; P_BP_HTKE type_lookup = BP_JSONLookupEntryByPathQuery ( parsed_session_creation_json , " " ) ; P_BP_HTKE app_path_lookup = BP_JSONLookupEntryByPathQuery ( parsed_session_creation_json , " " ) ; P_BP_HTKE envp_lookup = BP_JSONLookupEntryByPathQuery ( parsed_session_creation_json , " " ) ; P_BP_HTKE argv_lookup = BP_JSONLookupEntryByPathQuery ( parsed_session_creation_json , " " ) ; P_BP_HTKE is_interactive_lookup = BP_JSONLookupEntryByPathQuery ( parsed_session_creation_json , " " ) ; P_BP_HTKE event_status_lookup = BP_JSONLookupEntryByPathQuery ( parsed_session_creation_json , " " ) ; if ( ! type_lookup || ! app_path_lookup || ! envp_lookup || ! argv_lookup || ! is_interactive_lookup || ! event_status_lookup ) { return NULL ; } if ( type_lookup -> type != BP_HASH_TABLE_KEYED_ENTRY_TYPE_UTF8_STRING || app_path_lookup -> type != BP_HASH_TABLE_KEYED_ENTRY_TYPE_UTF8_STRING || is_interactive_lookup -> type != BP_HASH_TABLE_KEYED_ENTRY_TYPE_UTF8_STRING || event_status_lookup -> type != BP_HASH_TABLE_KEYED_ENTRY_TYPE_NAMED_HASH_TABLE || envp_lookup -> type != BP_HASH_TABLE_KEYED_ENTRY_TYPE_NAMED_HASH_TABLE || argv_lookup -> type != BP_HASH_TABLE_KEYED_ENTRY_TYPE_NAMED_HASH_TABLE ) { return NULL ; } if ( ! ht_memmatch_entry ( type_lookup , BP_EDCNC_GENERIC_SESSION_MARKER , bpstrlen ( BP_EDCNC_GENERIC_SESSION_MARKER ) ) ) { return NULL ; } char * app_path = ( char * ) app_path_lookup -> data ; if ( ! BP_FileAtPathExistsAndIsExecutable ( app_path ) ) { return NULL ; } BP_BOOL is_interactive = BP_FALSE ; if ( ht_memmatch_entry ( is_interactive_lookup , " " , bpstrlen ( " " ) ) ) is_interactive = BP_TRUE ; P_BP_HASH_TABLE_REGISTRY system_hreg = BP_CreateHashTableRegistry ( ) ; if ( ! system_hreg ) return NULL ; P_BP_EDCNC_GENERIC_SESSION edcnc_generic_session = ( P_BP_EDCNC_GENERIC_SESSION ) ht_calloc ( system_hreg , sizeof ( BP_EDCNC_GENERIC_SESSION ) , 1 ) ; if ( ! edcnc_generic_session ) { BP_DestroyHashTableRegistry ( system_hreg ) ; return NULL ; } edcnc_generic_session -> is_interactive_session = is_interactive ; if ( ! ht_entry_is_table ( envp_lookup ) ) { BP_EdcncDestroySession ( edcnc_generic_session ) ; return NULL ; } if ( ! ht_entry_is_table ( argv_lookup ) ) { BP_EdcncDestroySession ( edcnc_generic_session ) ; return NULL ; } BP_HASH_ITER_OPEN ( envp_lookup , curr_envp_lookup ) { printf ( " \n " ) ; } BP_HASH_ITER_CLOSE ; BP_HASH_ITER_OPEN ( argv_lookup , curr_argv_lookup ) { printf ( " \n " ) ; } BP_HASH_ITER_CLOSE ; return NULL ; }
Create a generic event driven CNC session based on provided json, linking it into the
provided event manager.
Create a generic event driven CNC session based on provided json linking it into the provided event manager .
// basic null checks // run basic check to ensure no garbage characters exist in our buffer // create new json session to parse from // if we don't have a parsed session creation json, exit null /*
	// example command and control buffer for parsing
	char * basic_generic_command_and_control_initial_json_structure = ""\
	"\n  {"\
	"\n  	'type': 'app_command_and_control',   "\
	"\n  	'application_path': '',              "\
	"\n  	'envp':                              "\
	"\n  	{                                    "\
	"\n  	},                                   "\
	"\n  	'argv':                              "\
	"\n  	{                                    "\
	"\n  	},                                   "\
	"\n  	'is_interactive': 'yes',             "\
	"\n  	'application_event_status':          "\
	"\n  	{                                    "\
	"\n  		'val1': 'blah'                   "\
	"\n  	}                                    "\
	"\n  }";
	*/ // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Extract Data from JSON %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // entry lookup into json table // perform json lookups // ensure all initial lookups were successful // run basic type checks // --- check for type marker ------------- // ensure that the type lookup matches our marker (defined in BP-Main.h) // --- run additional data checks ------- // gather app path // ensure path exists at provided position // ensure app is interactive // ensure that the type lookup matches our marker // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Create Session %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // create system hreg // ensure we have a system hreg // attempt to create session within hreg // ensure we have created our sesssion // mark session as interactive // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Envp and Argv Checks %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // check if our envp lookup is a table // check if our argv lookup is a table // -- iterate through envp and create --- // iterate through envp hashes // curr_envp_lookup->key; // curr_envp_lookup->data; // -- iterate through argv and create --- // iterate through envp hashes // curr_envp_lookup->key; // curr_envp_lookup->data; // size_t  envp_element_count = 0; // size_t  argv_element_count = 0; // return null