library/src/network/httpd/BP-HTTPdWebSocketRequestHandlers.cc
// Decode frame data using a frame header.
Decode frame data using a frame header.
Decode frame data using a frame header .
BP_ERROR_T BP_HTTPdWebsocketDecodeFrameData
(
		P_BP_HTTPD_WEBSOCKET_DECODED_RECV_FRAME_HEADER frame_header,
		unsigned char                                 *data,
		size_t                                         data_len,
		P_BP_LINKL                                     data_aggregate_tq
)
{
	if(!frame_header)
		return ERR_FAILURE;
	if(!data)
		return ERR_FAILURE;
	if(!data_len)
		return ERR_FAILURE;
	if(!frame_header->decoded_ok)
	{
		printf("\n Could not decode due to header not decoded ok");
		return ERR_FAILURE;
	}
	if(!data_aggregate_tq)
	{
		printf("\n Could not decode due to missing data aggregator");
		return ERR_FAILURE;
	}
	size_t n = 0;
	for(n = 0; n < data_len; n++)
	{
		data[n] = data[n] ^ frame_header->masking_key[frame_header->last_decode_byte_idx % 4];
		frame_header->last_decode_byte_idx++;
	}
	void *tmp_data_bucket = tq_malloc(data_aggregate_tq, data_len, BPLN);
	memcpy(tmp_data_bucket, data, data_len);
	frame_header->payload_bytes_read += data_len;
	frame_header->payload_bytes_remaining_for_read = frame_header->payload_len - frame_header->payload_bytes_read;
	frame_header->last_payload_decode_data_len = data_len;
	if(frame_header->payload_bytes_read == frame_header->payload_len)
	{
		frame_header->payload_finished_reading = BP_TRUE;
	}
	return ERR_SUCCESS;
}
BP_ERROR_T BP_HTTPdWebsocketDecodeFrameData ( P_BP_HTTPD_WEBSOCKET_DECODED_RECV_FRAME_HEADER frame_header , unsigned char * data , size_t data_len , P_BP_LINKL data_aggregate_tq ) { if ( ! frame_header ) return ERR_FAILURE ; if ( ! data ) return ERR_FAILURE ; if ( ! data_len ) return ERR_FAILURE ; if ( ! frame_header -> decoded_ok ) { printf ( " \n " ) ; return ERR_FAILURE ; } if ( ! data_aggregate_tq ) { printf ( " \n " ) ; return ERR_FAILURE ; } size_t n = 0 ; for ( n = 0 ; n < data_len ; n ++ ) { data [ n ] = data [ n ] ^ frame_header -> masking_key [ frame_header -> last_decode_byte_idx % 4 ] ; frame_header -> last_decode_byte_idx ++ ; } void * tmp_data_bucket = tq_malloc ( data_aggregate_tq , data_len , BPLN ) ; memcpy ( tmp_data_bucket , data , data_len ) ; frame_header -> payload_bytes_read += data_len ; frame_header -> payload_bytes_remaining_for_read = frame_header -> payload_len - frame_header -> payload_bytes_read ; frame_header -> last_payload_decode_data_len = data_len ; if ( frame_header -> payload_bytes_read == frame_header -> payload_len ) { frame_header -> payload_finished_reading = BP_TRUE ; } return ERR_SUCCESS ; }
Decode frame data using a frame header.
Decode frame data using a frame header .
// basic parameter checks // iterate through data // perform decryption // increment the decode byte index (this will be preserved throughout the full decode) // allocate data bucket // copy in the data // add data length read // bytes remaining for read // mark the last decode length // set marker if we completed our read // return indicating success