library/src/blockclass/subclasses/BPSC_SSHIntegrityChecker.cc
// polls a table in the database looking for jobs based on a status code
polls a table in the database looking for jobs based on a status code
polls a table in the database looking for jobs based on a status code
BP_ERROR_T BPSC_SSHIntegrityChecker::pollQueue(BPSC_JOB_QUEUE_STATUS status, size_t min_limit, size_t max_limit)
{
	char *status_str = NULL;
	switch(status)
	{
		case BPSC_JOB_QUEUE_STATUS_NEW:
			status_str = "new";
			break;
		case BPSC_JOB_QUEUE_STATUS_FINISHED:
			status_str = "finished";
			break;
		case BPSC_JOB_QUEUE_STATUS_RUNNING:
			status_str = "running";
			break;
		case BPSC_JOB_QUEUE_STATUS_WAITING:
			status_str = "waiting";
			break;
		default:
			return ERR_FAILURE;
	}
	char isql[2048] = {0};
	snprintf((char *) &isql, 2046, "SELECT {id}, {config_id}, {job_status} from `host_queue` where `job_status` = ? order by id desc limit %u,%u", min_limit, max_limit);
	char * sql = this->mysqlAesPrepare((char *) &isql, NULL);
	if(!sql)
		return ERR_FAILURE;
	this->mysqlPrepareQuery(sql);
	this->mysqlAddParameter(MYSQL_TYPE_STRING, status_str, bpstrlen(status_str));
	this->mysqlBindParameters();
	size_t job_id    = 0;
	size_t config_id = 0;
	char job_status[1024] = {0};
	this->mysqlAddResult(MYSQL_TYPE_LONG,   (char *) &job_id,     sizeof(job_id));
	this->mysqlAddResult(MYSQL_TYPE_LONG,   (char *) &config_id,  sizeof(config_id));
	this->mysqlAddResult(MYSQL_TYPE_STRING, (char *) &job_status, sizeof(job_status)-1);
	this->mysqlBindResults();
	this->mysqlExecuteStatement();
	this->mysqlStoreResults();
	size_t counter = 0;
	P_BPSC_JOB_QUEUE_ENTRY entries = NULL;
	while(this->mysqlFetchResult())
	{
		counter++;
		entries = (P_BPSC_JOB_QUEUE_ENTRY) bprealloc(entries, sizeof(BPSC_JOB_QUEUE_ENTRY) * counter);
		memset((char *) &entries[counter-1], 0x00, sizeof(BPSC_JOB_QUEUE_ENTRY));
		entries[counter-1].job_id    = job_id;
		entries[counter-1].config_id = config_id;
		snprintf((char *) &entries[counter-1].status, sizeof(entries[counter-1].status)-1, "%s", (char *) &job_status);
	}
	switch(status)
	{
		case BPSC_JOB_QUEUE_STATUS_NEW:
			if(this->new_queue)
				bpfree(this->new_queue);
			this->new_queue       = entries;
			this->new_entry_count = counter;
			break;
		case BPSC_JOB_QUEUE_STATUS_FINISHED:
			if(this->finished_queue)
				bpfree(this->finished_queue);
			this->finished_queue       = entries;
			this->finished_entry_count = counter;
			break;
		case BPSC_JOB_QUEUE_STATUS_RUNNING:
			if(this->running_queue)
				bpfree(this->running_queue);
			this->running_queue       = entries;
			this->running_entry_count = counter;
			break;
		case BPSC_JOB_QUEUE_STATUS_WAITING:
			if(this->waiting_queue)
				bpfree(this->waiting_queue);
			this->waiting_queue       = entries;
			this->waiting_entry_count = counter;
			break;
		default:
			return ERR_FAILURE;
	}
	this->mysqlDestroyStatement();
	if(sql)
		bpfree(sql);
	return ERR_SUCCESS;
}
BP_ERROR_T BPSC_SSHIntegrityChecker :: pollQueue ( BPSC_JOB_QUEUE_STATUS status , size_t min_limit , size_t max_limit ) { char * status_str = NULL ; switch ( status ) { case BPSC_JOB_QUEUE_STATUS_NEW : status_str = " " ; break ; case BPSC_JOB_QUEUE_STATUS_FINISHED : status_str = " " ; break ; case BPSC_JOB_QUEUE_STATUS_RUNNING : status_str = " " ; break ; case BPSC_JOB_QUEUE_STATUS_WAITING : status_str = " " ; break ; default : return ERR_FAILURE ; } char isql [ 2048 ] = { 0 } ; snprintf ( ( char * ) & isql , 2046 , " " , min_limit , max_limit ) ; char * sql = this -> mysqlAesPrepare ( ( char * ) & isql , NULL ) ; if ( ! sql ) return ERR_FAILURE ; this -> mysqlPrepareQuery ( sql ) ; this -> mysqlAddParameter ( MYSQL_TYPE_STRING , status_str , bpstrlen ( status_str ) ) ; this -> mysqlBindParameters ( ) ; size_t job_id = 0 ; size_t config_id = 0 ; char job_status [ 1024 ] = { 0 } ; this -> mysqlAddResult ( MYSQL_TYPE_LONG , ( char * ) & job_id , sizeof ( job_id ) ) ; this -> mysqlAddResult ( MYSQL_TYPE_LONG , ( char * ) & config_id , sizeof ( config_id ) ) ; this -> mysqlAddResult ( MYSQL_TYPE_STRING , ( char * ) & job_status , sizeof ( job_status ) - 1 ) ; this -> mysqlBindResults ( ) ; this -> mysqlExecuteStatement ( ) ; this -> mysqlStoreResults ( ) ; size_t counter = 0 ; P_BPSC_JOB_QUEUE_ENTRY entries = NULL ; while ( this -> mysqlFetchResult ( ) ) { counter ++ ; entries = ( P_BPSC_JOB_QUEUE_ENTRY ) bprealloc ( entries , sizeof ( BPSC_JOB_QUEUE_ENTRY ) * counter ) ; memset ( ( char * ) & entries [ counter - 1 ] , 0x00 , sizeof ( BPSC_JOB_QUEUE_ENTRY ) ) ; entries [ counter - 1 ] . job_id = job_id ; entries [ counter - 1 ] . config_id = config_id ; snprintf ( ( char * ) & entries [ counter - 1 ] . status , sizeof ( entries [ counter - 1 ] . status ) - 1 , " " , ( char * ) & job_status ) ; } switch ( status ) { case BPSC_JOB_QUEUE_STATUS_NEW : if ( this -> new_queue ) bpfree ( this -> new_queue ) ; this -> new_queue = entries ; this -> new_entry_count = counter ; break ; case BPSC_JOB_QUEUE_STATUS_FINISHED : if ( this -> finished_queue ) bpfree ( this -> finished_queue ) ; this -> finished_queue = entries ; this -> finished_entry_count = counter ; break ; case BPSC_JOB_QUEUE_STATUS_RUNNING : if ( this -> running_queue ) bpfree ( this -> running_queue ) ; this -> running_queue = entries ; this -> running_entry_count = counter ; break ; case BPSC_JOB_QUEUE_STATUS_WAITING : if ( this -> waiting_queue ) bpfree ( this -> waiting_queue ) ; this -> waiting_queue = entries ; this -> waiting_entry_count = counter ; break ; default : return ERR_FAILURE ; } this -> mysqlDestroyStatement ( ) ; if ( sql ) bpfree ( sql ) ; return ERR_SUCCESS ; }
polls a table in the database looking for jobs based on a status code
polls a table in the database looking for jobs based on a status code
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	 * %%%%%%%% Lookup Queue Data %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	 * %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ // base sql (limits are dynamic %u's) // create encrypted sql (must be bpfree'd) // prepare the encrypted mysql query // set parameters for lookup (bind prepare) // create result reciept variables // set result parameters // bind parameters // execute query // store results locally // variables required for data retrieval // fetch the results // increment and bprealloc the data pointer // zero out new memory // assign variables to memory // store job status in local buffer /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	 * %%%%%%%% Lookup Host Configurations For Queue %%%%%%%%%%%%
	 * %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ // now set pointers in class/free old pointers // shouldn't ever trigger this // destroy/free memory // return indicating success