library/src/network/httpd/BP-HTTPdSessions.cc
// Adds one xsrf token to a user session.
Adds one xsrf token to a user session.
Adds one xsrf token to a user session .
BP_ERROR_T BP_HTTPdSessionXSRFTokenAdd
(
		P_BP_HTTPD_USER_SESSION user_session
)
{
	if(!user_session)
		return ERR_FAILURE;
	if(!user_session->xsrf_reg)
		return ERR_FAILURE;
	char *new_xsrf_token_uuid = BP_GenRandomUUID();
	P_BP_HTTPD_SESSION_XSRF_TOKEN lookup_token = BP_HTTPdSessionXSRFTokenLookup
	(
			user_session,
			new_xsrf_token_uuid
	);
	if(lookup_token)
	{
		bpfree(new_xsrf_token_uuid);
		return ERR_FAILURE;
	}
	char *new_xsrf_token_add_path[10];
	BP_ZERO_STACK(new_xsrf_token_add_path);
	new_xsrf_token_add_path[0] = "tokens";
	BP_HashRegAddDataToTableByPath
	(
			user_session->xsrf_reg,
			(char **) &new_xsrf_token_add_path,
			new_xsrf_token_uuid,
			BP_HASH_TABLE_KEYED_ENTRY_TYPE_BINARY_BLOB,
			NULL,
			sizeof(BP_HTTPD_SESSION_XSRF_TOKEN)
	);
	P_BP_HASH_TABLE_KEYED_ENTRY table_entry_lookup = BP_HashRegLookupTableEntryByPath(user_session->xsrf_reg, (char **) &new_xsrf_token_add_path);
	if(!table_entry_lookup)
	{
		bpfree(new_xsrf_token_uuid);
		return ERR_FAILURE;
	}
	P_BP_HTTPD_SESSION_XSRF_TOKEN new_xsrf_token = (P_BP_HTTPD_SESSION_XSRF_TOKEN) table_entry_lookup->data;
	new_xsrf_token->token = (char *) ht_strdup(user_session->xsrf_reg, new_xsrf_token_uuid);
	bpfree(new_xsrf_token_uuid);
	return ERR_SUCCESS;
}
BP_ERROR_T BP_HTTPdSessionXSRFTokenAdd ( P_BP_HTTPD_USER_SESSION user_session ) { if ( ! user_session ) return ERR_FAILURE ; if ( ! user_session -> xsrf_reg ) return ERR_FAILURE ; char * new_xsrf_token_uuid = BP_GenRandomUUID ( ) ; P_BP_HTTPD_SESSION_XSRF_TOKEN lookup_token = BP_HTTPdSessionXSRFTokenLookup ( user_session , new_xsrf_token_uuid ) ; if ( lookup_token ) { bpfree ( new_xsrf_token_uuid ) ; return ERR_FAILURE ; } char * new_xsrf_token_add_path [ 10 ] ; BP_ZERO_STACK ( new_xsrf_token_add_path ) ; new_xsrf_token_add_path [ 0 ] = " " ; BP_HashRegAddDataToTableByPath ( user_session -> xsrf_reg , ( char * * ) & new_xsrf_token_add_path , new_xsrf_token_uuid , BP_HASH_TABLE_KEYED_ENTRY_TYPE_BINARY_BLOB , NULL , sizeof ( BP_HTTPD_SESSION_XSRF_TOKEN ) ) ; P_BP_HASH_TABLE_KEYED_ENTRY table_entry_lookup = BP_HashRegLookupTableEntryByPath ( user_session -> xsrf_reg , ( char * * ) & new_xsrf_token_add_path ) ; if ( ! table_entry_lookup ) { bpfree ( new_xsrf_token_uuid ) ; return ERR_FAILURE ; } P_BP_HTTPD_SESSION_XSRF_TOKEN new_xsrf_token = ( P_BP_HTTPD_SESSION_XSRF_TOKEN ) table_entry_lookup -> data ; new_xsrf_token -> token = ( char * ) ht_strdup ( user_session -> xsrf_reg , new_xsrf_token_uuid ) ; bpfree ( new_xsrf_token_uuid ) ; return ERR_SUCCESS ; }
Adds one xsrf token to a user session.
Adds one xsrf token to a user session .
// ensure we have a user session and a xsrf_registry // generate a new xsrf token // attempt lookup to ensure xsrf token doesn't already exist // ensure the token doesn't already exist // xsrf_tokens // set path for lookup // new_xsrf_token_add_path[1] = new_xsrf_token_uuid; // attempt to add new BP_HTTPD_SESSION_XSRF_TOKEN structure to the table using the uuid for a name // attempt to lookup table entry after addition // return indicating failure // set xsrf token from lookup // duplicate token // destroy token uuid // return indicating success