library/src/blockclass/BP-BlockClass.cc
// Adds an entry to the engine_analysis_data table.
Adds an entry to the engine_analysis_data table.
Adds an entry to the engine_analysis_data table .
BP_ERROR_T Block::WebAssessmentAddEngineAnalysisDataEntry
(
	size_t                      result_id,
	size_t                      request_id,
	size_t                      http_status_code,
	char *                      http_get,
	char *                      http_post,
	char *                      http_cookie,
	char *                      http_header,
	char *                      suspected_get_var,
	char *                      suspected_post_var,
	char *                      suspected_cookie_var,
	char *                      suspected_header_var,
	BP_WEB_ANALYSIS_ENGINE_T    detection_engine,
	BP_WEB_ANALYSIS_CONDITION_T condition,
	char *                      detection_string_test,
	char *                      detection_string_found,
	size_t                      detection_table_index
)
{
	if(!this->mysqlSession)
		return ERR_FAILURE;
	P_BP_LINKL tmp_tq = BP_CreateLinkL("tmp", BP_FALSE);
	char * result_id_s              = BP_SizeTToMySQLBuffer    (result_id,                       tmp_tq);
	char * request_id_s             = BP_SizeTToMySQLBuffer    (request_id,                      tmp_tq);
	char * http_status_code_s       = BP_SizeTToMySQLBuffer    (http_status_code,                tmp_tq);
	char * http_get_s               = BP_BufferToMySQLHexString((char *) http_get,               bpstrlen(http_get),               tmp_tq);
	char * http_post_s              = BP_BufferToMySQLHexString((char *) http_post,              bpstrlen(http_post),              tmp_tq);
	char * http_cookie_s            = BP_BufferToMySQLHexString((char *) http_cookie,            bpstrlen(http_cookie),              tmp_tq);
	char * http_header_s            = BP_BufferToMySQLHexString((char *) http_header,            bpstrlen(http_header),            tmp_tq);
	char * suspected_get_var_s      = BP_BufferToMySQLHexString((char *) suspected_get_var,      bpstrlen(suspected_get_var),      tmp_tq);
	char * suspected_post_var_s     = BP_BufferToMySQLHexString((char *) suspected_post_var,     bpstrlen(suspected_post_var),     tmp_tq);
	char * suspected_cookie_var_s   = BP_BufferToMySQLHexString((char *) suspected_cookie_var,   bpstrlen(suspected_cookie_var),   tmp_tq);
	char * suspected_header_var_s   = BP_BufferToMySQLHexString((char *) suspected_header_var,   bpstrlen(suspected_header_var),   tmp_tq);
	char * detection_engine_s       = BP_SizeTToMySQLBuffer    (detection_engine,                 tmp_tq);
	char * detection_string_test_s  = BP_BufferToMySQLHexString((char *) detection_string_test,  bpstrlen(detection_string_test),  tmp_tq);
	char * detection_string_found_s = BP_BufferToMySQLHexString((char *) detection_string_found, bpstrlen(detection_string_found), tmp_tq);
	char * detection_table_index_s  = BP_SizeTToMySQLBuffer    (detection_table_index,           tmp_tq);
	char * condition_s              = BP_SizeTToMySQLBuffer    (condition,                       tmp_tq);
	char * add_indexes[80];
	BP_ZERO_STACK(add_indexes);
	size_t x = 0;
	add_indexes[x] = "INSERT INTO `engine_analysis_data` " \
			         "( "                                  \
			         "  `result_id`, "\
			         "  `request_id`, "\
			         "  `http_status_code`, " \
			         "  `http_get`, "\
			         "  `http_post`, "\
			         "  `http_cookie`, "\
			         "  `http_header`, "
			         "  `suspected_get_var`, "
			         "  `suspected_post_var`, " \
			         "  `suspected_cookie_var`, "\
			         "  `suspected_header_var`, "\
			         "  `detection_engine`, "\
			         "  `detection_string_test`, "\
			         "  `detection_string_found`, "\
			         "  `detection_table_index`, "\
			         "  `condition_type`, "\
			         "  `commit_ts`) "\
			         "  VALUES ( ";
	x++;
	add_indexes[x] = result_id_s;               x++;
	add_indexes[x] = ",";                       x++;
	add_indexes[x] = request_id_s;              x++;
	add_indexes[x] = ",";                       x++;
	add_indexes[x] = http_status_code_s;        x++;
	add_indexes[x] = ",";                       x++;
	add_indexes[x] = http_get_s;                x++;
	add_indexes[x] = ",";                       x++;
	add_indexes[x] = http_post_s;               x++;
	add_indexes[x] = ",";                       x++;
	add_indexes[x] = http_cookie_s;             x++;
	add_indexes[x] = ",";                       x++;
	add_indexes[x] = http_header_s;             x++;
	add_indexes[x] = ",";                       x++;
	add_indexes[x] = suspected_get_var_s;       x++;
	add_indexes[x] = ",";                       x++;
	add_indexes[x] = suspected_post_var_s;      x++;
	add_indexes[x] = ",";                       x++;
	add_indexes[x] = suspected_cookie_var_s;    x++;
	add_indexes[x] = ",";                       x++;
	add_indexes[x] = suspected_header_var_s;    x++;
	add_indexes[x] = ",";                       x++;
	add_indexes[x] = detection_engine_s;        x++;
	add_indexes[x] = ",";                       x++;
	add_indexes[x] = detection_string_test_s;   x++;
	add_indexes[x] = ",";                       x++;
	add_indexes[x] = detection_string_found_s;  x++;
	add_indexes[x] = ",";                       x++;
	add_indexes[x] = detection_table_index_s;   x++;
	add_indexes[x] = ",";                       x++;
	add_indexes[x] = condition_s;               x++;
	add_indexes[x] = ",";                       x++;
	add_indexes[x] = "NOW()";                   x++;
	add_indexes[x] = "); ";                     x++;
	char * query = BP_JoinStringArray((char **) &add_indexes, x, tmp_tq);
	if(this->mysqlPrepareQuery(query) != ERR_SUCCESS)
	{
		BP_DestroyLinkL(tmp_tq, BP_TRUE);
		return ERR_FAILURE;
	}
	if(this->mysqlExecuteStatement() != ERR_SUCCESS)
	{
		this->mysqlDestroyStatement();
		BP_DestroyLinkL(tmp_tq, BP_TRUE);
		return ERR_FAILURE;
	}
	this->mysqlDestroyStatement();
	BP_DestroyLinkL(tmp_tq, BP_TRUE);
	return ERR_SUCCESS;
}
BP_ERROR_T Block :: WebAssessmentAddEngineAnalysisDataEntry ( size_t result_id , size_t request_id , size_t http_status_code , char * http_get , char * http_post , char * http_cookie , char * http_header , char * suspected_get_var , char * suspected_post_var , char * suspected_cookie_var , char * suspected_header_var , BP_WEB_ANALYSIS_ENGINE_T detection_engine , BP_WEB_ANALYSIS_CONDITION_T condition , char * detection_string_test , char * detection_string_found , size_t detection_table_index ) { if ( ! this -> mysqlSession ) return ERR_FAILURE ; P_BP_LINKL tmp_tq = BP_CreateLinkL ( " " , BP_FALSE ) ; char * result_id_s = BP_SizeTToMySQLBuffer ( result_id , tmp_tq ) ; char * request_id_s = BP_SizeTToMySQLBuffer ( request_id , tmp_tq ) ; char * http_status_code_s = BP_SizeTToMySQLBuffer ( http_status_code , tmp_tq ) ; char * http_get_s = BP_BufferToMySQLHexString ( ( char * ) http_get , bpstrlen ( http_get ) , tmp_tq ) ; char * http_post_s = BP_BufferToMySQLHexString ( ( char * ) http_post , bpstrlen ( http_post ) , tmp_tq ) ; char * http_cookie_s = BP_BufferToMySQLHexString ( ( char * ) http_cookie , bpstrlen ( http_cookie ) , tmp_tq ) ; char * http_header_s = BP_BufferToMySQLHexString ( ( char * ) http_header , bpstrlen ( http_header ) , tmp_tq ) ; char * suspected_get_var_s = BP_BufferToMySQLHexString ( ( char * ) suspected_get_var , bpstrlen ( suspected_get_var ) , tmp_tq ) ; char * suspected_post_var_s = BP_BufferToMySQLHexString ( ( char * ) suspected_post_var , bpstrlen ( suspected_post_var ) , tmp_tq ) ; char * suspected_cookie_var_s = BP_BufferToMySQLHexString ( ( char * ) suspected_cookie_var , bpstrlen ( suspected_cookie_var ) , tmp_tq ) ; char * suspected_header_var_s = BP_BufferToMySQLHexString ( ( char * ) suspected_header_var , bpstrlen ( suspected_header_var ) , tmp_tq ) ; char * detection_engine_s = BP_SizeTToMySQLBuffer ( detection_engine , tmp_tq ) ; char * detection_string_test_s = BP_BufferToMySQLHexString ( ( char * ) detection_string_test , bpstrlen ( detection_string_test ) , tmp_tq ) ; char * detection_string_found_s = BP_BufferToMySQLHexString ( ( char * ) detection_string_found , bpstrlen ( detection_string_found ) , tmp_tq ) ; char * detection_table_index_s = BP_SizeTToMySQLBuffer ( detection_table_index , tmp_tq ) ; char * condition_s = BP_SizeTToMySQLBuffer ( condition , tmp_tq ) ; char * add_indexes [ 80 ] ; BP_ZERO_STACK ( add_indexes ) ; size_t x = 0 ; add_indexes [ x ] = " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " ; x ++ ; add_indexes [ x ] = result_id_s ; x ++ ; add_indexes [ x ] = " " ; x ++ ; add_indexes [ x ] = request_id_s ; x ++ ; add_indexes [ x ] = " " ; x ++ ; add_indexes [ x ] = http_status_code_s ; x ++ ; add_indexes [ x ] = " " ; x ++ ; add_indexes [ x ] = http_get_s ; x ++ ; add_indexes [ x ] = " " ; x ++ ; add_indexes [ x ] = http_post_s ; x ++ ; add_indexes [ x ] = " " ; x ++ ; add_indexes [ x ] = http_cookie_s ; x ++ ; add_indexes [ x ] = " " ; x ++ ; add_indexes [ x ] = http_header_s ; x ++ ; add_indexes [ x ] = " " ; x ++ ; add_indexes [ x ] = suspected_get_var_s ; x ++ ; add_indexes [ x ] = " " ; x ++ ; add_indexes [ x ] = suspected_post_var_s ; x ++ ; add_indexes [ x ] = " " ; x ++ ; add_indexes [ x ] = suspected_cookie_var_s ; x ++ ; add_indexes [ x ] = " " ; x ++ ; add_indexes [ x ] = suspected_header_var_s ; x ++ ; add_indexes [ x ] = " " ; x ++ ; add_indexes [ x ] = detection_engine_s ; x ++ ; add_indexes [ x ] = " " ; x ++ ; add_indexes [ x ] = detection_string_test_s ; x ++ ; add_indexes [ x ] = " " ; x ++ ; add_indexes [ x ] = detection_string_found_s ; x ++ ; add_indexes [ x ] = " " ; x ++ ; add_indexes [ x ] = detection_table_index_s ; x ++ ; add_indexes [ x ] = " " ; x ++ ; add_indexes [ x ] = condition_s ; x ++ ; add_indexes [ x ] = " " ; x ++ ; add_indexes [ x ] = " " ; x ++ ; add_indexes [ x ] = " " ; x ++ ; char * query = BP_JoinStringArray ( ( char * * ) & add_indexes , x , tmp_tq ) ; if ( this -> mysqlPrepareQuery ( query ) != ERR_SUCCESS ) { BP_DestroyLinkL ( tmp_tq , BP_TRUE ) ; return ERR_FAILURE ; } if ( this -> mysqlExecuteStatement ( ) != ERR_SUCCESS ) { this -> mysqlDestroyStatement ( ) ; BP_DestroyLinkL ( tmp_tq , BP_TRUE ) ; return ERR_FAILURE ; } this -> mysqlDestroyStatement ( ) ; BP_DestroyLinkL ( tmp_tq , BP_TRUE ) ; return ERR_SUCCESS ; }
Adds an entry to the engine_analysis_data table.
Adds an entry to the engine_analysis_data table .
// ensure we have a mysql session // create a temporary allocator for tracking heap chunk // convert all parameters into escaped mysql hex strings, store them // all in the tmp tailqueue for easy cleanup. // create a joinable array // create iterator for moving index positions // move past front par // create the query // printf("\n Getting here?: %s - %s", query, detection_string_test); // prepare query // execute query // destroy the statement if we got this far // destroy all registered memory // return indicating success