library/src/blockclass/BP-BlockClass.cc
// check whether or not a record should be disabled.  As a note
// it's important to know that this is called directly from popWebResultWebStack
// automatically, this is to streamline the process of getting non-disabled
// entries.
check whether or not a record should be disabled.  As a note
it's important to know that this is called directly from popWebResultWebStack
automatically, this is to streamline the process of getting non-disabled
entries.
check whether or not a record should be disabled . As a note it ' s important to know that this is called directly from popWebResultWebStack automatically this is to streamline the process of getting non - disabled entries .
BP_ERROR_T Block::checkWebResultEntryShouldBeDisabled(P_BP_WEB_RESULT_ENTRY entry)
{
	if(!this->mysqlSession)
		return ERR_FAILURE;
	BP_BLOCK_MARIADB_ENTER_CRITICAL_SECTION;
	if(!this->web_result_disable_script_threshold)
	{
		printf("\n [!!] Error: Disable checks require a this->web_result_disable_script_threshold.");
		BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_FAILURE);
	}
	if(!this->web_result_disable_path_threshold)
	{
		printf("\n [!!] Error: Disable checks require a this->web_result_disable_path_threshold.");
		BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_FAILURE);
	}
	if(!this->web_result_disable_base_threshold)
	{
		printf("\n [!!] Error: Disable checks require a this->web_result_disable_base_threshold.");
		BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_FAILURE);
	}
	if(!entry)
		BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_FAILURE);
	if(!entry->result_id)
		BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_FAILURE);
	if(!entry->base)
		BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_FAILURE);
	if(!entry->path)
		BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_FAILURE);
	if(!entry->script)
		BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_FAILURE);
	char * base_hit_threshold_s   = (char *) BP_SizeTToMySQLBuffer(web_result_disable_base_threshold);
	char * path_hit_threshold_s   = (char *) BP_SizeTToMySQLBuffer(web_result_disable_path_threshold);
	char * script_hit_threshold_s = (char *) BP_SizeTToMySQLBuffer(web_result_disable_script_threshold);
	tq_link(this->tq, base_hit_threshold_s, 4, BPLN);
	tq_link(this->tq, path_hit_threshold_s, 4, BPLN);
	tq_link(this->tq, script_hit_threshold_s, 4, BPLN);
	char * result_id_s   = BP_SizeTToMySQLBuffer(entry->result_id);
	char * base_id_s     = BP_SizeTToMySQLBuffer(entry->base);
	char * path_id_s     = BP_SizeTToMySQLBuffer(entry->path);
	char * script_id_s   = BP_SizeTToMySQLBuffer(entry->script);
	tq_link(this->tq, result_id_s, 4, BPLN);
	tq_link(this->tq, base_id_s, 4, BPLN);
	tq_link(this->tq, path_id_s, 4, BPLN);
	tq_link(this->tq, script_id_s, 4, BPLN);
	if(entry->path)
	{
		BP_StringUtils * builder = new BP_StringUtils(NULL);
		builder->BuildString((char *) "UPDATE `results` ");
		builder->BuildString((char *) " JOIN `result_path_uris` ON `result_path_uris`.`id` = `results`.`path` ");
		builder->BuildString((char *) " SET `results`.`disabled` = 1 ");
		builder->BuildString((char *) " WHERE `results`.`id` = ");
		builder->BuildString((char *) result_id_s);
		builder->BuildString((char *) " AND `results`.`path` = ");
		builder->BuildString((char *) path_id_s);
		builder->BuildString((char *) " AND `result_path_uris`.`hits` >= ");
		builder->BuildString((char *) path_hit_threshold_s);
		printf("\n Disable Path Query: %s", builder->build_str);
		this->mysqlPrepareQuery(builder->build_str);
		this->mysqlExecuteStatement();
		this->mysqlDestroyStatement();
		delete builder;
	}
	if(entry->base)
	{
		BP_StringUtils * builder = new BP_StringUtils(NULL);
		builder->BuildString((char *) "UPDATE `results` ");
		builder->BuildString((char *) " JOIN `result_base_uris` ON `result_base_uris`.`id` = `results`.`base` ");
		builder->BuildString((char *) " SET `results`.`disabled` = 1 ");
		builder->BuildString((char *) " WHERE `results`.`id` = ");
		builder->BuildString((char *) result_id_s);
		builder->BuildString((char *) " AND `results`.`base` = ");
		builder->BuildString((char *) base_id_s);
		builder->BuildString((char *) " AND `result_base_uris`.`hits` >= ");
		builder->BuildString((char *) base_hit_threshold_s);
		this->mysqlPrepareQuery(builder->build_str);
		this->mysqlExecuteStatement();
		this->mysqlDestroyStatement();
		delete builder;
	}
	if(entry->script)
	{
		BP_StringUtils * builder = new BP_StringUtils(NULL);
		builder->BuildString((char *) "UPDATE `results` ");
		builder->BuildString((char *) " JOIN `result_script_uris` ON `result_script_uris`.`id` = `results`.`script` ");
		builder->BuildString((char *) " SET `results`.`disabled` = 1 ");
		builder->BuildString((char *) " WHERE `results`.`id` = ");
		builder->BuildString((char *) result_id_s);
		builder->BuildString((char *) " AND `results`.`script` = ");
		builder->BuildString((char *) script_id_s);
		builder->BuildString((char *) " AND `result_script_uris`.`hits` >= ");
		builder->BuildString((char *) script_hit_threshold_s);
		this->mysqlPrepareQuery(builder->build_str);
		this->mysqlExecuteStatement();
		this->mysqlDestroyStatement();
		delete builder;
	}
	if(result_id_s)
		tq_free(this->tq, result_id_s);
	if(base_id_s)
		tq_free(this->tq, base_id_s);
	if(path_id_s)
		tq_free(this->tq, path_id_s);
	if(script_id_s)
		tq_free(this->tq, script_id_s);
	if(base_hit_threshold_s)
		tq_free(this->tq, base_hit_threshold_s);
	if(path_hit_threshold_s)
		tq_free(this->tq, path_hit_threshold_s);
	if(script_hit_threshold_s)
		tq_free(this->tq, script_hit_threshold_s);
	BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_SUCCESS);
}
BP_ERROR_T Block :: checkWebResultEntryShouldBeDisabled ( P_BP_WEB_RESULT_ENTRY entry ) { if ( ! this -> mysqlSession ) return ERR_FAILURE ; BP_BLOCK_MARIADB_ENTER_CRITICAL_SECTION ; if ( ! this -> web_result_disable_script_threshold ) { printf ( " \n " ) ; BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_FAILURE ) ; } if ( ! this -> web_result_disable_path_threshold ) { printf ( " \n " ) ; BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_FAILURE ) ; } if ( ! this -> web_result_disable_base_threshold ) { printf ( " \n " ) ; BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_FAILURE ) ; } if ( ! entry ) BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_FAILURE ) ; if ( ! entry -> result_id ) BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_FAILURE ) ; if ( ! entry -> base ) BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_FAILURE ) ; if ( ! entry -> path ) BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_FAILURE ) ; if ( ! entry -> script ) BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_FAILURE ) ; char * base_hit_threshold_s = ( char * ) BP_SizeTToMySQLBuffer ( web_result_disable_base_threshold ) ; char * path_hit_threshold_s = ( char * ) BP_SizeTToMySQLBuffer ( web_result_disable_path_threshold ) ; char * script_hit_threshold_s = ( char * ) BP_SizeTToMySQLBuffer ( web_result_disable_script_threshold ) ; tq_link ( this -> tq , base_hit_threshold_s , 4 , BPLN ) ; tq_link ( this -> tq , path_hit_threshold_s , 4 , BPLN ) ; tq_link ( this -> tq , script_hit_threshold_s , 4 , BPLN ) ; char * result_id_s = BP_SizeTToMySQLBuffer ( entry -> result_id ) ; char * base_id_s = BP_SizeTToMySQLBuffer ( entry -> base ) ; char * path_id_s = BP_SizeTToMySQLBuffer ( entry -> path ) ; char * script_id_s = BP_SizeTToMySQLBuffer ( entry -> script ) ; tq_link ( this -> tq , result_id_s , 4 , BPLN ) ; tq_link ( this -> tq , base_id_s , 4 , BPLN ) ; tq_link ( this -> tq , path_id_s , 4 , BPLN ) ; tq_link ( this -> tq , script_id_s , 4 , BPLN ) ; if ( entry -> path ) { BP_StringUtils * builder = new BP_StringUtils ( NULL ) ; builder -> BuildString ( ( char * ) " " ) ; builder -> BuildString ( ( char * ) " " ) ; builder -> BuildString ( ( char * ) " " ) ; builder -> BuildString ( ( char * ) " " ) ; builder -> BuildString ( ( char * ) result_id_s ) ; builder -> BuildString ( ( char * ) " " ) ; builder -> BuildString ( ( char * ) path_id_s ) ; builder -> BuildString ( ( char * ) " " ) ; builder -> BuildString ( ( char * ) path_hit_threshold_s ) ; printf ( " \n " , builder -> build_str ) ; this -> mysqlPrepareQuery ( builder -> build_str ) ; this -> mysqlExecuteStatement ( ) ; this -> mysqlDestroyStatement ( ) ; delete builder ; } if ( entry -> base ) { BP_StringUtils * builder = new BP_StringUtils ( NULL ) ; builder -> BuildString ( ( char * ) " " ) ; builder -> BuildString ( ( char * ) " " ) ; builder -> BuildString ( ( char * ) " " ) ; builder -> BuildString ( ( char * ) " " ) ; builder -> BuildString ( ( char * ) result_id_s ) ; builder -> BuildString ( ( char * ) " " ) ; builder -> BuildString ( ( char * ) base_id_s ) ; builder -> BuildString ( ( char * ) " " ) ; builder -> BuildString ( ( char * ) base_hit_threshold_s ) ; this -> mysqlPrepareQuery ( builder -> build_str ) ; this -> mysqlExecuteStatement ( ) ; this -> mysqlDestroyStatement ( ) ; delete builder ; } if ( entry -> script ) { BP_StringUtils * builder = new BP_StringUtils ( NULL ) ; builder -> BuildString ( ( char * ) " " ) ; builder -> BuildString ( ( char * ) " " ) ; builder -> BuildString ( ( char * ) " " ) ; builder -> BuildString ( ( char * ) " " ) ; builder -> BuildString ( ( char * ) result_id_s ) ; builder -> BuildString ( ( char * ) " " ) ; builder -> BuildString ( ( char * ) script_id_s ) ; builder -> BuildString ( ( char * ) " " ) ; builder -> BuildString ( ( char * ) script_hit_threshold_s ) ; this -> mysqlPrepareQuery ( builder -> build_str ) ; this -> mysqlExecuteStatement ( ) ; this -> mysqlDestroyStatement ( ) ; delete builder ; } if ( result_id_s ) tq_free ( this -> tq , result_id_s ) ; if ( base_id_s ) tq_free ( this -> tq , base_id_s ) ; if ( path_id_s ) tq_free ( this -> tq , path_id_s ) ; if ( script_id_s ) tq_free ( this -> tq , script_id_s ) ; if ( base_hit_threshold_s ) tq_free ( this -> tq , base_hit_threshold_s ) ; if ( path_hit_threshold_s ) tq_free ( this -> tq , path_hit_threshold_s ) ; if ( script_hit_threshold_s ) tq_free ( this -> tq , script_hit_threshold_s ) ; BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_SUCCESS ) ; }
check whether or not a record should be disabled.
check whether or not a record should be disabled .
// ensure we have a msyql session to work with // enter critical section // ensure threshold values are set // ensure we have an entry // require a set result id // require a base // require a base // require a script // convert parameters to strings for query embedding // link up the converted values for chunk loging // now set result/base/path/script // link in items // create a new builder // create new builder // build update path query // prepare update query // execute statement // destroy statement // build update base query // create new builder // build update base query // build and execute // build update script query // create new builder // build update script query // prepare query // execute statement // destroy statement // destroy builder // free data // return indicating success