Optim Data Privacy Providers  11.7.0
 All Data Structures Files Functions Variables Macros Groups Pages
Example for ODPP_OPR_LKP_NOT_FOUND_REPLACEMENT_ROW

In the following example, the user supplied replacement values are read from a CSV file, A Row is created containing these values and assign to pUserVal member of DP_INIT_OP_DEF.

DP_ROW_DEF *pRow = NULL; //Pointer to the row
DP_FIELD_DATA_DEF *pData = NULL; //Pointer to the replacement data field
//Open the source CSV data file containing the user supplied replacement data values
fin = fopen(&SourceFilePath[0], "r");

Create a row and chain of replacement data fields. Assign the values read from CSV file to data fields and pass it to Provider_Init() using pUserVal member of DP_INIT_OP_DEF.

//Allocate memory for the Row
pRow = (DP_ROW_DEF *) malloc(sizeof(DP_ROW_DEF));
if(NULL == (*pRow)) //Check if memory was allocated successfully
{
printf("Failed to allocate memory for the row");
goto CleanRowDef;
}
//Clear the allocated memory for the Row Define
memset(*pRow, 0, sizeof(DP_ROW_DEF));
//Assume there are 2 replacement data fields
//Allocate memory for the first replacement data field
pData = (DP_FIELD_DATA_DEF *) malloc(sizeof(DP_FIELD_DATA_DEF));
if(NULL == pData) //Check if memory was allocated successfully
{
printf("Failed to allocate memory for Data field");
goto CleanRowDef;
}
//Clear the allocated memory for the data field
memset(pData, 0, sizeof(DP_FIELD_DATA_DEF));
//It is mandatory to provide the size of the pSrcBuf buffer, in bytes
//first replacement column holds integer value
pData->iSrcBufLen = sizeof(int);
//Allocate memory for the replacement value
pData->pSrcBuf = (unsigned char *) malloc(pData->iSrcBufLen);
if(NULL == pData->pSrcBuf) //Check if memory was allocated successfully
{
printf("Failed to allocate memory for source buffer");
goto CleanRowDef;
}
//Clear the allocated memory
memset(pData->pSrcBuf, 0, pData->iSrcBufLen);
//Convert the value read from the CSV file to INTEGER data type and store it in pData->pSrcBuf
//Copy the pData pointer to the replacement data field
pRow->pFldDataDefine = pData;
//Allocate memory for the second replacement data field
pData = (DP_FIELD_DATA_DEF *) malloc(sizeof(DP_FIELD_DATA_DEF));
if(NULL == pData) //Check if memory was allocated successfully
{
printf("Failed to allocate memory for pData");
goto CleanRowDef;
}
//Clear the allocated memory for the data field
memset(pData, 0, sizeof(DP_FIELD_DATA_DEF));
//second replacement column holds unsigned short value
pData->iSrcBufLen = sizeof(unsigned short);
//Allocate memory for the replacement value
pData->pSrcBuf = (unsigned char *) malloc(pData->iSrcBufLen);
if(NULL == pData->pSrcBuf) //Check if memory was allocated successfully
{
printf("Failed to allocate memory for source buffer");
goto CleanRowDef;
}
//Clear the allocated memory
memset(pData->pSrcBuf, 0, pData->iSrcBufLen);
//Convert the value read from the CSV file to unsigned short data type and store it in pData->pSrcBuf
//Add the data field to the list of replacement data fields
pRow->pFldDataDefine->pNext = pData;
//Close the source CSV file
fclose(fin);

After the row containing replacement data values has been created, pass it to the Provider_Init() using pUserVal member of DP_INIT_OP_DEF. Assume all required operands for Lookup Service provider are provided to DP_INIT_OP_DEF, refer Provider_Init() example for more detail.

//Parameter to provide user supplied replacement values for NOT FOUND rows
InitParameters[6].usParameterID = ODPP_OPR_LKP_NOT_FOUND_REPLACEMENT_ROW;
//Set the subtype to use pUserVal
InitParameters[6].iValueSubType = 10; // Any integer value other than PARAM_VAL_NUM, PARAM_VAL_WC, PARAM_VAL_MC, PARAM_VAL_NONE
//Assign the row pointer containing replacement values for replacement columns
InitParameters[6].pUserVal = pRow;

Free the memory that has been allocated if an error occurred.

//Free the memory allocated in the pRowDef
CleanRowDef:
if(pRowDef != NULL)
{
pDpFldDataDef = pRowDef->pFldDataDefine;
while(pDpFldDataDef != NULL)
{
pPrevDataDef = pDpFldDataDef;
if(pPrevDataDef->pSrcBuf != NULL)
free(pPrevDataDef->pSrcBuf);
pDpFldDataDef = pDpFldDataDef->pNext;
free(pPrevDataDef);
}
pDpFldDataDef = NULL;
free(pRowDef);
pRowDefLkp = NULL;
}