library/src/filesystem/BP-FilesystemRegistry.cc
// this sets a perl compatible regular expression policy for
// filesystem crawls.
this sets a perl compatible regular expression policy for
filesystem crawls.
this sets a perl compatible regular expression policy for filesystem crawls .
BP_ERROR_T BP_FSRegAddPregexPolicy
(
		P_BP_FSREG                fs_reg,
		BP_FSREG_PREG_POLICY_TYPE preg_policy_type,
		char *                    pregex
)
{
	if(!fs_reg)
		return ERR_FAILURE;
	if(!fs_reg->hreg)
		return ERR_FAILURE;
	if(!preg_policy_type)
		return ERR_FAILURE;
	if(!pregex)
		return ERR_FAILURE;
	if(!BP_StringIsReasonablePrintableString(pregex, bpstrlen(pregex), BP_FALSE, BP_FALSE))
		return ERR_FAILURE;
	BP_HASH_TABLE_ENTER_CRITICAL_SECTION(fs_reg->hreg);
	char ** regexp_set = NULL;
	size_t  regexp_n   = 0;
	switch(preg_policy_type)
	{
		case BP_FSREG_PREG_POLICY_TYPE_FNAME_MATCH:
			fs_reg->crawl_policies.preg_fname_policies = (char **) ht_realloc
			(
					fs_reg->hreg,
					fs_reg->crawl_policies.preg_fname_policies,
					(fs_reg->crawl_policies.preg_fname_policies_n + 2) * sizeof(char *)
			);
			fs_reg->crawl_policies.preg_fname_policies[fs_reg->crawl_policies.preg_fname_policies_n] = ht_strdup(fs_reg->hreg, pregex);
			fs_reg->crawl_policies.preg_fname_policies_n++;
			break;
		case BP_FSREG_PREG_POLICY_TYPE_PATHONLY_MATCH:
			fs_reg->crawl_policies.preg_pathonly_matching_policies = (char **) ht_realloc
			(
					fs_reg->hreg,
					fs_reg->crawl_policies.preg_pathonly_matching_policies,
					(fs_reg->crawl_policies.preg_pathonly_matching_policies_n + 2) * sizeof(char *)
			);
			fs_reg->crawl_policies.preg_pathonly_matching_policies[fs_reg->crawl_policies.preg_pathonly_matching_policies_n] = ht_strdup(fs_reg->hreg, pregex);
			fs_reg->crawl_policies.preg_pathonly_matching_policies_n++;
			break;
		case BP_FSREG_PREG_POLICY_TYPE_FULLPATH_MATCH:
			fs_reg->crawl_policies.preg_fullpath_matching_policies = (char **) ht_realloc
			(
					fs_reg->hreg,
					fs_reg->crawl_policies.preg_fullpath_matching_policies,
					(fs_reg->crawl_policies.preg_fullpath_matching_policies_n + 2) * sizeof(char *)
			);
			fs_reg->crawl_policies.preg_fullpath_matching_policies[fs_reg->crawl_policies.preg_fullpath_matching_policies_n] = ht_strdup(fs_reg->hreg, pregex);
			fs_reg->crawl_policies.preg_fullpath_matching_policies_n++;
			break;
		default:
			BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(fs_reg->hreg, ERR_FAILURE);
			break;
	}
	BP_HASH_TABLE_LEAVE_CRITICAL_SECTION(fs_reg->hreg);
	return ERR_SUCCESS;
}
BP_ERROR_T BP_FSRegAddPregexPolicy ( P_BP_FSREG fs_reg , BP_FSREG_PREG_POLICY_TYPE preg_policy_type , char * pregex ) { if ( ! fs_reg ) return ERR_FAILURE ; if ( ! fs_reg -> hreg ) return ERR_FAILURE ; if ( ! preg_policy_type ) return ERR_FAILURE ; if ( ! pregex ) return ERR_FAILURE ; if ( ! BP_StringIsReasonablePrintableString ( pregex , bpstrlen ( pregex ) , BP_FALSE , BP_FALSE ) ) return ERR_FAILURE ; BP_HASH_TABLE_ENTER_CRITICAL_SECTION ( fs_reg -> hreg ) ; char * * regexp_set = NULL ; size_t regexp_n = 0 ; switch ( preg_policy_type ) { case BP_FSREG_PREG_POLICY_TYPE_FNAME_MATCH : fs_reg -> crawl_policies . preg_fname_policies = ( char * * ) ht_realloc ( fs_reg -> hreg , fs_reg -> crawl_policies . preg_fname_policies , ( fs_reg -> crawl_policies . preg_fname_policies_n + 2 ) * sizeof ( char * ) ) ; fs_reg -> crawl_policies . preg_fname_policies [ fs_reg -> crawl_policies . preg_fname_policies_n ] = ht_strdup ( fs_reg -> hreg , pregex ) ; fs_reg -> crawl_policies . preg_fname_policies_n ++ ; break ; case BP_FSREG_PREG_POLICY_TYPE_PATHONLY_MATCH : fs_reg -> crawl_policies . preg_pathonly_matching_policies = ( char * * ) ht_realloc ( fs_reg -> hreg , fs_reg -> crawl_policies . preg_pathonly_matching_policies , ( fs_reg -> crawl_policies . preg_pathonly_matching_policies_n + 2 ) * sizeof ( char * ) ) ; fs_reg -> crawl_policies . preg_pathonly_matching_policies [ fs_reg -> crawl_policies . preg_pathonly_matching_policies_n ] = ht_strdup ( fs_reg -> hreg , pregex ) ; fs_reg -> crawl_policies . preg_pathonly_matching_policies_n ++ ; break ; case BP_FSREG_PREG_POLICY_TYPE_FULLPATH_MATCH : fs_reg -> crawl_policies . preg_fullpath_matching_policies = ( char * * ) ht_realloc ( fs_reg -> hreg , fs_reg -> crawl_policies . preg_fullpath_matching_policies , ( fs_reg -> crawl_policies . preg_fullpath_matching_policies_n + 2 ) * sizeof ( char * ) ) ; fs_reg -> crawl_policies . preg_fullpath_matching_policies [ fs_reg -> crawl_policies . preg_fullpath_matching_policies_n ] = ht_strdup ( fs_reg -> hreg , pregex ) ; fs_reg -> crawl_policies . preg_fullpath_matching_policies_n ++ ; break ; default : BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( fs_reg -> hreg , ERR_FAILURE ) ; break ; } BP_HASH_TABLE_LEAVE_CRITICAL_SECTION ( fs_reg -> hreg ) ; return ERR_SUCCESS ; }
this sets a perl compatible regular expression policy for
filesystem crawls.
this sets a perl compatible regular expression policy for filesystem crawls .
// basic null checks // ensure string is reasonable/printable // enter critical section // these hold the selected regexp set (based on type switch) // select set based on type // attempt to realloc policies // overwrite the fname data // attempt to realloc policies // overwrite the fname data // attempt to realloc policies // overwrite the fname data // exit immediately if we can't match a set // leave critical section // return indicating success