library/src/blockclass/BP-BlockClass.cc
// extract match data from JIT match set
extract match data from JIT match set
extract match data from JIT match set
BP_ERROR_T Block::extractDataFromJITMatches()
{
	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;
	char * regexp = NULL;
	for
	(
			size_t x = 0;
			x < this->web_request_jit_match_n;
			x++
	)
	{
		regexp = (char *) &this->web_request_jit_match_set[x].regexp;
		BP_REGEX_MATCH_INFO match_info = {0};
		size_t matched = BP_MatchRegularExpressionPCRE
		(
				this->httpSession->page->page_data,
				this->httpSession->page->page_data_size,
				regexp,
				PCRE_CASELESS | PCRE_MULTILINE,
				256,
				(P_BP_REGEX_MATCH_INFO )&match_info,
				true
		);
		if(matched == ERR_SUCCESS)
		{
			size_t n = 0;
			for(; n < match_info.pcre_num_matched; n++)
			{
				if(!match_info.preg_matches[n].matched_string)
					continue;
				size_t len = match_info.preg_matches[n].match_len;
				if(!isalpha(match_info.preg_matches[n].matched_string[len-1]))
					match_info.preg_matches[n].matched_string[len-1] = '\0';
				this->insertWebJITExpressionMatchDelayed
				(
						this->web_request_jit_match_set[x].group_id,
						this->web_request_jit_match_set[x].id,
						this->web_result_id,
						match_info.preg_matches[n].matched_string,
						match_info.preg_matches[n].match_len
				);
			}
		}
		BP_DestroyRegexpMatchInfo(&match_info);
	}
	this->flushWebJITExpressionMatchDelayedSQL();
	return ERR_SUCCESS;
}
BP_ERROR_T Block :: extractDataFromJITMatches ( ) { 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 ; char * regexp = NULL ; for ( size_t x = 0 ; x < this -> web_request_jit_match_n ; x ++ ) { regexp = ( char * ) & this -> web_request_jit_match_set [ x ] . regexp ; BP_REGEX_MATCH_INFO match_info = { 0 } ; size_t matched = BP_MatchRegularExpressionPCRE ( this -> httpSession -> page -> page_data , this -> httpSession -> page -> page_data_size , regexp , PCRE_CASELESS | PCRE_MULTILINE , 256 , ( P_BP_REGEX_MATCH_INFO ) & match_info , true ) ; if ( matched == ERR_SUCCESS ) { size_t n = 0 ; for ( ; n < match_info . pcre_num_matched ; n ++ ) { if ( ! match_info . preg_matches [ n ] . matched_string ) continue ; size_t len = match_info . preg_matches [ n ] . match_len ; if ( ! isalpha ( match_info . preg_matches [ n ] . matched_string [ len - 1 ] ) ) match_info . preg_matches [ n ] . matched_string [ len - 1 ] = ' \0 ' ; this -> insertWebJITExpressionMatchDelayed ( this -> web_request_jit_match_set [ x ] . group_id , this -> web_request_jit_match_set [ x ] . id , this -> web_result_id , match_info . preg_matches [ n ] . matched_string , match_info . preg_matches [ n ] . match_len ) ; } } BP_DestroyRegexpMatchInfo ( & match_info ) ; } this -> flushWebJITExpressionMatchDelayedSQL ( ) ; return ERR_SUCCESS ; }
extract match data from JIT match set
extract match data from JIT match set
// NOTE: Don't use critical sections here.  The insert routines do it automatically on a more granular level. // set regular expression // create zeroed out inout structure // get matches // printf("\n Using regex: %s", regexp); // ensure we have a matched string // get match len // check len and null terminate if necessary // insert match here // clear out match info // flush db writes now // return indicating success