library/src/databases/bpdb/BP-DB.cc
// adds a mariadb connection to the pool of available connections
adds a mariadb connection to the pool of available connections
adds a mariadb connection to the pool of available connections
BP_ERROR_T BP_DBAddMariadbConnectionToPool(P_BPDB bpdb, P_BP_MYSQL_SESSION mariadbi)
{
	if(!bpdb)
		return ERR_FAILURE;
	if(!bpdb->system_hreg)
		return ERR_FAILURE;
	BPDB_ENTER_CRITICAL_SECTION;
	if(BP_DBLookupMariadbConnectionByUUID(bpdb, mariadbi->uuid))
	{
		BP_DBAddErrorMsg(bpdb, "BP_DBLookupMariadbConnectionByUUID failed while attempting BP_DBAddMariadbConnectionToPool.");
		BPDB_LEAVE_CRITICAL_SECTION_AND_RETURN(ERR_FAILURE);
	}
	printf("\n [+] Adding maraidb connection to connection pool: %s", mariadbi->uuid);
	if(
		!BP_HashRegAddDataToTableByPathQuery
		(
				bpdb->system_hreg,
				"/mariadb_connections",
				mariadbi->uuid,
				BP_HASH_TABLE_KEYED_ENTRY_TYPE_BINARY_BLOB,
				NULL,
				sizeof(BP_MYSQL_SESSION *)
		)
	)
	{
		BP_DBAddErrorMsg(bpdb, "BP_HashRegAddDataToTableByPathQuery failed while attempting BP_DBAddMariadbConnectionToPool.");
		BPDB_LEAVE_CRITICAL_SECTION_AND_RETURN(ERR_FAILURE);
	}
	char * connection_lookup_path[] =
	{
		"mariadb_connections",
		mariadbi->uuid,
		NULL
	};
	P_BP_HASH_TABLE_KEYED_ENTRY connection_entry = BP_HashRegLookupTableEntryByPath(bpdb->system_hreg, (char **) &connection_lookup_path);
	if(!connection_entry)
	{
		BP_DBAddErrorMsg(bpdb, "BP_HashRegLookupTableEntryByPath failed while attempting BP_DBAddMariadbConnectionToPool.");
		BPDB_LEAVE_CRITICAL_SECTION_AND_RETURN(ERR_FAILURE);
	}
	memcpy(connection_entry->data, &mariadbi, sizeof(BP_MYSQL_SESSION *));
	P_BP_MYSQL_SESSION mysqli_session = BP_DBLookupMariadbConnectionByUUID(bpdb, mariadbi->uuid);
	mysqli_session->pool_available = BP_TRUE;
	BPDB_LEAVE_CRITICAL_SECTION_AND_RETURN(ERR_SUCCESS);
}
BP_ERROR_T BP_DBAddMariadbConnectionToPool ( P_BPDB bpdb , P_BP_MYSQL_SESSION mariadbi ) { if ( ! bpdb ) return ERR_FAILURE ; if ( ! bpdb -> system_hreg ) return ERR_FAILURE ; BPDB_ENTER_CRITICAL_SECTION ; if ( BP_DBLookupMariadbConnectionByUUID ( bpdb , mariadbi -> uuid ) ) { BP_DBAddErrorMsg ( bpdb , " " ) ; BPDB_LEAVE_CRITICAL_SECTION_AND_RETURN ( ERR_FAILURE ) ; } printf ( " \n " , mariadbi -> uuid ) ; if ( ! BP_HashRegAddDataToTableByPathQuery ( bpdb -> system_hreg , " " , mariadbi -> uuid , BP_HASH_TABLE_KEYED_ENTRY_TYPE_BINARY_BLOB , NULL , sizeof ( BP_MYSQL_SESSION * ) ) ) { BP_DBAddErrorMsg ( bpdb , " " ) ; BPDB_LEAVE_CRITICAL_SECTION_AND_RETURN ( ERR_FAILURE ) ; } char * connection_lookup_path [ ] = { " " , mariadbi -> uuid , NULL } ; P_BP_HASH_TABLE_KEYED_ENTRY connection_entry = BP_HashRegLookupTableEntryByPath ( bpdb -> system_hreg , ( char * * ) & connection_lookup_path ) ; if ( ! connection_entry ) { BP_DBAddErrorMsg ( bpdb , " " ) ; BPDB_LEAVE_CRITICAL_SECTION_AND_RETURN ( ERR_FAILURE ) ; } memcpy ( connection_entry -> data , & mariadbi , sizeof ( BP_MYSQL_SESSION * ) ) ; P_BP_MYSQL_SESSION mysqli_session = BP_DBLookupMariadbConnectionByUUID ( bpdb , mariadbi -> uuid ) ; mysqli_session -> pool_available = BP_TRUE ; BPDB_LEAVE_CRITICAL_SECTION_AND_RETURN ( ERR_SUCCESS ) ; }
adds a mariadb connection to the pool of available connections
adds a mariadb connection to the pool of available connections
// return indicating failure // enter critical section // lookup connection by uuid // display addition message // add space for entry // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Lookup Entry After Creation %%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // set connection lookup path // attempt to lookup the connection entry // copy in the new connection entry addr (POINTER ONLY) // lookup mysqli session // mark the session as pool available after addition // return indicating success