library/src/network/httpd/BP-HTTPdDefaultCallbacks.cc
// This is the default post iterator callback that gets called
// when processing http post data with the default access handler.
This is the default post iterator callback that gets called
when processing http post data with the default access handler.
This is the default post iterator callback that gets called when processing http post data with the default access handler .
int BP_HTTPdDefaultPostIteratorCallback
(
		void *cls,
		enum MHD_ValueKind kind,
		const char * key,
		const char * filename,
		const char * content_type,
		const char * transfer_encoding,
		const char * data,
		uint64_t off,
		size_t size
)
{
	if(!cls)
		return MHD_YES;
	P_BP_HTTPD_REQUEST request = (P_BP_HTTPD_REQUEST) cls;
	if(!key)
		return MHD_YES;
	if(!BP_StringIsReasonablePrintableString((char *) key, bpstrlen((char *) key), BP_FALSE, BP_FALSE))
		return MHD_YES;
	if(off && !size)
	{
		request->post_processing_completed = BP_TRUE;
		return MHD_YES;
	}
	if(!request->post_processing_started)
		request->post_processing_started = BP_TRUE;
	%%%
	%%%
	BP_HTTPD_REQUEST_CONTENT_TYPE content_type_id = BP_HTTPdRequestGetContentType((char *) content_type);
	P_BP_HTTPD_REQUEST_VAR var = (P_BP_HTTPD_REQUEST_VAR) NULL;
	switch(content_type_id)
	{
		case BP_HTTPD_REQUEST_CONTENT_TYPE_APPLICATION_OCTET_STREAM:
			if(request->request_handler->use_tmpfile_for_multipart_form_data)
			{
				var = BP_HTTPdRequestVarArgRegistryLookup(request, BP_HTTPD_REQUEST_VAR_TYPE_POST_TMPFILE, (char *) key);
				if(var)
					break;
				char new_tmp_uuid[BP_UUID_LEN+5];
				BP_ZERO_STACK(new_tmp_uuid);
				BP_GenRandomUUID_StoreInBuff((char *) &new_tmp_uuid);
				char * path_elems[] =
				{
					request->request_handler->posted_data_tmp_directory_literal_path,
					new_tmp_uuid,
					"-XXXXXX"
				};
				char * file_path = BP_JoinStringArray((char **) &path_elems, 3, NULL);
				BP_ERROR_T retstatus = BP_HTTPdRequestVarAddToArgRegistry
				(
					request,
					BP_HTTPD_REQUEST_VAR_TYPE_POST_TMPFILE,
					content_type_id,
					(char *) key,
					NULL,
					file_path,
					0
				);
				if(retstatus == ERR_FAILURE)
				{
					return MHD_YES;
				}
				var = BP_HTTPdRequestVarArgRegistryLookup(request, BP_HTTPD_REQUEST_VAR_TYPE_POST_TMPFILE, (char *) key);
			}
			else
			{
				BP_ERROR_T retstatus = BP_HTTPdRequestVarAddToArgRegistry
				(
					request,
					BP_HTTPD_REQUEST_VAR_TYPE_POST_DATA,
					content_type_id,
					(char *) key,
					NULL,
					NULL,
					0
				);
				if(retstatus == ERR_FAILURE)
				{
					return MHD_YES;
				}
				var = BP_HTTPdRequestVarArgRegistryLookup(request, BP_HTTPD_REQUEST_VAR_TYPE_POST_DATA, (char *) key);
			}
			break;
		case BP_HTTPD_REQUEST_CONTENT_TYPE_MULTIPART_FORM_DATA:
			if(request->request_handler->use_tmpfile_for_multipart_form_data)
			{
				var = BP_HTTPdRequestVarArgRegistryLookup(request, BP_HTTPD_REQUEST_VAR_TYPE_POST_TMPFILE, (char *) key);
				if(var)
					break;
				char new_tmp_uuid[BP_UUID_LEN+5];
				BP_ZERO_STACK(new_tmp_uuid);
				BP_GenRandomUUID_StoreInBuff((char *) &new_tmp_uuid);
				char * path_elems[] =
				{
					request->request_handler->posted_data_tmp_directory_literal_path,
					new_tmp_uuid,
					"-XXXXXX"
				};
				char * file_path = BP_JoinStringArray((char **) &path_elems, 3, NULL);
				BP_ERROR_T retstatus = BP_HTTPdRequestVarAddToArgRegistry
				(
					request,
					BP_HTTPD_REQUEST_VAR_TYPE_POST_DATA,
					content_type_id,
					(char *) key,
					NULL,
					file_path,
					0
				);
				if(retstatus == ERR_FAILURE)
				{
					return MHD_YES;
				}
				var = BP_HTTPdRequestVarArgRegistryLookup(request, BP_HTTPD_REQUEST_VAR_TYPE_POST_DATA, (char *) key);
			}
			else
			{
				BP_ERROR_T retstatus = BP_HTTPdRequestVarAddToArgRegistry
				(
					request,
					BP_HTTPD_REQUEST_VAR_TYPE_POST_DATA,
					content_type_id,
					(char *) key,
					NULL,
					NULL,
					0
				);
				if(retstatus == ERR_FAILURE)
				{
					return MHD_YES;
				}
				var = BP_HTTPdRequestVarArgRegistryLookup(request, BP_HTTPD_REQUEST_VAR_TYPE_POST_DATA, (char *) key);
			}
			break;
		case BP_HTTPD_REQUEST_CONTENT_TYPE_APPLICATION_X_WWW_FORM_URLENCODED:
			{
				BP_ERROR_T retstatus = BP_HTTPdRequestVarAddToArgRegistry
				(
					request,
					BP_HTTPD_REQUEST_VAR_TYPE_POST_DATA,
					content_type_id,
					(char *) key,
					NULL,
					NULL,
					0
				);
				if(retstatus == ERR_FAILURE)
				{
					return MHD_YES;
				}
				var = BP_HTTPdRequestVarArgRegistryLookup(request, BP_HTTPD_REQUEST_VAR_TYPE_POST_DATA, (char *) key);
			}
			break;
		default:
			content_type_id = BP_HTTPD_REQUEST_CONTENT_TYPE_APPLICATION_X_WWW_FORM_URLENCODED;
			{
				BP_ERROR_T retstatus = BP_HTTPdRequestVarAddToArgRegistry
				(
					request,
					BP_HTTPD_REQUEST_VAR_TYPE_POST_DATA,
					content_type_id,
					(char *) key,
					NULL,
					NULL,
					0
				);
				if(retstatus == ERR_FAILURE)
				{
					return MHD_YES;
				}
				var = BP_HTTPdRequestVarArgRegistryLookup(request, BP_HTTPD_REQUEST_VAR_TYPE_POST_DATA, (char *) key);
			}
			break;
	}
	%%%%%%%%%
	%%%%%%%%%
	if(!var)
		return MHD_YES;
	request->internal_last_request_var_processed = (void *) var;
	BP_HTTPdRequestVarAppendData
	(
			request,
			var,
			(char *) data,
			size
	);
	%%%%%%
	%%%%%%
	return MHD_YES;
}
int BP_HTTPdDefaultPostIteratorCallback ( void * cls , enum MHD_ValueKind kind , const char * key , const char * filename , const char * content_type , const char * transfer_encoding , const char * data , uint64_t off , size_t size ) { if ( ! cls ) return MHD_YES ; P_BP_HTTPD_REQUEST request = ( P_BP_HTTPD_REQUEST ) cls ; if ( ! key ) return MHD_YES ; if ( ! BP_StringIsReasonablePrintableString ( ( char * ) key , bpstrlen ( ( char * ) key ) , BP_FALSE , BP_FALSE ) ) return MHD_YES ; if ( off && ! size ) { request -> post_processing_completed = BP_TRUE ; return MHD_YES ; } if ( ! request -> post_processing_started ) request -> post_processing_started = BP_TRUE ; BP_HTTPD_REQUEST_CONTENT_TYPE content_type_id = BP_HTTPdRequestGetContentType ( ( char * ) content_type ) ; P_BP_HTTPD_REQUEST_VAR var = ( P_BP_HTTPD_REQUEST_VAR ) NULL ; switch ( content_type_id ) { case BP_HTTPD_REQUEST_CONTENT_TYPE_APPLICATION_OCTET_STREAM : if ( request -> request_handler -> use_tmpfile_for_multipart_form_data ) { var = BP_HTTPdRequestVarArgRegistryLookup ( request , BP_HTTPD_REQUEST_VAR_TYPE_POST_TMPFILE , ( char * ) key ) ; if ( var ) break ; char new_tmp_uuid [ BP_UUID_LEN + 5 ] ; BP_ZERO_STACK ( new_tmp_uuid ) ; BP_GenRandomUUID_StoreInBuff ( ( char * ) & new_tmp_uuid ) ; char * path_elems [ ] = { request -> request_handler -> posted_data_tmp_directory_literal_path , new_tmp_uuid , " " } ; char * file_path = BP_JoinStringArray ( ( char * * ) & path_elems , 3 , NULL ) ; BP_ERROR_T retstatus = BP_HTTPdRequestVarAddToArgRegistry ( request , BP_HTTPD_REQUEST_VAR_TYPE_POST_TMPFILE , content_type_id , ( char * ) key , NULL , file_path , 0 ) ; if ( retstatus == ERR_FAILURE ) { return MHD_YES ; } var = BP_HTTPdRequestVarArgRegistryLookup ( request , BP_HTTPD_REQUEST_VAR_TYPE_POST_TMPFILE , ( char * ) key ) ; } else { BP_ERROR_T retstatus = BP_HTTPdRequestVarAddToArgRegistry ( request , BP_HTTPD_REQUEST_VAR_TYPE_POST_DATA , content_type_id , ( char * ) key , NULL , NULL , 0 ) ; if ( retstatus == ERR_FAILURE ) { return MHD_YES ; } var = BP_HTTPdRequestVarArgRegistryLookup ( request , BP_HTTPD_REQUEST_VAR_TYPE_POST_DATA , ( char * ) key ) ; } break ; case BP_HTTPD_REQUEST_CONTENT_TYPE_MULTIPART_FORM_DATA : if ( request -> request_handler -> use_tmpfile_for_multipart_form_data ) { var = BP_HTTPdRequestVarArgRegistryLookup ( request , BP_HTTPD_REQUEST_VAR_TYPE_POST_TMPFILE , ( char * ) key ) ; if ( var ) break ; char new_tmp_uuid [ BP_UUID_LEN + 5 ] ; BP_ZERO_STACK ( new_tmp_uuid ) ; BP_GenRandomUUID_StoreInBuff ( ( char * ) & new_tmp_uuid ) ; char * path_elems [ ] = { request -> request_handler -> posted_data_tmp_directory_literal_path , new_tmp_uuid , " " } ; char * file_path = BP_JoinStringArray ( ( char * * ) & path_elems , 3 , NULL ) ; BP_ERROR_T retstatus = BP_HTTPdRequestVarAddToArgRegistry ( request , BP_HTTPD_REQUEST_VAR_TYPE_POST_DATA , content_type_id , ( char * ) key , NULL , file_path , 0 ) ; if ( retstatus == ERR_FAILURE ) { return MHD_YES ; } var = BP_HTTPdRequestVarArgRegistryLookup ( request , BP_HTTPD_REQUEST_VAR_TYPE_POST_DATA , ( char * ) key ) ; } else { BP_ERROR_T retstatus = BP_HTTPdRequestVarAddToArgRegistry ( request , BP_HTTPD_REQUEST_VAR_TYPE_POST_DATA , content_type_id , ( char * ) key , NULL , NULL , 0 ) ; if ( retstatus == ERR_FAILURE ) { return MHD_YES ; } var = BP_HTTPdRequestVarArgRegistryLookup ( request , BP_HTTPD_REQUEST_VAR_TYPE_POST_DATA , ( char * ) key ) ; } break ; case BP_HTTPD_REQUEST_CONTENT_TYPE_APPLICATION_X_WWW_FORM_URLENCODED : { BP_ERROR_T retstatus = BP_HTTPdRequestVarAddToArgRegistry ( request , BP_HTTPD_REQUEST_VAR_TYPE_POST_DATA , content_type_id , ( char * ) key , NULL , NULL , 0 ) ; if ( retstatus == ERR_FAILURE ) { return MHD_YES ; } var = BP_HTTPdRequestVarArgRegistryLookup ( request , BP_HTTPD_REQUEST_VAR_TYPE_POST_DATA , ( char * ) key ) ; } break ; default : content_type_id = BP_HTTPD_REQUEST_CONTENT_TYPE_APPLICATION_X_WWW_FORM_URLENCODED ; { BP_ERROR_T retstatus = BP_HTTPdRequestVarAddToArgRegistry ( request , BP_HTTPD_REQUEST_VAR_TYPE_POST_DATA , content_type_id , ( char * ) key , NULL , NULL , 0 ) ; if ( retstatus == ERR_FAILURE ) { return MHD_YES ; } var = BP_HTTPdRequestVarArgRegistryLookup ( request , BP_HTTPD_REQUEST_VAR_TYPE_POST_DATA , ( char * ) key ) ; } break ; } if ( ! var ) return MHD_YES ; request -> internal_last_request_var_processed = ( void * ) var ; BP_HTTPdRequestVarAppendData ( request , var , ( char * ) data , size ) ; return MHD_YES ; }
This is the default post iterator callback that gets called
when processing http post data with the default access handler.
This is the default post iterator callback that gets called when processing http post data with the default access handler .
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Preliminary Data Checks %%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // ensure we have a request parameter // get request from cls // ensure we have a key to work with // ensure key is reasonable/printable // mark the post processing as completed ok // printf("\n EXITING AT SIZE!"); // DO NOT exit immediately if we have our size DO NOT UNCOMMENT.  We need // to close the file handle below if the size is zero, so we can't just // exclude it here. // if(!size) // { // 	return MHD_YES; // } // set the post processor as started // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Process Post Var Types Based on Content Type %%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // get the encoded content type // create initial var // switch on the encoding type // octet streams are people uploading files // if we can't look it up, create it // if we can look up our var as a post tmpfile // create new tmp uuid // generate new random uuid // set path elements for new temp file // generate the temp filepath template // attempt to add variable to argument registry as new file path type // check that the variable was added to the registry // printf("\n Failed to add var to registry."); // attempt lookup after add to ensure it's there // attempt to add variable to argument registry as new file path type // check that the variable was added to the registry // printf("\n Failed to add var to registry."); // attempt lookup after add to ensure it's there // exit switch // attempt to create a new form post // attempt to create a tmpfile type for posted data // if we can look up our var as a post tmpfile // create new tmp uuid // generate new random uuid // set path elements for new temp file // generate the temp filepath template // attempt to add variable to argument registry as new file path type // ensure the variable can be added successfully // printf("\n Failed to add var to registry."); // attempt lookup after add to ensure it's there // attempt to add variable to argument registry as new file path type // check that the variable was added to the registry // printf("\n Failed to add var to registry."); // attempt lookup after add to ensure it's there // attempt to add variable to argument registry as new file path type // check that the variable was added to the registry // printf("\n Failed to add var to registry."); // attempt lookup after add to ensure it's there // set default content type as urlencoded form // attempt to add variable to argument registry as new file path type // check that the variable was added to the registry // printf("\n Failed to add var to registry."); // attempt lookup after add to ensure it's there // printf("\n Running default variable addition11111?: %p", var); // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Add Data to Posted Vars %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // we should have a var at all times at this point // save last processed var here // append data to the created variable here.  If the variable type is specified // as a file or data type, either will be selected and data will added either // in memory, or as a file.  This selected behavior is determined when you create // a HTTPd Request Handler. // display the registry // BP_HashRegDisplay(request->arg_hreg, BP_FALSE, BP_TRUE); /*
	// Adds a variable to the registry according to type.
	BP_ERROR_T BP_HTTPdRequestVarAddToArgRegistry
	(
			P_BP_HTTPD_REQUEST             request,
			BP_HTTPD_REQUEST_VAR_TYPE      type,
			encoding,
			key,
			char *                         data,
			char *                         data_file,
			size_t                         data_size
	)
	*/ // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Handle Post Type %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // handle post data type //if(request->post_data_is_file) //{ /*
		// zero out data
		char * data_out = (char *) NULL;
		if(size)
		{
			data_out = (char *) bpcalloc(size+1, 1);
			memcpy(data_out, data, size);
		}

		printf("\n -> key:               %s", key);
		printf("\n -> filename:          %s", filename);
		printf("\n -> content_type:      %s", content_type);
		printf("\n -> transfer_encoding: %s", transfer_encoding);
		printf("\n -> data:              %s", data_out);
		printf("\n -> off:               %u", off);
		printf("\n -> size:              %u", size);
		printf("\n");

		// destroy alloced buffer if necessary
		if(data_out)
			bpfree(data_out);
		*/ //} // printf("\n EXITING AT END?!"); // return indicating success