library/src/network/httpd/BP-HTTPdRequestHandlerParameterFilters.cc
// Add parameter filter.  Filters stack.  Attempting to add two filters
// to one request handler will result in cascading filtering.
Add parameter filter.  Filters stack.  Attempting to add two filters
to one request handler will result in cascading filtering.
Add parameter filter . Filters stack . Attempting to add two filters to one request handler will result in cascading filtering .
BP_ERROR_T BP_HTTPdRequestHandlerParameterFilterAdd
(
	P_BP_HTTPD_REQUEST_HANDLER                         request_handler,
	BP_HTTPD_REQUEST_VAR_TYPE                          var_type,
	char                                              *key,
	char                                              *filter_name,
	BP_HTTPdRequestHandlerParameterFilterFptr          filter,
	P_BP_HTTPD_REQUEST_HANDLER_PARAMETER_FILTER_CONFIG filter_config
)
{
	if(!request_handler)
		return ERR_FAILURE;
	if(!var_type)
		return ERR_FAILURE;
	if(!key)
		return ERR_FAILURE;
	if(!filter)
		return ERR_FAILURE;
	char *reg_path[10];
	BP_ZERO_STACK(reg_path);
	size_t path_idx = 0;
	reg_path[path_idx] = "filters";
	path_idx++;
	if(!request_handler->parameter_filters)
	{
		request_handler->parameter_filters = BP_CreateHashTableRegistry();
		if(!request_handler->parameter_filters)
			return ERR_FAILURE;
		BP_HashRegAddTableByPath(request_handler->parameter_filters, (char **) &reg_path);
		reg_path[path_idx] = "BP_HTTPD_REQUEST_VAR_TYPE_COOKIE";
		BP_HashRegAddTableByPath(request_handler->parameter_filters, (char **) &reg_path);
		reg_path[path_idx] = "BP_HTTPD_REQUEST_VAR_TYPE_GET";
		BP_HashRegAddTableByPath(request_handler->parameter_filters, (char **) &reg_path);
		reg_path[path_idx] = "BP_HTTPD_REQUEST_VAR_TYPE_HEADER";
		BP_HashRegAddTableByPath(request_handler->parameter_filters, (char **) &reg_path);
		reg_path[path_idx] = "BP_HTTPD_REQUEST_VAR_TYPE_POST_DATA";
		BP_HashRegAddTableByPath(request_handler->parameter_filters, (char **) &reg_path);
		reg_path[path_idx] = "BP_HTTPD_REQUEST_VAR_TYPE_POST_TMPFILE";
		BP_HashRegAddTableByPath(request_handler->parameter_filters, (char **) &reg_path);
	}
	%
	%
	char * type_indicator_str = NULL;
	char *add_path[10];
	BP_ZERO_STACK(add_path);
	size_t add_path_idx = 0;
	add_path[add_path_idx] = "filters";
	add_path_idx++;
	switch(var_type)
	{
		case BP_HTTPD_REQUEST_VAR_TYPE_POST_DATA:
			type_indicator_str = "BP_HTTPD_REQUEST_VAR_TYPE_POST_DATA";
			add_path[path_idx] = "BP_HTTPD_REQUEST_VAR_TYPE_POST_DATA";
			add_path_idx++;
			break;
		case BP_HTTPD_REQUEST_VAR_TYPE_POST_TMPFILE:
			type_indicator_str = "BP_HTTPD_REQUEST_VAR_TYPE_POST_TMPFILE";
			add_path[path_idx] = "BP_HTTPD_REQUEST_VAR_TYPE_POST_TMPFILE";
			add_path_idx++;
			break;
		case BP_HTTPD_REQUEST_VAR_TYPE_GET:
			type_indicator_str = "BP_HTTPD_REQUEST_VAR_TYPE_GET";
			add_path[path_idx] = "BP_HTTPD_REQUEST_VAR_TYPE_GET";
			add_path_idx++;
			break;
		case BP_HTTPD_REQUEST_VAR_TYPE_COOKIE:
			type_indicator_str = "BP_HTTPD_REQUEST_VAR_TYPE_COOKIE";
			add_path[path_idx] = "BP_HTTPD_REQUEST_VAR_TYPE_COOKIE";
			add_path_idx++;
			break;
		case BP_HTTPD_REQUEST_VAR_TYPE_HEADER:
			type_indicator_str = "BP_HTTPD_REQUEST_VAR_TYPE_HEADER";
			add_path[path_idx] = "BP_HTTPD_REQUEST_VAR_TYPE_HEADER";
			add_path_idx++;
			break;
		default:
			break;
	}
	if(!type_indicator_str)
		return ERR_FAILURE;
	add_path[add_path_idx] = key;
	add_path_idx++;
	BP_HashRegAddTableByPath
	(
		request_handler->parameter_filters,
		(char **) &add_path
	);
	add_path[add_path_idx] = "filter_set";
	if(!BP_HashRegAddTableByPath(request_handler->parameter_filters,(char **) &add_path))
	{
		return ERR_FAILURE;
	}
	%
	%
	char *filter_set_add_path[] = {"filters", type_indicator_str, key, "filter_set", NULL};
	BP_ERROR_T filter_add_ret_val = ERR_FAILURE;
	filter_add_ret_val = BP_HashRegAddDataToTableByPath
	(
			request_handler->parameter_filters,
			(char **) &filter_set_add_path,
			filter_name,
			BP_HASH_TABLE_KEYED_ENTRY_TYPE_BINARY_BLOB,
			NULL,
			sizeof(BP_HTTPD_REQUEST_HANDLER_PARAMETER_FILTER)
	);
	if(!filter_add_ret_val)
	{
		return ERR_FAILURE;
	}
	%%%%%%%%%%
	%%%%%%%%%%
	char *filter_set_lookup_path[] = {"filters", type_indicator_str, key, "filter_set", filter_name, NULL};
	P_BP_HASH_TABLE_KEYED_ENTRY new_filter_lookup = BP_HashRegLookupTableEntryByPath
	(
		request_handler->parameter_filters,
		(char **) &filter_set_lookup_path
	);
	if(!new_filter_lookup)
		return ERR_FAILURE;
	if(!new_filter_lookup->data)
		return ERR_FAILURE;
	%
	%
	P_BP_HTTPD_REQUEST_HANDLER_PARAMETER_FILTER new_filter = (P_BP_HTTPD_REQUEST_HANDLER_PARAMETER_FILTER) new_filter_lookup->data;
	new_filter->key = filter_name;
	new_filter->filter = filter;
	new_filter->var_type = var_type;
	new_filter->request_handler = request_handler;
	if(filter_config)
	{
		memcpy
		(
			&new_filter->filter_config,
			filter_config,
			sizeof(BP_HTTPD_REQUEST_HANDLER_PARAMETER_FILTER_CONFIG)
		);
		new_filter->filter_config_has_been_set = BP_TRUE;
	}
	return ERR_SUCCESS;
}
BP_ERROR_T BP_HTTPdRequestHandlerParameterFilterAdd ( P_BP_HTTPD_REQUEST_HANDLER request_handler , BP_HTTPD_REQUEST_VAR_TYPE var_type , char * key , char * filter_name , BP_HTTPdRequestHandlerParameterFilterFptr filter , P_BP_HTTPD_REQUEST_HANDLER_PARAMETER_FILTER_CONFIG filter_config ) { if ( ! request_handler ) return ERR_FAILURE ; if ( ! var_type ) return ERR_FAILURE ; if ( ! key ) return ERR_FAILURE ; if ( ! filter ) return ERR_FAILURE ; char * reg_path [ 10 ] ; BP_ZERO_STACK ( reg_path ) ; size_t path_idx = 0 ; reg_path [ path_idx ] = " " ; path_idx ++ ; if ( ! request_handler -> parameter_filters ) { request_handler -> parameter_filters = BP_CreateHashTableRegistry ( ) ; if ( ! request_handler -> parameter_filters ) return ERR_FAILURE ; BP_HashRegAddTableByPath ( request_handler -> parameter_filters , ( char * * ) & reg_path ) ; reg_path [ path_idx ] = " " ; BP_HashRegAddTableByPath ( request_handler -> parameter_filters , ( char * * ) & reg_path ) ; reg_path [ path_idx ] = " " ; BP_HashRegAddTableByPath ( request_handler -> parameter_filters , ( char * * ) & reg_path ) ; reg_path [ path_idx ] = " " ; BP_HashRegAddTableByPath ( request_handler -> parameter_filters , ( char * * ) & reg_path ) ; reg_path [ path_idx ] = " " ; BP_HashRegAddTableByPath ( request_handler -> parameter_filters , ( char * * ) & reg_path ) ; reg_path [ path_idx ] = " " ; BP_HashRegAddTableByPath ( request_handler -> parameter_filters , ( char * * ) & reg_path ) ; } char * type_indicator_str = NULL ; char * add_path [ 10 ] ; BP_ZERO_STACK ( add_path ) ; size_t add_path_idx = 0 ; add_path [ add_path_idx ] = " " ; add_path_idx ++ ; switch ( var_type ) { case BP_HTTPD_REQUEST_VAR_TYPE_POST_DATA : type_indicator_str = " " ; add_path [ path_idx ] = " " ; add_path_idx ++ ; break ; case BP_HTTPD_REQUEST_VAR_TYPE_POST_TMPFILE : type_indicator_str = " " ; add_path [ path_idx ] = " " ; add_path_idx ++ ; break ; case BP_HTTPD_REQUEST_VAR_TYPE_GET : type_indicator_str = " " ; add_path [ path_idx ] = " " ; add_path_idx ++ ; break ; case BP_HTTPD_REQUEST_VAR_TYPE_COOKIE : type_indicator_str = " " ; add_path [ path_idx ] = " " ; add_path_idx ++ ; break ; case BP_HTTPD_REQUEST_VAR_TYPE_HEADER : type_indicator_str = " " ; add_path [ path_idx ] = " " ; add_path_idx ++ ; break ; default : break ; } if ( ! type_indicator_str ) return ERR_FAILURE ; add_path [ add_path_idx ] = key ; add_path_idx ++ ; BP_HashRegAddTableByPath ( request_handler -> parameter_filters , ( char * * ) & add_path ) ; add_path [ add_path_idx ] = " " ; if ( ! BP_HashRegAddTableByPath ( request_handler -> parameter_filters , ( char * * ) & add_path ) ) { return ERR_FAILURE ; } char * filter_set_add_path [ ] = { " " , type_indicator_str , key , " " , NULL } ; BP_ERROR_T filter_add_ret_val = ERR_FAILURE ; filter_add_ret_val = BP_HashRegAddDataToTableByPath ( request_handler -> parameter_filters , ( char * * ) & filter_set_add_path , filter_name , BP_HASH_TABLE_KEYED_ENTRY_TYPE_BINARY_BLOB , NULL , sizeof ( BP_HTTPD_REQUEST_HANDLER_PARAMETER_FILTER ) ) ; if ( ! filter_add_ret_val ) { return ERR_FAILURE ; } char * filter_set_lookup_path [ ] = { " " , type_indicator_str , key , " " , filter_name , NULL } ; P_BP_HASH_TABLE_KEYED_ENTRY new_filter_lookup = BP_HashRegLookupTableEntryByPath ( request_handler -> parameter_filters , ( char * * ) & filter_set_lookup_path ) ; if ( ! new_filter_lookup ) return ERR_FAILURE ; if ( ! new_filter_lookup -> data ) return ERR_FAILURE ; P_BP_HTTPD_REQUEST_HANDLER_PARAMETER_FILTER new_filter = ( P_BP_HTTPD_REQUEST_HANDLER_PARAMETER_FILTER ) new_filter_lookup -> data ; new_filter -> key = filter_name ; new_filter -> filter = filter ; new_filter -> var_type = var_type ; new_filter -> request_handler = request_handler ; if ( filter_config ) { memcpy ( & new_filter -> filter_config , filter_config , sizeof ( BP_HTTPD_REQUEST_HANDLER_PARAMETER_FILTER_CONFIG ) ) ; new_filter -> filter_config_has_been_set = BP_TRUE ; } return ERR_SUCCESS ; }
Add parameter filter.
Add parameter filter .
// Run basic checks // note: filter_config is optional. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Create Registry if Necessary %%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // create space for registry path // path index is zero // set parameter filter // only create filters if they don't exist. // create hash table registry // add filters table // add cookie table // add http get table // add http header table // add post data table // add post tmpfile table // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Attempt Filter Addition %%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // This is a type indicator string set in the switch below // create add path on the stack // path index // set initial path to filters // switch on the var type // post data type // set tmpfile // set get // set cookie // set header path // default case is to break // ensure we have a type indicator string (set in switch above) // set the final path lookup from key parameter // add table by path // filter set for this filter // add table by path // return indicating failure if we couldn't add the filter set table ok // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Add Filter Entry %%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // set lookup path // set filter add value // attempt to add data to table // ensure we have added the filter ok // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Run Lookup %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // set lookup path // attempt to lookup the new filter // ensure we have a new filter // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Add New Entry Info %%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // reference new filter // set the new filter key // set the filter // set the var type // set the request handler // if we have a filter config, copy it over // copy in config // mark set config value to true after copy completes // return indicating success after all data set