library/src/blockclass/subclasses/command_line_tools/BP_CommandLineToolBase.cc
// insert command line tool run data
insert command line tool run data
insert command line tool run data
BP_ERROR_T BP_CommandLineToolBase::insertCommandLineToolData
(
	size_t tool_data_type,
	size_t assessment_id,
	size_t nmap_host_id,
	size_t base_id,
	size_t path_id,
	size_t script_id,
	size_t result_id,
	char * data,
	size_t data_size
)
{
	if(!this->cltdb_id)
	{
		printf("\n [!!] Attempting to insertCommandLineToolData without having a valid tool_id to associate it with.  Exiting routine with failure.  Fix: call insertCommandLineTool() first.");
		return ERR_SUCCESS;
	}
	if(!data || !data_size)
		return ERR_FAILURE;
	if(!this->mysqlSession)
		return ERR_FAILURE;
	if(!this->mysqlSession->connected)
		return ERR_FAILURE;
	if(!this->application_unique_db_run_id)
		this->getNewRunIDFromDB();
	if(!this->application_unique_db_run_id)
		return ERR_FAILURE;
	BP_StringUtils * builder = new BP_StringUtils(NULL);
	builder->BuildString("INSERT INTO `command_line_tool_data` (`run_id`, `tool_id`, `tool_data_type`, `assessment_id`, `nmap_host_id`, `base`, `path`, `script`, `result`, `data_sha1`, `data`) VALUES ");
	char * run_id_s = BP_BufferToMySQLHexString(this->application_unique_db_run_id, bpstrlen(this->application_unique_db_run_id));
	char * tool_id_s = BP_SizeTToMySQLBuffer(this->cltdb_id);
	char * tool_data_type_s = BP_SizeTToMySQLBuffer(tool_data_type);
	char * assessment_id_s = BP_SizeTToMySQLBuffer(assessment_id);
	char * nmap_host_id_s = BP_SizeTToMySQLBuffer(nmap_host_id);
	char * base_s = BP_SizeTToMySQLBuffer(base_id);
	char * path_s = BP_SizeTToMySQLBuffer(path_id);
	char * script_s = BP_SizeTToMySQLBuffer(script_id);
	char * result_s = BP_SizeTToMySQLBuffer(result_id);
	this->GenSHA1(data, data_size);
	char * data_sha1_s = BP_BufferToMySQLHexString(this->sha1_ascii, bpstrlen(this->sha1_ascii));
	char * data_s = BP_BufferToMySQLHexString(data, data_size);
	builder->BuildString(" ( ");
	builder->BuildString(run_id_s);
	builder->BuildString(" , ");
	builder->BuildString(tool_id_s);
	builder->BuildString(" , ");
	builder->BuildString(tool_data_type_s);
	builder->BuildString(" , ");
	builder->BuildString(assessment_id_s);
	builder->BuildString(" , ");
	builder->BuildString(nmap_host_id_s);
	builder->BuildString(" , ");
	builder->BuildString(base_s);
	builder->BuildString(" , ");
	builder->BuildString(path_s);
	builder->BuildString(" , ");
	builder->BuildString(script_s);
	builder->BuildString(" , ");
	builder->BuildString(result_s);
	builder->BuildString(" , ");
	builder->BuildString(data_sha1_s);
	builder->BuildString(" , ");
	builder->BuildString(data_s);
	builder->BuildString(" ) ");
	this->mysqlPrepareQuery(builder->build_str);
	this->mysqlExecuteStatement();
	this->mysqlDestroyStatement();
	if(data_sha1_s)
		bpfree(data_sha1_s);
	if(run_id_s)
		bpfree(run_id_s);
	if(tool_id_s)
		bpfree(tool_id_s);
	if(tool_data_type_s)
		bpfree(tool_data_type_s);
	if(assessment_id_s)
		bpfree(assessment_id_s);
	if(nmap_host_id_s)
		bpfree(nmap_host_id_s);
	if(base_s)
		bpfree(base_s);
	if(path_s)
		bpfree(path_s);
	if(script_s)
		bpfree(script_s);
	if(result_s)
		bpfree(result_s);
	delete builder;
	return ERR_SUCCESS;
}
BP_ERROR_T BP_CommandLineToolBase :: insertCommandLineToolData ( size_t tool_data_type , size_t assessment_id , size_t nmap_host_id , size_t base_id , size_t path_id , size_t script_id , size_t result_id , char * data , size_t data_size ) { if ( ! this -> cltdb_id ) { printf ( " \n " ) ; return ERR_SUCCESS ; } if ( ! data || ! data_size ) return ERR_FAILURE ; if ( ! this -> mysqlSession ) return ERR_FAILURE ; if ( ! this -> mysqlSession -> connected ) return ERR_FAILURE ; if ( ! this -> application_unique_db_run_id ) this -> getNewRunIDFromDB ( ) ; if ( ! this -> application_unique_db_run_id ) return ERR_FAILURE ; BP_StringUtils * builder = new BP_StringUtils ( NULL ) ; builder -> BuildString ( " " ) ; char * run_id_s = BP_BufferToMySQLHexString ( this -> application_unique_db_run_id , bpstrlen ( this -> application_unique_db_run_id ) ) ; char * tool_id_s = BP_SizeTToMySQLBuffer ( this -> cltdb_id ) ; char * tool_data_type_s = BP_SizeTToMySQLBuffer ( tool_data_type ) ; char * assessment_id_s = BP_SizeTToMySQLBuffer ( assessment_id ) ; char * nmap_host_id_s = BP_SizeTToMySQLBuffer ( nmap_host_id ) ; char * base_s = BP_SizeTToMySQLBuffer ( base_id ) ; char * path_s = BP_SizeTToMySQLBuffer ( path_id ) ; char * script_s = BP_SizeTToMySQLBuffer ( script_id ) ; char * result_s = BP_SizeTToMySQLBuffer ( result_id ) ; this -> GenSHA1 ( data , data_size ) ; char * data_sha1_s = BP_BufferToMySQLHexString ( this -> sha1_ascii , bpstrlen ( this -> sha1_ascii ) ) ; char * data_s = BP_BufferToMySQLHexString ( data , data_size ) ; builder -> BuildString ( " " ) ; builder -> BuildString ( run_id_s ) ; builder -> BuildString ( " " ) ; builder -> BuildString ( tool_id_s ) ; builder -> BuildString ( " " ) ; builder -> BuildString ( tool_data_type_s ) ; builder -> BuildString ( " " ) ; builder -> BuildString ( assessment_id_s ) ; builder -> BuildString ( " " ) ; builder -> BuildString ( nmap_host_id_s ) ; builder -> BuildString ( " " ) ; builder -> BuildString ( base_s ) ; builder -> BuildString ( " " ) ; builder -> BuildString ( path_s ) ; builder -> BuildString ( " " ) ; builder -> BuildString ( script_s ) ; builder -> BuildString ( " " ) ; builder -> BuildString ( result_s ) ; builder -> BuildString ( " " ) ; builder -> BuildString ( data_sha1_s ) ; builder -> BuildString ( " " ) ; builder -> BuildString ( data_s ) ; builder -> BuildString ( " " ) ; this -> mysqlPrepareQuery ( builder -> build_str ) ; this -> mysqlExecuteStatement ( ) ; this -> mysqlDestroyStatement ( ) ; if ( data_sha1_s ) bpfree ( data_sha1_s ) ; if ( run_id_s ) bpfree ( run_id_s ) ; if ( tool_id_s ) bpfree ( tool_id_s ) ; if ( tool_data_type_s ) bpfree ( tool_data_type_s ) ; if ( assessment_id_s ) bpfree ( assessment_id_s ) ; if ( nmap_host_id_s ) bpfree ( nmap_host_id_s ) ; if ( base_s ) bpfree ( base_s ) ; if ( path_s ) bpfree ( path_s ) ; if ( script_s ) bpfree ( script_s ) ; if ( result_s ) bpfree ( result_s ) ; delete builder ; return ERR_SUCCESS ; }
insert command line tool run data
insert command line tool run data
// check that we have a resolved id // cant insert data without data // ensure we have a mysql session // create a new run id if we don't already have one // create new string builder // frontload insert query // `run_id`, // `tool_id`, // `tool_data_type`, // `assessment_id`, // `nmap_host_id`, // `base`, // `path`, // `script`, // `result`, // `data_sha1`, // create hex string // `data` // build in parameters // set execute // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %% Destroy Data %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // create hex string // `run_id`, // `tool_id`, // `tool_data_type`, // `assessment_id`, // `nmap_host_id`, // `base`, // `path`, // `script`, // `result`, // destroy the builder // return indicating success