library/src/network/httpd/BP-HTTPdRequestHandlerParameterFilters.cc
// Attempts to run filter checks on a request.  Request filters are stored in the request handler, filter check
// output is stored in the P_BP_HTTPD_REQUEST itself.  Logically, this function should be stored with the httpd
// request methods themselves, but I made a dev-call and put this function here instead, as it's heavily reliant
// on the code here (above).
Attempts to run filter checks on a request.  Request filters are stored in the request handler, filter check
output is stored in the P_BP_HTTPD_REQUEST itself.  Logically, this function should be stored with the httpd
request methods themselves, but I made a dev-call and put this function here instead, as it's heavily reliant
on the code here (above).
Attempts to run filter checks on a request . Request filters are stored in the request handler filter check output is stored in the P_BP_HTTPD_REQUEST itself . Logically this function should be stored with the httpd request methods themselves but I made a dev - call and put this function here instead as it ' s heavily reliant on the code here ( above ) .
BP_ERROR_T BP_HTTPdRequestRunFilterChecks(P_BP_HTTPD_REQUEST req)
{
	if(!req)
		return ERR_FAILURE;
	if(!req->request_handler)
		return ERR_FAILURE;
	if(!req->request_handler->parameter_filters)
		return ERR_FAILURE;
	if(BP_HTTPdRequestContainsPOST(req))
	{
		char * post_table_lookup_path[] = {"POST", NULL};
		P_BP_HASH_TABLE_KEYED_ENTRY post_table = NULL;
		post_table = BP_HashRegLookupTableByPath(req->arg_hreg, (char **) &post_table_lookup_path);
		if(!post_table->data)
			return ERR_FAILURE;
		post_table = (P_BP_HASH_TABLE_KEYED_ENTRY) post_table->data;
		P_BP_HTTPD_REQUEST_VAR curr_var = NULL;
		BP_HASH_ITER_OPEN(post_table, post_table_iter)
		{
			curr_var = (P_BP_HTTPD_REQUEST_VAR) post_table_iter->data;
			if(!curr_var)
				break;
			P_BP_HASH_TABLE_KEYED_ENTRY post_filter_set = BP_HTTPdRequestHandlerParameterFilterSetLookup
			(
				req->request_handler,
				BP_HTTPD_REQUEST_VAR_TYPE_POST_DATA,
				curr_var->name
			);
			if(!post_filter_set)
				break;
			BP_HASH_ITER_OPEN(post_filter_set, post_filter_entry)
			{
				if(!post_filter_entry)
					break;
				printf("\n WOOP: FILTER KEY -> %s", post_filter_entry->key);
				if
				(
					!BP_HTTPdRequestHandlerFilterCheckVarAgainstFilter
					(
						(P_BP_HTTPD_REQUEST_VAR)                      curr_var,
						(P_BP_HTTPD_REQUEST_HANDLER_PARAMETER_FILTER) post_filter_entry->data
					)
				)
				{
					return ERR_FAILURE;
				}
			} BP_HASH_ITER_CLOSE;
		} BP_HASH_ITER_CLOSE;
	}
	if(BP_HTTPdRequestContainsGET(req))
	{
		char * get_table_lookup_path[] = {"GET", NULL};
		P_BP_HASH_TABLE_KEYED_ENTRY get_table = NULL;
		get_table = BP_HashRegLookupTableByPath(req->arg_hreg, (char **) &get_table_lookup_path);
		if(!get_table->data)
			return ERR_FAILURE;
		get_table = (P_BP_HASH_TABLE_KEYED_ENTRY) get_table->data;
		P_BP_HTTPD_REQUEST_VAR curr_var = NULL;
		BP_HASH_ITER_OPEN(get_table, get_table_iter)
		{
			curr_var = (P_BP_HTTPD_REQUEST_VAR) get_table_iter->data;
			if(!curr_var)
				break;
			P_BP_HASH_TABLE_KEYED_ENTRY get_filter_set = BP_HTTPdRequestHandlerParameterFilterSetLookup
			(
				req->request_handler,
				BP_HTTPD_REQUEST_VAR_TYPE_GET,
				curr_var->name
			);
			if(!get_filter_set)
				break;
			BP_HASH_ITER_OPEN(get_filter_set, get_filter_entry)
			{
				if(!get_filter_entry)
					break;
				printf("\n GET FILTER KEY -> %s", get_filter_entry->key);
				if
				(
					!BP_HTTPdRequestHandlerFilterCheckVarAgainstFilter
					(
						(P_BP_HTTPD_REQUEST_VAR)                      curr_var,
						(P_BP_HTTPD_REQUEST_HANDLER_PARAMETER_FILTER) get_filter_entry->data
					)
				)
				{
					return ERR_FAILURE;
				}
			} BP_HASH_ITER_CLOSE;
		} BP_HASH_ITER_CLOSE;
	}
	if(BP_HTTPdRequestContainsHEADER(req))
	{
	}
	if(BP_HTTPdRequestContainsCOOKIE(req))
	{
	}
	BP_HashRegDisplay(req->arg_hreg, BP_FALSE, BP_TRUE);
	/*
	// %%% Iterate Through Filters and Apply %%%%%%%%%%%%%%%%%%
	// set lookup path to the filters table
	char *filter_set_lookup[] = {"filters", NULL};
	// iterate through filters set
	BP_HASH_ITER_FROM_LOOKUP_PATH_OPEN
	(
		req->request_handler->parameter_filters,
		(char **) &filter_set_lookup,
		filter_iter_entry
	)
	{
		// iterate through filter entries
		if(filter_iter_entry->data)
		{
			P_BP_HASH_TABLE_KEYED_ENTRY filter_set_table = (P_BP_HASH_TABLE_KEYED_ENTRY) filter_iter_entry->data;
		}
	} BP_HASH_ITER_FROM_LOOKUP_PATH_CLOSE;
	*/
	return ERR_SUCCESS;
}
BP_ERROR_T BP_HTTPdRequestRunFilterChecks ( P_BP_HTTPD_REQUEST req ) { if ( ! req ) return ERR_FAILURE ; if ( ! req -> request_handler ) return ERR_FAILURE ; if ( ! req -> request_handler -> parameter_filters ) return ERR_FAILURE ; if ( BP_HTTPdRequestContainsPOST ( req ) ) { char * post_table_lookup_path [ ] = { " " , NULL } ; P_BP_HASH_TABLE_KEYED_ENTRY post_table = NULL ; post_table = BP_HashRegLookupTableByPath ( req -> arg_hreg , ( char * * ) & post_table_lookup_path ) ; if ( ! post_table -> data ) return ERR_FAILURE ; post_table = ( P_BP_HASH_TABLE_KEYED_ENTRY ) post_table -> data ; P_BP_HTTPD_REQUEST_VAR curr_var = NULL ; BP_HASH_ITER_OPEN ( post_table , post_table_iter ) { curr_var = ( P_BP_HTTPD_REQUEST_VAR ) post_table_iter -> data ; if ( ! curr_var ) break ; P_BP_HASH_TABLE_KEYED_ENTRY post_filter_set = BP_HTTPdRequestHandlerParameterFilterSetLookup ( req -> request_handler , BP_HTTPD_REQUEST_VAR_TYPE_POST_DATA , curr_var -> name ) ; if ( ! post_filter_set ) break ; BP_HASH_ITER_OPEN ( post_filter_set , post_filter_entry ) { if ( ! post_filter_entry ) break ; printf ( " \n " , post_filter_entry -> key ) ; if ( ! BP_HTTPdRequestHandlerFilterCheckVarAgainstFilter ( ( P_BP_HTTPD_REQUEST_VAR ) curr_var , ( P_BP_HTTPD_REQUEST_HANDLER_PARAMETER_FILTER ) post_filter_entry -> data ) ) { return ERR_FAILURE ; } } BP_HASH_ITER_CLOSE ; } BP_HASH_ITER_CLOSE ; } if ( BP_HTTPdRequestContainsGET ( req ) ) { char * get_table_lookup_path [ ] = { " " , NULL } ; P_BP_HASH_TABLE_KEYED_ENTRY get_table = NULL ; get_table = BP_HashRegLookupTableByPath ( req -> arg_hreg , ( char * * ) & get_table_lookup_path ) ; if ( ! get_table -> data ) return ERR_FAILURE ; get_table = ( P_BP_HASH_TABLE_KEYED_ENTRY ) get_table -> data ; P_BP_HTTPD_REQUEST_VAR curr_var = NULL ; BP_HASH_ITER_OPEN ( get_table , get_table_iter ) { curr_var = ( P_BP_HTTPD_REQUEST_VAR ) get_table_iter -> data ; if ( ! curr_var ) break ; P_BP_HASH_TABLE_KEYED_ENTRY get_filter_set = BP_HTTPdRequestHandlerParameterFilterSetLookup ( req -> request_handler , BP_HTTPD_REQUEST_VAR_TYPE_GET , curr_var -> name ) ; if ( ! get_filter_set ) break ; BP_HASH_ITER_OPEN ( get_filter_set , get_filter_entry ) { if ( ! get_filter_entry ) break ; printf ( " \n " , get_filter_entry -> key ) ; if ( ! BP_HTTPdRequestHandlerFilterCheckVarAgainstFilter ( ( P_BP_HTTPD_REQUEST_VAR ) curr_var , ( P_BP_HTTPD_REQUEST_HANDLER_PARAMETER_FILTER ) get_filter_entry -> data ) ) { return ERR_FAILURE ; } } BP_HASH_ITER_CLOSE ; } BP_HASH_ITER_CLOSE ; } if ( BP_HTTPdRequestContainsHEADER ( req ) ) { } if ( BP_HTTPdRequestContainsCOOKIE ( req ) ) { } BP_HashRegDisplay ( req -> arg_hreg , BP_FALSE , BP_TRUE ) ; return ERR_SUCCESS ; }
Attempts to run filter checks on a request.
Attempts to run filter checks on a request .
// run basic checks // Note:  This routine tries to be as efficient as possible by only running checks against //        posted parameters. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Run HTTP Post Filters %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // only run post checks if we have posted arguments // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Lookup HTTP Post Data Table %%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // set the posted data lookup path // post table // attempt to looup the post table // set post table from data pointer so we can iterate // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Iterate HTTP Post Data Table %%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // req->arg_hreg // close the hash iterator // set the current value on loop // attempt to pull a filter set // ensure we have a filter set // iterate though hashes // break if we have no entries // if the filter check fails, exit immediately (don't run other checks, just fail immediately) // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Run HTTP GET Filters %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Lookup HTTP GET Data Table %%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // set the http get data lookup path // get table // attempt to looup the get table // set get table from data pointer so we can iterate // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Iterate HTTP GET Data Table %%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // req->arg_hreg // close the hash iterator // set the current value on loop // attempt to pull a filter set // ensure we have a filter set // iterate though hashes // break if we have no entries // if the filter check fails, exit immediately (don't run other checks, just fail immediately) // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Run HTTP HEADER Filters %%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Run HTTP COOKIE Filters %%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // display the argument hreg at this point /*
	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	// %%% Iterate Through Filters and Apply %%%%%%%%%%%%%%%%%%
	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

	// set lookup path to the filters table
	char *filter_set_lookup[] = {"filters", NULL};

	// iterate through filters set
	BP_HASH_ITER_FROM_LOOKUP_PATH_OPEN
	(
		req->request_handler->parameter_filters,
		(char **) &filter_set_lookup,
		filter_iter_entry
	)
	{

		// iterate through filter entries
		if(filter_iter_entry->data)
		{

			P_BP_HASH_TABLE_KEYED_ENTRY filter_set_table = (P_BP_HASH_TABLE_KEYED_ENTRY) filter_iter_entry->data;

		}

	} BP_HASH_ITER_FROM_LOOKUP_PATH_CLOSE;
	*/ // return indicating success