// SearchDLL.cpp : Defines the exported functions for the Identity Finder client application. // Copyright 2023, Spirion LLC All Rights Reserved #include "stdafx.h" #include #include #include #include "SearchItemData.h" /* Define the custom name, result type, and icon index CUSTOM_SEARCH_NAME - The custom name that will be displayed in the Identity Finder client and on the console. Specify the name of the new search item by changing "Custom Identity Type" to something of your choosing This will appear in the results as the "Identity Type" For example "Customer ID", "Student ID", or "Medical Record Number" RESULT_TYPE - The unique number between 12001 and 14000 that is mapped on the console to this custom search DLL */ #define CUSTOM_SEARCH_NAME _T("DEA") #define RESULT_TYPE 12681 using namespace std; extern "C" __declspec(dllexport) const TCHAR * GetDisplayName(void) { return(CUSTOM_SEARCH_NAME); } extern "C" __declspec(dllexport) unsigned int GetResultType(void) { return(RESULT_TYPE); } extern "C" __declspec(dllexport) void GetSearchItemData(SearchItemData * &pData) { /*********************************************************/ /****************** Begin Search Item ********************/ /* Create a new Search Item - this line should not be edited */ pData = new SearchItemData(); /* The custom search name, icon index, and result type will be set below based on the above settings - these lines should not be edited */ pData->searchInfo.displayName = CUSTOM_SEARCH_NAME; pData->resultType = RESULT_TYPE; /* Specify the base regular expression or keyword on which to match Regular Expression: Use the Boost Perl regular express syntax: http://www.boost.org/doc/libs/1_45_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html Be sure to escape any special/reservered characters For example, if your regular expression is 3 digits followed by dash followed by 3 digits: \d{3}\-\d{3} you must escape the \ character by preceeding it with a \ so you end up with: \\d{3}\\-\\d{3} To specify your own regular expression, replace "\\d{3}\\-\\d{2}\\-\\d{4}-\\d{1}" with your own pattern The expression below will match zero or more whitespace characters followed by 3 digits followed by a dash followed by 2 digits followed by a dash followed by 4 digits followed by a dash followed by 1 digit Keyword: You can also specify a keyword on which to match, such as "Patient Locator" or "Invoice" This allows you to find all locations that contain these keywords. For instance, in situations where you would like to find all files that contain specific keywords for later follow-up */ pData->data = _T("\\b\\w{2}\\d{7}\\b"); /* Specify the type for the search item: For a regular expression, use type 1 For a simple keyword, use type 2 */ pData->dataType = 1; /******************* End Search Item *********************/ /*********************************************************/ return; } extern "C" __declspec(dllexport) void DeleteSearchItemData(SearchItemData * pData) { /* This function serves as the destructor for the search item and should not be edited */ if (NULL != pData) { delete pData; } } extern "C" __declspec(dllexport) bool DoTest(const wstring & x, const wstring * fileDataPtr) { /* A tester is an optional function that allows you to perform validation on the pattern that was matched by the regular expression The 2 input parameters are x and fileDataPtr: x: this string holds the match data (whatever matched in the regular expression) fileDataPtr: this string is a pointer to the entire contents of the location (for example, the file) in which the match was found. This pointer allows you to access the entire location to test for contextual information such as proximate keywords. The return value is true or false: true: the string x passed the test and should be considered a match false: the string x failed the test and should be discarded The tester is executed before the cleaner */ /* For example, if we would like to require that the sum of the first 3 digits is less than 10, then we implement that as follows: */ try { //If nothing in x then just return false if (x.empty() || x == _T("\0")) { return(false); } wstring answer; //Get just the digit characters //wstring allowedChars = _T("0123456789"); for (wstring::size_type i = 0; i < x.length(); i++) { if (x.at(i) != wstring::npos) { answer += x.at(i); } } //if (answer.size() < 3) { return(false); } int totalOne = 0; int totalTwo = 0; for (int i = 2; i < answer.size() - 1; i++) { if (i % 2 == 0) { totalOne += answer[i] - _T('0'); } else { totalTwo += answer[i] - _T('0'); } } totalTwo *= 2; const int totalTotal = totalOne + totalTwo; const int last = totalTotal % 10; if (last != answer[answer.size() - 1] - _T('0')) { return false; } } catch (...) { //the tester code is wrong so we'll fall through and allow a true return so we don't remove results that could be correct } return (true); } extern "C" __declspec(dllexport) bool DoTestEx(const wstring & x, const wstring * fileDataPtr, wstring::size_type location) { /* A tester is an optional function that allows you to perform validation on the pattern that was matched by the regular expression The 2 input parameters are x and fileDataPtr: x: this string holds the match data (whatever matched in the regular expression) fileDataPtr: this string is a pointer to the entire contents of the location (for example, the file) in which the match was found. This pointer allows you to access the entire location to test for contextual information such as proximate keywords. location: location of the start of the match in the file data pointer The return value is true or false: true: the string x passed the test and should be considered a match false: the string x failed the test and should be discarded The tester is executed before the cleaner */ /* For example, if we would like to require that the sum of the first 3 digits is less than 10, then we implement that as follows: */ try { //If nothing in x then just return false if (x.empty() || x == _T("\0")) { return(false); } //Get just the digit characters wstring answer; //Get just the digit characters //wstring allowedChars = _T("0123456789"); for (wstring::size_type i = 0; i < x.length(); i++) { if (x.at(i) != wstring::npos) { answer += x.at(i); } } //if (answer.size() < 3) { return(false); } int totalOne = 0; int totalTwo = 0; for (int i = 2; i < answer.size() - 1; i++) { if (i % 2 == 0) { totalOne += answer[i] - _T('0'); } else { totalTwo += answer[i] - _T('0'); } } totalTwo *= 2; const int totalTotal = totalOne + totalTwo; const int last = totalTotal % 10; if (last != answer[answer.size() - 1] - _T('0')) { return false; } } catch (...) { //the tester code is wrong so we'll fall through and allow a true return so we don't remove results that could be correct } return (true); } extern "C" __declspec(dllexport) bool Clean(const wstring & x, wstring * &result) { /* A cleaner is an optional function that allows you to manipulate the string that was matched by the regular expression. The input parameters are: x: this string holds the match data (whatever matched in the regular expression) result: this is a string pointer passed by reference that will then become the match data */ try { /* Clear the return value answer */ wstring answer; result = NULL; /* For example, in our regular expression above, the first characters can be any number of whitespace characters, we may wish to strip these off so they are not shown as part of the match in the results */ //wstring allowedChars = _T("0123456789-"); for (wstring::size_type i = 0; i < x.length(); i++) { if (x.at(i) != wstring::npos) { answer += x.at(i); } } result = new wstring(answer); } catch (...) { //the cleaner failed due to invalid cleaner code that threw an exception, the caller will ignore the results return(false); } return (result != NULL); } extern "C" __declspec(dllexport) bool FreeCleanedResult(wstring * &result) { /* The FreeCleanedResult function is used to free memory allocated during the clean function by the DLL. This function is automatically called and must not be altered. */ bool answer = false; try { if (result != NULL) { delete result; result = NULL; } answer = true; } catch (...) { } return(answer); }