library/src/network/httpd/BP-HTTPdRequestHandlers.cc
// This method will dispatch a request handler.  This should only be called from
// within a MHD request access handler callback (eg: BP_HTTPdDefaultAccessHandlerCallback).
This method will dispatch a request handler.  This should only be called from
within a MHD request access handler callback .
This method will dispatch a request handler . This should only be called from within a MHD request access handler callback .
BP_ERROR_T BP_HTTPdRequestHandlerDispatch
(
		P_BP_HTTPD_REQUEST     request,
		char *                 handler,
		struct MHD_Connection *connection,
		const char *           url,
		const char *           method,
		const char *           version,
		const char *           upload_data,
		size_t *               upload_data_size,
		void **                con_cls
)
{
	if(!request)
		return ERR_FAILURE;
	if(!request->httpd)
		return ERR_FAILURE;
	if(!request->httpd->system_hreg)
		return ERR_FAILURE;
	if(!url)
			return ERR_FAILURE;
	if(!method)
			return ERR_FAILURE;
	if(!version)
			return ERR_FAILURE;
	if(BP_StringIsReasonablePrintableString((char *) url, bpstrlen((char *) url), BP_FALSE, BP_FALSE) != BP_TRUE)
	{
			return ERR_FAILURE;
	}
	if(BP_StringIsReasonablePrintableString((char *) method, bpstrlen((char *) method), BP_FALSE, BP_FALSE) != BP_TRUE)
	{
			return ERR_FAILURE;
	}
	if(BP_StringIsReasonablePrintableString((char *) version, bpstrlen((char *) version), BP_FALSE, BP_FALSE) != BP_TRUE)
	{
			return ERR_FAILURE;
	}
	%
	%
	P_BP_HTTPD_REQUEST_HANDLER request_handler = BP_HTTPdRequestHandlerLookup(request->httpd, (char *) url);
	if(!request_handler)
		return ERR_FAILURE;
	BP_HTTPD_METHOD curr_request_method = BP_HTTPdDetermineMethod((char *) method);
	if(!(BP_FLAG_IS_SET(request_handler->supported_http_methods, curr_request_method)))
	{
		printf("\n [+] UNSUPPORTED METHOD DETECTED");
		printf("\n");
		return ERR_FAILURE;
	}
	request_handler->activation_n++;
	BP_ERROR_T handler_ret_status = request_handler->handler
	(
			request,
			connection,
			url,
			method,
			version,
			upload_data,
			upload_data_size,
			con_cls
	);
	if(handler_ret_status == ERR_FAILURE)
		request_handler->error_n++;
	else
		request_handler->completed_n++;
	%%%%
	%%%%
	return ERR_SUCCESS;
}
BP_ERROR_T BP_HTTPdRequestHandlerDispatch ( P_BP_HTTPD_REQUEST request , char * handler , struct MHD_Connection * connection , const char * url , const char * method , const char * version , const char * upload_data , size_t * upload_data_size , void * * con_cls ) { if ( ! request ) return ERR_FAILURE ; if ( ! request -> httpd ) return ERR_FAILURE ; if ( ! request -> httpd -> system_hreg ) return ERR_FAILURE ; if ( ! url ) return ERR_FAILURE ; if ( ! method ) return ERR_FAILURE ; if ( ! version ) return ERR_FAILURE ; if ( BP_StringIsReasonablePrintableString ( ( char * ) url , bpstrlen ( ( char * ) url ) , BP_FALSE , BP_FALSE ) != BP_TRUE ) { return ERR_FAILURE ; } if ( BP_StringIsReasonablePrintableString ( ( char * ) method , bpstrlen ( ( char * ) method ) , BP_FALSE , BP_FALSE ) != BP_TRUE ) { return ERR_FAILURE ; } if ( BP_StringIsReasonablePrintableString ( ( char * ) version , bpstrlen ( ( char * ) version ) , BP_FALSE , BP_FALSE ) != BP_TRUE ) { return ERR_FAILURE ; } P_BP_HTTPD_REQUEST_HANDLER request_handler = BP_HTTPdRequestHandlerLookup ( request -> httpd , ( char * ) url ) ; if ( ! request_handler ) return ERR_FAILURE ; BP_HTTPD_METHOD curr_request_method = BP_HTTPdDetermineMethod ( ( char * ) method ) ; if ( ! ( BP_FLAG_IS_SET ( request_handler -> supported_http_methods , curr_request_method ) ) ) { printf ( " \n " ) ; printf ( " \n " ) ; return ERR_FAILURE ; } request_handler -> activation_n ++ ; BP_ERROR_T handler_ret_status = request_handler -> handler ( request , connection , url , method , version , upload_data , upload_data_size , con_cls ) ; if ( handler_ret_status == ERR_FAILURE ) request_handler -> error_n ++ ; else request_handler -> completed_n ++ ; return ERR_SUCCESS ; }
This method will dispatch a request handler.
This method will dispatch a request handler .
// ensure we have a request and httpd // the httpd must have a hash registry associated with it // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Run Basic Sanity Checks %%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // run basic checks // URL string check // Method string check. // Version string check. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Lookup Request Handler and Dispatch %%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // attempt to lookup the handler in the hash table // ensure we have a request handler // attempt to get the current method of the post // printf("\n Current Method is?: %u", curr_request_method); // check to see if the method is supported // increment the total activation counts // call the handler directly // if the request failed, increment the error count, else increment the completed count // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Do Request Cleanup and Exit %%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // return indicating success