library/src/blockclass/BP-BlockClass.cc
// generate queries and search the database
generate queries and search the database
generate queries and search the database
size_t Block::searchNmapDb()
{
	if (!this->mysqlSession)
	{
		this->AddErrorToStack((char*) "Error in Block::searchNmapDb(): No MySQL connection for this block.");
		return ERR_FAILURE;
	}
	BP_BLOCK_MARIADB_ENTER_CRITICAL_SECTION;
	BP_NMAPDB_PORTSTATS portstats_empty = { 0 };
	BP_NMAPDB_HOSTSTATS hoststats_empty = { 0 };
	BP_NMAPDB_TARGETS targets_empty     = { 0 };
	BP_NMAPDB_SCANNERS scanners_empty   = { 0 };
	BP_NMAPDB_RUNLIST runlist_empty     = { 0 };
	P_BP_NMAPDB_RESULTS portstats_results = NULL;
	if
	(
			memcmp(&this->portstats_min_s,   &portstats_empty, sizeof(portstats_empty)) ||
			memcmp(&this->portstats_max_s,   &portstats_empty, sizeof(portstats_empty)) ||
			memcmp(&this->portstats_like_s,  &portstats_empty, sizeof(portstats_empty)) ||
			memcmp(&this->portstats_equal_s, &portstats_empty, sizeof(portstats_empty))
	)
	{
		portstats_results = BP_NDBSearchPortStats
		(
			this->mysqlSession,
			&this->portstats_min_s,
			&this->portstats_max_s,
			&this->portstats_like_s,
			&this->portstats_equal_s,
			this->limitBottom,
			this->limitTop
		);
	}
	P_BP_NMAPDB_RESULTS hoststats_results = NULL;
	if
	(
			memcmp(&this->hoststats_min_s, &hoststats_empty, sizeof(hoststats_empty))  ||
			memcmp(&this->hoststats_max_s, &hoststats_empty, sizeof(hoststats_empty))  ||
			memcmp(&this->hoststats_like_s, &hoststats_empty, sizeof(hoststats_empty)) ||
			memcmp(&this->hoststats_equal_s, &hoststats_empty, sizeof(hoststats_empty))
	)
	{
		hoststats_results = BP_NDBSearchHostStats
		(
				this->mysqlSession,
				&this->hoststats_min_s,
				&this->hoststats_max_s,
				&this->hoststats_like_s,
				&this->hoststats_equal_s,
				this->limitBottom,
				this->limitTop
		);
	}
	P_BP_NMAPDB_RESULTS targets_results = NULL;
	if
	(
			memcmp(&this->targets_min_s,   &targets_empty, sizeof(targets_empty)) ||
			memcmp(&this->targets_max_s,   &targets_empty, sizeof(targets_empty)) ||
			memcmp(&this->targets_like_s,  &targets_empty, sizeof(targets_empty)) ||
			memcmp(&this->targets_equal_s, &targets_empty, sizeof(targets_empty))
	)
	{
		targets_results = BP_NDBSearchTargets
		(
				this->mysqlSession,
				&this->targets_min_s,
				&this->targets_max_s,
				&this->targets_like_s,
				&this->targets_equal_s,
				this->limitBottom,
				this->limitTop
		);
	}
	P_BP_NMAPDB_RESULTS scanners_results = NULL;
	if
	(
			memcmp(&this->scanners_min_s, &scanners_empty, sizeof(scanners_empty)) ||
			memcmp(&this->scanners_max_s, &scanners_empty, sizeof(scanners_empty)) ||
			memcmp(&this->scanners_like_s, &scanners_empty, sizeof(scanners_empty)) ||
			memcmp(&this->scanners_equal_s, &scanners_empty, sizeof(scanners_empty))
	)
	{
		hoststats_results = BP_NDBSearchScanners
		(
				this->mysqlSession,
				&this->scanners_min_s,
				&this->scanners_max_s,
				&this->scanners_like_s,
				&this->scanners_equal_s,
				this->limitBottom,
				this->limitTop
		);
	}
	P_BP_NMAPDB_RESULTS runlist_results = NULL;
	if
	(
			memcmp(&this->runlist_min_s, &runlist_empty, sizeof(runlist_empty)) ||
			memcmp(&this->runlist_max_s, &runlist_empty, sizeof(runlist_empty)) ||
			memcmp(&this->runlist_like_s, &runlist_empty, sizeof(runlist_empty)) ||
			memcmp(&this->runlist_equal_s, &runlist_empty, sizeof(runlist_empty))
	)
	{
		runlist_results = BP_NDBSearchRunlist
		(
				this->mysqlSession,
				&this->runlist_min_s,
				&this->runlist_max_s,
				&this->runlist_like_s,
				&this->runlist_equal_s,
				this->limitBottom,
				this->limitTop
		);
	}
	if (!this->nmapdb_results)
	{
		if
		(
				portstats_results ||
				hoststats_results ||
				targets_results   ||
				scanners_results  ||
				runlist_results
		)
		{
			this->nmapdb_results = (P_BP_NMAPDB_SEARCH_RESULTS) tq_calloc(this->tq, sizeof(BP_NMAPDB_SEARCH_RESULTS), 1, BPLN);
		}
	}
	if (this->nmapdb_results)
	{
		this->nmapdb_results->runlist   = runlist_results;
		this->nmapdb_results->scanners  = scanners_results;
		this->nmapdb_results->targets   = targets_results;
		this->nmapdb_results->hoststats = hoststats_results;
		this->nmapdb_results->portstats = portstats_results;
	}
	else
	{
		this->AddWarningToStack((char *) "Warning in Block::searchNmapDb(): Search returned 0 results.");
		BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_FAILURE);
	}
	BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_SUCCESS);
}
size_t Block :: searchNmapDb ( ) { if ( ! this -> mysqlSession ) { this -> AddErrorToStack ( ( char * ) " " ) ; return ERR_FAILURE ; } BP_BLOCK_MARIADB_ENTER_CRITICAL_SECTION ; BP_NMAPDB_PORTSTATS portstats_empty = { 0 } ; BP_NMAPDB_HOSTSTATS hoststats_empty = { 0 } ; BP_NMAPDB_TARGETS targets_empty = { 0 } ; BP_NMAPDB_SCANNERS scanners_empty = { 0 } ; BP_NMAPDB_RUNLIST runlist_empty = { 0 } ; P_BP_NMAPDB_RESULTS portstats_results = NULL ; if ( memcmp ( & this -> portstats_min_s , & portstats_empty , sizeof ( portstats_empty ) ) || memcmp ( & this -> portstats_max_s , & portstats_empty , sizeof ( portstats_empty ) ) || memcmp ( & this -> portstats_like_s , & portstats_empty , sizeof ( portstats_empty ) ) || memcmp ( & this -> portstats_equal_s , & portstats_empty , sizeof ( portstats_empty ) ) ) { portstats_results = BP_NDBSearchPortStats ( this -> mysqlSession , & this -> portstats_min_s , & this -> portstats_max_s , & this -> portstats_like_s , & this -> portstats_equal_s , this -> limitBottom , this -> limitTop ) ; } P_BP_NMAPDB_RESULTS hoststats_results = NULL ; if ( memcmp ( & this -> hoststats_min_s , & hoststats_empty , sizeof ( hoststats_empty ) ) || memcmp ( & this -> hoststats_max_s , & hoststats_empty , sizeof ( hoststats_empty ) ) || memcmp ( & this -> hoststats_like_s , & hoststats_empty , sizeof ( hoststats_empty ) ) || memcmp ( & this -> hoststats_equal_s , & hoststats_empty , sizeof ( hoststats_empty ) ) ) { hoststats_results = BP_NDBSearchHostStats ( this -> mysqlSession , & this -> hoststats_min_s , & this -> hoststats_max_s , & this -> hoststats_like_s , & this -> hoststats_equal_s , this -> limitBottom , this -> limitTop ) ; } P_BP_NMAPDB_RESULTS targets_results = NULL ; if ( memcmp ( & this -> targets_min_s , & targets_empty , sizeof ( targets_empty ) ) || memcmp ( & this -> targets_max_s , & targets_empty , sizeof ( targets_empty ) ) || memcmp ( & this -> targets_like_s , & targets_empty , sizeof ( targets_empty ) ) || memcmp ( & this -> targets_equal_s , & targets_empty , sizeof ( targets_empty ) ) ) { targets_results = BP_NDBSearchTargets ( this -> mysqlSession , & this -> targets_min_s , & this -> targets_max_s , & this -> targets_like_s , & this -> targets_equal_s , this -> limitBottom , this -> limitTop ) ; } P_BP_NMAPDB_RESULTS scanners_results = NULL ; if ( memcmp ( & this -> scanners_min_s , & scanners_empty , sizeof ( scanners_empty ) ) || memcmp ( & this -> scanners_max_s , & scanners_empty , sizeof ( scanners_empty ) ) || memcmp ( & this -> scanners_like_s , & scanners_empty , sizeof ( scanners_empty ) ) || memcmp ( & this -> scanners_equal_s , & scanners_empty , sizeof ( scanners_empty ) ) ) { hoststats_results = BP_NDBSearchScanners ( this -> mysqlSession , & this -> scanners_min_s , & this -> scanners_max_s , & this -> scanners_like_s , & this -> scanners_equal_s , this -> limitBottom , this -> limitTop ) ; } P_BP_NMAPDB_RESULTS runlist_results = NULL ; if ( memcmp ( & this -> runlist_min_s , & runlist_empty , sizeof ( runlist_empty ) ) || memcmp ( & this -> runlist_max_s , & runlist_empty , sizeof ( runlist_empty ) ) || memcmp ( & this -> runlist_like_s , & runlist_empty , sizeof ( runlist_empty ) ) || memcmp ( & this -> runlist_equal_s , & runlist_empty , sizeof ( runlist_empty ) ) ) { runlist_results = BP_NDBSearchRunlist ( this -> mysqlSession , & this -> runlist_min_s , & this -> runlist_max_s , & this -> runlist_like_s , & this -> runlist_equal_s , this -> limitBottom , this -> limitTop ) ; } if ( ! this -> nmapdb_results ) { if ( portstats_results || hoststats_results || targets_results || scanners_results || runlist_results ) { this -> nmapdb_results = ( P_BP_NMAPDB_SEARCH_RESULTS ) tq_calloc ( this -> tq , sizeof ( BP_NMAPDB_SEARCH_RESULTS ) , 1 , BPLN ) ; } } if ( this -> nmapdb_results ) { this -> nmapdb_results -> runlist = runlist_results ; this -> nmapdb_results -> scanners = scanners_results ; this -> nmapdb_results -> targets = targets_results ; this -> nmapdb_results -> hoststats = hoststats_results ; this -> nmapdb_results -> portstats = portstats_results ; } else { this -> AddWarningToStack ( ( char * ) " " ) ; BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_FAILURE ) ; } BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_SUCCESS ) ; }
generate queries and search the database
generate queries and search the database
// check mysql session // enter critical section // create empty compare structures // check portstats to see if the user specified they want to search through them // search port data around our settings // check hoststats to see if the user specified they want to search through them // search port data around our settings // check targets to see if the user specified they want to search through them // search targets around our settings // check scanners to see if the user specified they want to search through them // search scanners around our settings // check runlist to see if the user specified they want to search through them // search port data around our settings // --------------------------------------------------------------------------- // allocate dbresults structure if non-allocated, reuse if it is allocated // set database pointers in structures // return indicating success