library/src/network/httpd/BP-HTTPdDefaultCallbacks.cc
// This is the default CSS type request handler.
This is the default CSS type request handler.
This is the default CSS type request handler .
BP_ERROR_T BP_CSSStaticRequestHandler_require_valid_user
(
		void *                 request,
        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
)
{
	BP_HTTPD_ENTER_REQUEST_HANDLER;
	if(!request)
		return ERR_FAILURE;
	P_BP_HTTPD_REQUEST req = (P_BP_HTTPD_REQUEST) request;
	if(!req->httpd)
		return ERR_FAILURE;
	if(!connection)
		return ERR_FAILURE;
	if(!url)
		return ERR_FAILURE;
	if(!method)
		return ERR_FAILURE;
	if(!version)
		return ERR_FAILURE;
	P_BP_HTTPD_USER_SESSION session = (P_BP_HTTPD_USER_SESSION) req->session;
	if(!session)
	{
		BP_HTTPdRequestResponseSendLoginForm
		(
			req,
			connection,
			"login_header",
			"login_body",
			"login_footer"
		);
		return ERR_SUCCESS;
	}
	char * response_buff      = NULL;
	char * response_buff_b64  = NULL;
	size_t response_buff_size = 0;
	printf("\n [CSS] Getting here");
	if(req->request_handler->external_handler_parameter)
	{
		response_buff      = BP_FileGetContents((char *) req->request_handler->external_handler_parameter);
		response_buff_size = BP_FGetSize((char *) req->request_handler->external_handler_parameter);
		printf("\n[CSS] Got response param: %s - %p - %u", req->request_handler->external_handler_parameter, response_buff, response_buff_size);
	}
	else
	{
		printf("\n [CSS] FAILING?!!!!");
		return ERR_FAILURE;
	}
	if(!response_buff)
	{
		return ERR_SUCCESS;
	}
	BP_HTTPdRequestAppendBinaryBuffer
	(
			req,
			response_buff,
			response_buff_size
	);
	char content_length_str[128];
	BP_ZERO_STACK(content_length_str);
	sprintf(content_length_str, "%u", response_buff_size);
	printf("\n [CSS] Got Response Buffer Size?: %u", response_buff_size);
	BP_HTTPdAddExtraResponseHeaderToRequest(req,"content-length",	content_length_str);
	BP_HTTPdAddExtraResponseHeaderToRequest(req,"content-type",	"text/css; charset=utf-8");
	BP_HTTPdRequestResponseSendPrepared
	(
		req,
		connection,
		BP_HTTPD_RESPONSE_CODE_200_OK
	);
	bpfree((void *) response_buff);
	return ERR_SUCCESS;
}
BP_ERROR_T BP_CSSStaticRequestHandler_require_valid_user ( void * request , 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 ) { BP_HTTPD_ENTER_REQUEST_HANDLER ; if ( ! request ) return ERR_FAILURE ; P_BP_HTTPD_REQUEST req = ( P_BP_HTTPD_REQUEST ) request ; if ( ! req -> httpd ) return ERR_FAILURE ; if ( ! connection ) return ERR_FAILURE ; if ( ! url ) return ERR_FAILURE ; if ( ! method ) return ERR_FAILURE ; if ( ! version ) return ERR_FAILURE ; P_BP_HTTPD_USER_SESSION session = ( P_BP_HTTPD_USER_SESSION ) req -> session ; if ( ! session ) { BP_HTTPdRequestResponseSendLoginForm ( req , connection , " " , " " , " " ) ; return ERR_SUCCESS ; } char * response_buff = NULL ; char * response_buff_b64 = NULL ; size_t response_buff_size = 0 ; printf ( " \n " ) ; if ( req -> request_handler -> external_handler_parameter ) { response_buff = BP_FileGetContents ( ( char * ) req -> request_handler -> external_handler_parameter ) ; response_buff_size = BP_FGetSize ( ( char * ) req -> request_handler -> external_handler_parameter ) ; printf ( " \n " , req -> request_handler -> external_handler_parameter , response_buff , response_buff_size ) ; } else { printf ( " \n " ) ; return ERR_FAILURE ; } if ( ! response_buff ) { return ERR_SUCCESS ; } BP_HTTPdRequestAppendBinaryBuffer ( req , response_buff , response_buff_size ) ; char content_length_str [ 128 ] ; BP_ZERO_STACK ( content_length_str ) ; sprintf ( content_length_str , " " , response_buff_size ) ; printf ( " \n " , response_buff_size ) ; BP_HTTPdAddExtraResponseHeaderToRequest ( req , " " , content_length_str ) ; BP_HTTPdAddExtraResponseHeaderToRequest ( req , " " , " " ) ; BP_HTTPdRequestResponseSendPrepared ( req , connection , BP_HTTPD_RESPONSE_CODE_200_OK ) ; bpfree ( ( void * ) response_buff ) ; return ERR_SUCCESS ; }
This is the default CSS type request handler.
This is the default CSS type request handler .
// enter the request handler // ensure we have a passed in pointer // create req structure from void request pointer /* ensure we have a httpd to work with */ /* ensure we have a connection to work with */ /* ensure we have a url to work with */ /* ensure we have a method to work with */ /* ensure we have a version to work with */ // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% process authentication %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // session (filled dynamically) // if no session, go ahead and generate login form // send the login form // immediately exit after sending the login // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Generate Html Output %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // create an arbitrary response buffer // set response buffer // base64 encode value if we have a response buffer // if(response_buff && response_buff_size) // 	response_buff_b64 = BP_Base64Encode(response_buff, response_buff_size); // return indicating failure (should always have a buff) // ensure we hav a response buffer // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Create Response %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // set request response as binary buffer // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Add PNG Datatype %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // set content length // set the content length string // add content length header // add content type header // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Send Response %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // send the prepared response (along with cookie data) // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Destroy Relevant Data and Exit %%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // free the allocated buffer // return indicating success (request completed)