library/src/network/httpd/BP-HTTPdRequests.cc
// Appends data to an existing request variable.  This is primarily used
// during the post processor.
Appends data to an existing request variable.  This is primarily used
during the post processor.
Appends data to an existing request variable . This is primarily used during the post processor .
BP_ERROR_T BP_HTTPdRequestVarAppendData
(
		P_BP_HTTPD_REQUEST             request,
		P_BP_HTTPD_REQUEST_VAR         var,
		char *                         data,
		size_t                         data_size
)
{
	if(!request)
		return ERR_FAILURE;
	if(!var)
		return ERR_FAILURE;
	if(var->data_file)
	{
		if(data && data_size)
		{
			if(var->file_descriptor == -1)
				return ERR_FAILURE;
			BP_FDWrite(var->file_descriptor, (char *) data, data_size);
			BP_FDFlush(var->file_descriptor);
			var->file_handle_data_written += data_size;
			var->content_stored_in_file = BP_TRUE;
		}
	}
	else
	{
		if(data && data_size)
		{
			var->data = (char *) bprealloc((void *) var->data, (var->data_size + data_size));
			if(!var->data)
				return ERR_FAILURE;
			if(var->data)
			{
				memcpy(&var->data[var->data_size], data, data_size);
				var->data_size += data_size;
			}
		}
	}
	return ERR_SUCCESS;
}
BP_ERROR_T BP_HTTPdRequestVarAppendData ( P_BP_HTTPD_REQUEST request , P_BP_HTTPD_REQUEST_VAR var , char * data , size_t data_size ) { if ( ! request ) return ERR_FAILURE ; if ( ! var ) return ERR_FAILURE ; if ( var -> data_file ) { if ( data && data_size ) { if ( var -> file_descriptor == -1 ) return ERR_FAILURE ; BP_FDWrite ( var -> file_descriptor , ( char * ) data , data_size ) ; BP_FDFlush ( var -> file_descriptor ) ; var -> file_handle_data_written += data_size ; var -> content_stored_in_file = BP_TRUE ; } } else { if ( data && data_size ) { var -> data = ( char * ) bprealloc ( ( void * ) var -> data , ( var -> data_size + data_size ) ) ; if ( ! var -> data ) return ERR_FAILURE ; if ( var -> data ) { memcpy ( & var -> data [ var -> data_size ] , data , data_size ) ; var -> data_size += data_size ; } } } return ERR_SUCCESS ; }
Appends data to an existing request variable.
Appends data to an existing request variable .
// enusre we have a request (unnecessary, but kept here in case we // want to add cross features between request and var structs) // ensure we have a var // open the file if necessary // if we have data, open file and append // ensure we can open it // write data to file (append) // flush data to file // increment the size by the current write portion // set the storage flag to true if we write any data ever // if we have data, alloc and copy // attempt attempt block reallocation to the correct size (or init with initial size) // if the data was allocated, copy it in // copy in the data // set data size only if we make a copy // return indicating success