library/src/blockclass/BP-BlockClass.cc
// This attempts to parse any number of entries and sort them out into
// insertable records in the database.
This attempts to parse any number of entries and sort them out into
insertable records in the database.
This attempts to parse any number of entries and sort them out into insertable records in the database .
BP_ERROR_T Block::addProxyDBEntriesFromGenericFormatProxyBuff
(
		char *file_containing_proxies_to_insert
)
{
	if(!this->mysqlSession)
		return ERR_FAILURE;
	BP_BLOCK_MARIADB_ENTER_CRITICAL_SECTION;
	if(!file_containing_proxies_to_insert)
		BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_FAILURE);
	if(!BP_StringIsReasonableForUnixEXT4Directory(file_containing_proxies_to_insert, BP_TRUE))
		BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_FAILURE);
	char * file_content = BP_FileGetContents(file_containing_proxies_to_insert);
	if(!file_content)
		BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_FAILURE);
	char ** exploded = BP_ExplodeBufferBin(file_content, bpstrlen(file_content), "\n", 1, 500000);
	if(!exploded)
		BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_FAILURE);
	size_t n = 0;
	for(; exploded[n]; n++)
	{
		if(!BP_StringIsReasonablePrintableString(exploded[n], bpstrlen(exploded[n]), BP_FALSE, BP_FALSE))
			continue;
		char ** split_buff = BP_SplitBuffer(exploded[n], ":");
		if(!split_buff)
			continue;
		size_t arr_n = BP_CountNullTerminatedPtrArray(split_buff);
		if(arr_n != 2)
		{
			BP_DestroyPointerArrayNullTerminated((void **) split_buff);
			continue;
		}
		char * host_name  = split_buff[0];
		char * port_ascii = split_buff[1];
		size_t port = strtoul(port_ascii, NULL, 10);
		this->addProxyDBEntry
		(
				2,
				0,
				host_name,
				port,
				NULL,
				NULL,
				NULL,
				1
		);
		BP_DestroyPointerArrayNullTerminated((void **) split_buff);
	}
	if(exploded)
		BP_DestroyPointerArrayNullTerminated((void **) exploded);
	BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_SUCCESS);
}
BP_ERROR_T Block :: addProxyDBEntriesFromGenericFormatProxyBuff ( char * file_containing_proxies_to_insert ) { if ( ! this -> mysqlSession ) return ERR_FAILURE ; BP_BLOCK_MARIADB_ENTER_CRITICAL_SECTION ; if ( ! file_containing_proxies_to_insert ) BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_FAILURE ) ; if ( ! BP_StringIsReasonableForUnixEXT4Directory ( file_containing_proxies_to_insert , BP_TRUE ) ) BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_FAILURE ) ; char * file_content = BP_FileGetContents ( file_containing_proxies_to_insert ) ; if ( ! file_content ) BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_FAILURE ) ; char * * exploded = BP_ExplodeBufferBin ( file_content , bpstrlen ( file_content ) , " \n " , 1 , 500000 ) ; if ( ! exploded ) BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_FAILURE ) ; size_t n = 0 ; for ( ; exploded [ n ] ; n ++ ) { if ( ! BP_StringIsReasonablePrintableString ( exploded [ n ] , bpstrlen ( exploded [ n ] ) , BP_FALSE , BP_FALSE ) ) continue ; char * * split_buff = BP_SplitBuffer ( exploded [ n ] , " " ) ; if ( ! split_buff ) continue ; size_t arr_n = BP_CountNullTerminatedPtrArray ( split_buff ) ; if ( arr_n != 2 ) { BP_DestroyPointerArrayNullTerminated ( ( void * * ) split_buff ) ; continue ; } char * host_name = split_buff [ 0 ] ; char * port_ascii = split_buff [ 1 ] ; size_t port = strtoul ( port_ascii , NULL , 10 ) ; this -> addProxyDBEntry ( 2 , 0 , host_name , port , NULL , NULL , NULL , 1 ) ; BP_DestroyPointerArrayNullTerminated ( ( void * * ) split_buff ) ; } if ( exploded ) BP_DestroyPointerArrayNullTerminated ( ( void * * ) exploded ) ; BP_BLOCK_MARIADB_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_SUCCESS ) ; }
This attempts to parse any number of entries and sort them out into
insertable records in the database.
This attempts to parse any number of entries and sort them out into insertable records in the database .
// this method requires a valid mysql session // enter critical section // attempt to retrieve file content // explode the file // ensure file was exploded ok // check string to make sure it's reasonable // split along colon // count split array indexes // destroy the split buffer // set host name and port // add proxy entry // destroy the split buffer // printf("\n LINE: %s", exploded[n]); // return indicating success