library/src/javascript/BP-Javascript.cc
// Creates a javascript event within the event manager.
Creates a javascript event within the event manager.
Creates a javascript event within the event manager .
BP_ERROR_T BP_JSCreateEvent
(
		P_BP_EVENT_MANAGER         event_manager,
		P_BP_EVENT_PROCESSOR       processor,
		P_BP_EVENT_PROCESSOR       output_transformation_processor,
		BP_EVENT_MESSAGE_IN_OUT    append_to_queue,
		char *                     event_name,
		char *                     event_description,
		char *                     event_javascript_code,
		size_t                     event_code_size,
		BP_JS_RUN_CONTEXT_T        event_run_ctx,
		BP_JS_PRIVILEGE_LEVEL_T    event_privilege_level,
		P_BP_JS_EVENT_PRIVILEGES   event_privileges,
		BP_EVENT_PRIORITY          event_priority
)
{
	if(!event_manager)
		return ERR_FAILURE;
	if(!processor)
		return ERR_FAILURE;
	if(!output_transformation_processor)
		return ERR_FAILURE;
	if(!append_to_queue)
		return ERR_FAILURE;
	if(!event_name)
		return ERR_FAILURE;
	if(!event_description)
		return ERR_FAILURE;
	if(!event_javascript_code)
		return ERR_FAILURE;
	if(!event_code_size)
		return ERR_FAILURE;
	if(!event_priority)
		return ERR_FAILURE;
	if(bpstrlen(event_javascript_code) != event_code_size)
		return ERR_FAILURE;
	if(!BP_StringIsReasonablePrintableString(event_javascript_code, event_code_size, BP_TRUE, BP_TRUE))
		return ERR_FAILURE;
	P_BP_JS_EVENT_DATA new_event = (P_BP_JS_EVENT_DATA) bpcalloc(sizeof(BP_JS_EVENT_DATA), 1);
	new_event->javascript_code = bpstrdup(event_javascript_code);
	new_event->code_size       = event_code_size;
	BP_EVENT_TYPE_MARKER type_marker = BP_EVENT_TYPE_MARKER_UNSET;
	switch(event_run_ctx)
	{
		case BP_JS_CONTEXT_SYSTEM:
			type_marker = BP_EVENT_TYPE_MARKER_SYSTEM_JS_EVENT;
			break;
		case BP_JS_CONTEXT_HTML_DOM:
			type_marker = BP_EVENT_TYPE_MARKER_DOM_JS_EVENT;
			break;
		default:
			type_marker = BP_EVENT_TYPE_MARKER_UNSET;
			break;
	}
	BP_ERROR_T err_status = BP_EventMgrCreateEvent
	(
		event_manager,
		processor,
		output_transformation_processor,
		append_to_queue,
		type_marker,
		event_name,
		event_description,
		(void *) new_event,
		sizeof(BP_JS_EVENT_DATA),
		event_priority
	);
	if(!err_status)
		return ERR_FAILURE;
	return ERR_SUCCESS;
}
BP_ERROR_T BP_JSCreateEvent ( P_BP_EVENT_MANAGER event_manager , P_BP_EVENT_PROCESSOR processor , P_BP_EVENT_PROCESSOR output_transformation_processor , BP_EVENT_MESSAGE_IN_OUT append_to_queue , char * event_name , char * event_description , char * event_javascript_code , size_t event_code_size , BP_JS_RUN_CONTEXT_T event_run_ctx , BP_JS_PRIVILEGE_LEVEL_T event_privilege_level , P_BP_JS_EVENT_PRIVILEGES event_privileges , BP_EVENT_PRIORITY event_priority ) { if ( ! event_manager ) return ERR_FAILURE ; if ( ! processor ) return ERR_FAILURE ; if ( ! output_transformation_processor ) return ERR_FAILURE ; if ( ! append_to_queue ) return ERR_FAILURE ; if ( ! event_name ) return ERR_FAILURE ; if ( ! event_description ) return ERR_FAILURE ; if ( ! event_javascript_code ) return ERR_FAILURE ; if ( ! event_code_size ) return ERR_FAILURE ; if ( ! event_priority ) return ERR_FAILURE ; if ( bpstrlen ( event_javascript_code ) != event_code_size ) return ERR_FAILURE ; if ( ! BP_StringIsReasonablePrintableString ( event_javascript_code , event_code_size , BP_TRUE , BP_TRUE ) ) return ERR_FAILURE ; P_BP_JS_EVENT_DATA new_event = ( P_BP_JS_EVENT_DATA ) bpcalloc ( sizeof ( BP_JS_EVENT_DATA ) , 1 ) ; new_event -> javascript_code = bpstrdup ( event_javascript_code ) ; new_event -> code_size = event_code_size ; BP_EVENT_TYPE_MARKER type_marker = BP_EVENT_TYPE_MARKER_UNSET ; switch ( event_run_ctx ) { case BP_JS_CONTEXT_SYSTEM : type_marker = BP_EVENT_TYPE_MARKER_SYSTEM_JS_EVENT ; break ; case BP_JS_CONTEXT_HTML_DOM : type_marker = BP_EVENT_TYPE_MARKER_DOM_JS_EVENT ; break ; default : type_marker = BP_EVENT_TYPE_MARKER_UNSET ; break ; } BP_ERROR_T err_status = BP_EventMgrCreateEvent ( event_manager , processor , output_transformation_processor , append_to_queue , type_marker , event_name , event_description , ( void * ) new_event , sizeof ( BP_JS_EVENT_DATA ) , event_priority ) ; if ( ! err_status ) return ERR_FAILURE ; return ERR_SUCCESS ; }
Creates a javascript event within the event manager.
Creates a javascript event within the event manager .
// ensure that the code matches the size provided // ensure the code has no insane characters // create new event data // set javascript code and size // create type marker // switch on the event running context type to determine which // marker is the correct one to use. // set context to system if its a system event // set context to dom if it's a dom event // default is no context // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Dispatch Event %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // create new event // ensure event was created ok // return indicating success