library/src/blockclass/BP-BlockClass.cc
// attempt to extract emails from memory buffer.This
// routine will use this->httpSession data if no buffer is passed in)
attempt to extract emails from memory buffer.This
routine will use this->httpSession data if no buffer is passed in)
attempt to extract emails from memory buffer . This routine will use this - > httpSession data if no buffer is passed in )
BP_ERROR_T Block::extractEmailsFromPREGSearch
(
		char * buff_search,
		size_t buff_len
)
{
	if(!this->mysqlSession)
		return ERR_FAILURE;
	if(!buff_search && !buff_len)
	{
		if(!this->httpSession)
			return ERR_FAILURE;
		if(!this->httpSession->page)
			return ERR_FAILURE;
		if(!this->httpSession->page->page_data)
			return ERR_FAILURE;
		if(!this->httpSession->page->page_data_size)
			return ERR_FAILURE;
		buff_search = this->httpSession->page->page_data;
		buff_len    = this->httpSession->page->page_data_size;
	}
 	char * regexp = "[\\w-]+(?:\\.[\\w-]+)*@(?:[\\w-]+\\.)+[a-zA-Z]{2,7}";
	BP_REGEX_MATCH_INFO match_info = {0};
	size_t matched = BP_MatchRegularExpressionPCRE
	(
		buff_search,
		buff_len,
		regexp,
		0,
		1024,
		&match_info,
		true
	);
	if(matched == ERR_SUCCESS)
	{
		size_t n = 0;
		for
		(
			;
			n < match_info.pcre_num_matched;
			n++
		)
		{
			size_t len = bpstrlen(match_info.preg_matches[n].matched_string);
			if(!BP_StringIsReasonablePrintableString(match_info.preg_matches[n].matched_string, len, BP_FALSE, BP_FALSE))
				continue;
			if(!isalpha(match_info.preg_matches[n].matched_string[len-1]))
				match_info.preg_matches[n].matched_string[len-1] = '\0';
			this->insertDiscoveredEmail(match_info.preg_matches[n].matched_string);
		}
	}
	BP_DestroyRegexpMatchInfo(&match_info);
	return ERR_SUCCESS;
}
BP_ERROR_T Block :: extractEmailsFromPREGSearch ( char * buff_search , size_t buff_len ) { if ( ! this -> mysqlSession ) return ERR_FAILURE ; if ( ! buff_search && ! buff_len ) { if ( ! this -> httpSession ) return ERR_FAILURE ; if ( ! this -> httpSession -> page ) return ERR_FAILURE ; if ( ! this -> httpSession -> page -> page_data ) return ERR_FAILURE ; if ( ! this -> httpSession -> page -> page_data_size ) return ERR_FAILURE ; buff_search = this -> httpSession -> page -> page_data ; buff_len = this -> httpSession -> page -> page_data_size ; } char * regexp = " \\ \\ \\ \\ \\ " ; BP_REGEX_MATCH_INFO match_info = { 0 } ; size_t matched = BP_MatchRegularExpressionPCRE ( buff_search , buff_len , regexp , 0 , 1024 , & match_info , true ) ; if ( matched == ERR_SUCCESS ) { size_t n = 0 ; for ( ; n < match_info . pcre_num_matched ; n ++ ) { size_t len = bpstrlen ( match_info . preg_matches [ n ] . matched_string ) ; if ( ! BP_StringIsReasonablePrintableString ( match_info . preg_matches [ n ] . matched_string , len , BP_FALSE , BP_FALSE ) ) continue ; if ( ! isalpha ( match_info . preg_matches [ n ] . matched_string [ len - 1 ] ) ) match_info . preg_matches [ n ] . matched_string [ len - 1 ] = ' \0 ' ; this -> insertDiscoveredEmail ( match_info . preg_matches [ n ] . matched_string ) ; } } BP_DestroyRegexpMatchInfo ( & match_info ) ; return ERR_SUCCESS ; }
attempt to extract emails from memory buffer.This
routine will use this->httpSession data if no buffer is passed in)
attempt to extract emails from memory buffer . This routine will use this - > httpSession data if no buffer is passed in )
// ensure we have a mysql session // if we don't have a buffer to search, we try to set buffer from // http session. // run session checks // set the search from input if not provided already // loose url grabbing regexp (can result in false positives, but not very often, treat // results from this regexp with regard to that taint effect) // create zeroed out inout structure // get matches // if we have a match we can attempt to insert the email // walk matches and attempt to insert // calculate length of matched string // ensure string is reasonable printable string // basic check // insert email // clear out match info // return indicating success