library/src/network/httpd/BP-HTTPdSessions.cc
// Retrieves a valid user if a valid api key is matched
Retrieves a valid user if a valid api key is matched
Retrieves a valid user if a valid api key is matched
P_BP_HTTPD_USER_SESSION BP_HTTPdSessionAuthUserFromAPIKey
(
	P_BP_HTTPD_SESSION httpd,
	char * api_key
)
{
	if(!httpd)
		return NULL;
	if(!httpd->system_hreg)
		return NULL;
	BP_HTTPD_ENTER_CRITICAL_SECTION;
	P_BP_HTTPD_API_KEY api_key_lookup = BP_HTTPdSessionLookupAPIKeyByIdentifier(httpd, api_key);
	if(!api_key_lookup)
		BP_HTTPD_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(NULL);
	if(!api_key_lookup->user_session)
		BP_HTTPD_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(NULL);
	P_BP_HTTPD_USER_SESSION session_lookup = (P_BP_HTTPD_USER_SESSION) api_key_lookup->user_session;
	if(!BP_HTTPdSessionExpired((P_BP_HTTPD_USER_SESSION) session_lookup))
	{
		BP_HTTPD_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC((P_BP_HTTPD_USER_SESSION) session_lookup);
	}
	BP_HTTPdSessionDestroy(httpd, (P_BP_HTTPD_USER_SESSION) session_lookup);
	session_lookup = NULL;
	BP_HTTPD_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(session_lookup);
}
P_BP_HTTPD_USER_SESSION BP_HTTPdSessionAuthUserFromAPIKey ( P_BP_HTTPD_SESSION httpd , char * api_key ) { if ( ! httpd ) return NULL ; if ( ! httpd -> system_hreg ) return NULL ; BP_HTTPD_ENTER_CRITICAL_SECTION ; P_BP_HTTPD_API_KEY api_key_lookup = BP_HTTPdSessionLookupAPIKeyByIdentifier ( httpd , api_key ) ; if ( ! api_key_lookup ) BP_HTTPD_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( NULL ) ; if ( ! api_key_lookup -> user_session ) BP_HTTPD_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( NULL ) ; P_BP_HTTPD_USER_SESSION session_lookup = ( P_BP_HTTPD_USER_SESSION ) api_key_lookup -> user_session ; if ( ! BP_HTTPdSessionExpired ( ( P_BP_HTTPD_USER_SESSION ) session_lookup ) ) { BP_HTTPD_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ( P_BP_HTTPD_USER_SESSION ) session_lookup ) ; } BP_HTTPdSessionDestroy ( httpd , ( P_BP_HTTPD_USER_SESSION ) session_lookup ) ; session_lookup = NULL ; BP_HTTPD_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( session_lookup ) ; }
Retrieves a valid user if a valid api key is matched
Retrieves a valid user if a valid api key is matched
// enter critical section // attempt to lookup the api key // set session lookup from api key // check if the session is expired // if the session isn't expired, return it // destroy the user session // set session ptr to null // return null if the session was expired