library/src/blockclass/BP-BlockClass.cc
// Inserts a new audit target into the db.  This routine automatically does insert stacking
// if configured to do so via class member settings (aka this->enable_result_insert_stacking etc).  Stacking
// is done to conserve database resources when doing inserts.  IN laymans terms, stacking essentially enables
// batch database record insertion.
Inserts a new audit target into the db.  This routine automatically does insert stacking
if configured to do so via class member settings (aka this->enable_result_insert_stacking etc).  Stacking
is done to conserve database resources when doing inserts.  IN laymans terms, stacking essentially enables
batch database record insertion.
Inserts a new audit target into the db . This routine automatically does insert stacking if configured to do so via class member settings ( aka this - > enable_result_insert_stacking etc ) . Stacking is done to conserve database resources when doing inserts . IN laymans terms stacking essentially enables batch database record insertion .
size_t Block::insertNewResult(size_t type, char *href, size_t status_code, size_t parent_id)
{
	if(!this->mysqlSession)
		return ERR_FAILURE;
	BP_BLOCK_MARIADB_ENTER_CRITICAL_SECTION;
	if (!href)
		BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_FAILURE);
	if(!BP_StringIsReasonablePrintableString(href, bpstrlen(href), BP_FALSE, BP_FALSE))
		BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_FAILURE);
	if(href[0] == '/')
		BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_FAILURE);
	if(href[0] == '.')
		BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_FAILURE);
	if(href[0] == '#')
		BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_FAILURE);
	char *script = BP_ParseURLToScriptPCRE(href);
	char *path   = BP_ParseURLToPathPCRE(script);
	char *base   = BP_ParseURLToBasePCRE(path);
	char *host   = BP_ParseURLToHostPCRE(base);
	if(!script || !path || !base || !host)
	{
		if(script)
			bpfree(script);
		if(path)
			bpfree(path);
		if(base)
			bpfree(base);
		if(host)
			bpfree(host);
		BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_FAILURE);
	}
	printf("\n [!!] Inserting new result1: %s", href);
	if(this->enable_result_insert_stacking == true)
	{
		if(!this->stackInsertRequest(type, href, status_code, parent_id))
		{
			BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_FAILURE);
		}
		if(script)
			bpfree(script);
		if(path)
			bpfree(path);
		if(base)
			bpfree(base);
		if(host)
			bpfree(host);
		BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_SUCCESS);
	}
	printf("\n [!!] Inserting new result2: %s", href);
	if (this->checkResultExists(href, status_code) == ERR_SUCCESS)
		BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_FAILURE);
	printf("\n [!!] Inserting new result3: %s", href);
	this->stackInsertRequest(type, href, status_code, parent_id);
	printf("\n [!!] Inserting new result4: %s", href);
	this->flushInsertRequests();
	BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_SUCCESS);
}
size_t Block :: insertNewResult ( size_t type , char * href , size_t status_code , size_t parent_id ) { if ( ! this -> mysqlSession ) return ERR_FAILURE ; BP_BLOCK_MARIADB_ENTER_CRITICAL_SECTION ; if ( ! href ) BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_FAILURE ) ; if ( ! BP_StringIsReasonablePrintableString ( href , bpstrlen ( href ) , BP_FALSE , BP_FALSE ) ) BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_FAILURE ) ; if ( href [ 0 ] == ' ' ) BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_FAILURE ) ; if ( href [ 0 ] == ' ' ) BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_FAILURE ) ; if ( href [ 0 ] == ' ' ) BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_FAILURE ) ; char * script = BP_ParseURLToScriptPCRE ( href ) ; char * path = BP_ParseURLToPathPCRE ( script ) ; char * base = BP_ParseURLToBasePCRE ( path ) ; char * host = BP_ParseURLToHostPCRE ( base ) ; if ( ! script || ! path || ! base || ! host ) { if ( script ) bpfree ( script ) ; if ( path ) bpfree ( path ) ; if ( base ) bpfree ( base ) ; if ( host ) bpfree ( host ) ; BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_FAILURE ) ; } printf ( " \n " , href ) ; if ( this -> enable_result_insert_stacking == true ) { if ( ! this -> stackInsertRequest ( type , href , status_code , parent_id ) ) { BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_FAILURE ) ; } if ( script ) bpfree ( script ) ; if ( path ) bpfree ( path ) ; if ( base ) bpfree ( base ) ; if ( host ) bpfree ( host ) ; BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_SUCCESS ) ; } printf ( " \n " , href ) ; if ( this -> checkResultExists ( href , status_code ) == ERR_SUCCESS ) BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_FAILURE ) ; printf ( " \n " , href ) ; this -> stackInsertRequest ( type , href , status_code , parent_id ) ; printf ( " \n " , href ) ; this -> flushInsertRequests ( ) ; BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_SUCCESS ) ; }
Inserts a new audit target into the db.
Inserts a new audit target into the db .
// ensure we have a non-null session // enter critical section // check parameters // run basic initial checks // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Attempt To Parse Base/Path/Script/Host %%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // ensure the result can be parsed out in all // metrics, if not, consider it invalid // push results into caches // destroy any which may have been parsed out // return indicating failure // do insert stacking where necessary // attempt to stack the insert request // destroy all allocated memory // return indicating success // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Do Immediate Insert if We're Not Stacking %%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // check to make sure it doesn't exist first (prevent ovewrites) // stack the request and flush immediately // flush immediately // return indicating success