library/src/blockclass/BP-BlockClass.cc
// save class this->bing_session results to database (requires above table installed on current database)
save class this->bing_session results to database (requires above table installed on current database)
save class this - > bing_session results to database ( requires above table installed on current database )
BP_ERROR_T Block::saveBingResults() {
	if (!this->bing_session)
		return ERR_FAILURE;
	if (!this->mysqlSession)
		return ERR_FAILURE;
	BP_BLOCK_MARIADB_ENTER_CRITICAL_SECTION;
	char * select_query = (char *) "SELECT `id` from `results` WHERE `href` = ? LIMIT 0, 1";
	char * insert_query = (char *) "INSERT INTO `results` (  `type` , `sha1`,`href` , `status` , `commit_timestamp`, `audit_start_timestamp`, `audit_completed_timestamp` ) VALUES (  ?, SHA1(?), ?, ?, NOW(), '0000-00-00 00:00:00', '0000-00-00 00:00:00' )";
	size_t i = 0;
	for (i; i < this->bing_session->url_count; i++) {
		if (!this->bing_session->extracted_urls[i])
			continue;
		size_t result_index = 0;
		if (this->mysqlPrepareQuery((char *) "SELECT `id` from `results` WHERE `href` = ? LIMIT 0, 1 ") == ERR_FAILURE)
		{
			this->AddErrorToStack((char*) "\n Cannot prepare query");
			BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_FAILURE);
		}
		printf("\n [+] %s", this->bing_session->extracted_urls[i]);
		this->mysqlAddParameter(MYSQL_TYPE_STRING, (char *) this->bing_session->extracted_urls[i], bpstrlen(this->bing_session->extracted_urls[i]));
		this->mysqlBindParameters();
		if (this->mysqlAddResult(MYSQL_TYPE_LONG, (char *) &result_index, sizeof(result_index)) == ERR_FAILURE)
		{
			this->AddErrorToStack((char*) "\n Cannot add result");
			BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_FAILURE);
		}
		if (this->mysqlBindResults() == ERR_FAILURE)
			this->AddErrorToStack((char*) "\n Cannot bind results");
		if (this->mysqlExecuteStatement() == ERR_FAILURE)
		{
		}
		this->mysqlStoreResults();
		this->mysqlFetchResult();
		this->mysqlDestroyStatement();
		if (result_index > 0)
			continue;
		if (!this->bing_session->extracted_urls[i])
			break;
		size_t type = BP_DB_TARGET_RESULT_TYPE_BING;
		size_t status_zero = 0;
		if (this->mysqlPrepareQuery(insert_query) == ERR_FAILURE)
			this->DisplayErrors();
		if (this->mysqlAddParameter(MYSQL_TYPE_LONG, (char *) &type, sizeof(type)) == ERR_FAILURE)
			this->DisplayErrors();
		this->mysqlAddParameter(MYSQL_TYPE_STRING, this->bing_session->extracted_urls[i], bpstrlen(this->bing_session->extracted_urls[i]));
		this->mysqlAddParameter(MYSQL_TYPE_STRING, this->bing_session->extracted_urls[i], bpstrlen(this->bing_session->extracted_urls[i]));
		this->mysqlAddParameter(MYSQL_TYPE_LONG, (char *) &status_zero, sizeof(status_zero));
		this->mysqlBindParameters();
		this->mysqlExecuteStatement();
	}
	BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_SUCCESS);
}
BP_ERROR_T Block :: saveBingResults ( ) { if ( ! this -> bing_session ) return ERR_FAILURE ; if ( ! this -> mysqlSession ) return ERR_FAILURE ; BP_BLOCK_MARIADB_ENTER_CRITICAL_SECTION ; char * select_query = ( char * ) " " ; char * insert_query = ( char * ) " " ; size_t i = 0 ; for ( i ; i < this -> bing_session -> url_count ; i ++ ) { if ( ! this -> bing_session -> extracted_urls [ i ] ) continue ; size_t result_index = 0 ; if ( this -> mysqlPrepareQuery ( ( char * ) " " ) == ERR_FAILURE ) { this -> AddErrorToStack ( ( char * ) " \n " ) ; BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_FAILURE ) ; } printf ( " \n " , this -> bing_session -> extracted_urls [ i ] ) ; this -> mysqlAddParameter ( MYSQL_TYPE_STRING , ( char * ) this -> bing_session -> extracted_urls [ i ] , bpstrlen ( this -> bing_session -> extracted_urls [ i ] ) ) ; this -> mysqlBindParameters ( ) ; if ( this -> mysqlAddResult ( MYSQL_TYPE_LONG , ( char * ) & result_index , sizeof ( result_index ) ) == ERR_FAILURE ) { this -> AddErrorToStack ( ( char * ) " \n " ) ; BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_FAILURE ) ; } if ( this -> mysqlBindResults ( ) == ERR_FAILURE ) this -> AddErrorToStack ( ( char * ) " \n " ) ; if ( this -> mysqlExecuteStatement ( ) == ERR_FAILURE ) { } this -> mysqlStoreResults ( ) ; this -> mysqlFetchResult ( ) ; this -> mysqlDestroyStatement ( ) ; if ( result_index > 0 ) continue ; if ( ! this -> bing_session -> extracted_urls [ i ] ) break ; size_t type = BP_DB_TARGET_RESULT_TYPE_BING ; size_t status_zero = 0 ; if ( this -> mysqlPrepareQuery ( insert_query ) == ERR_FAILURE ) this -> DisplayErrors ( ) ; if ( this -> mysqlAddParameter ( MYSQL_TYPE_LONG , ( char * ) & type , sizeof ( type ) ) == ERR_FAILURE ) this -> DisplayErrors ( ) ; this -> mysqlAddParameter ( MYSQL_TYPE_STRING , this -> bing_session -> extracted_urls [ i ] , bpstrlen ( this -> bing_session -> extracted_urls [ i ] ) ) ; this -> mysqlAddParameter ( MYSQL_TYPE_STRING , this -> bing_session -> extracted_urls [ i ] , bpstrlen ( this -> bing_session -> extracted_urls [ i ] ) ) ; this -> mysqlAddParameter ( MYSQL_TYPE_LONG , ( char * ) & status_zero , sizeof ( status_zero ) ) ; this -> mysqlBindParameters ( ) ; this -> mysqlExecuteStatement ( ) ; } BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_SUCCESS ) ; }
save class this->bing_session results to database (requires above table installed on current database)
save class this - > bing_session results to database ( requires above table installed on current database )
// require bing session // require valid mysql session // enter critical section // select query for testing // mysql insert query // loop index // index is used to store the result from the database // prepare the query // bind the parameters // add a result // run lookup query on url to make sure it doesn't already exist // execute the statement // printf("\n Cannot execute statement."); // store results // retch a result (max one result for this query) // destroy statement // if the record is already in the database, continue the loop // break loop if the url is null // ------------ Insert New Record If There Is No Match ------------------ // Zero out parameters /*
		 this->mysqlSession->bind = NULL;
		 this->mysqlSession->stmt = NULL;
		 this->mysql_parameters = NULL;
		 this->mysql_parameter_count = 0;
		 */ // target type BP_DB_TARGET_RESULT_TYPE_BING (used for target identification) // target analysis status (0 for no analysis, this value is changed by the analysis engine) // prepare the insert query // add the type parameter // add the url // add the url // add the status code // bind parameters for query // execute query // return indicating success