Optim Data Privacy Providers  11.3.0
 All Data Structures Files Functions Variables Macros Groups Pages
Example for Provider_Service()

In the following example, the source data for Hash Service Provider is read from a CSV file, the list of rows is created and sent to the Service Provider.

//Clear the DP_ROWSET_DEF structure
memset(&rowSet, 0, sizeof(DP_ROWSET_DEF));
//Initialize the DP_ROWSET_DEF structure
//Set pRow to point to the address of the first element in the list of Row Defines
pRow = &rowSet.pRowDefine;
//Set piRows to point to the address of the rowSet count
piRows = &rowSet.iCount;
//Open the source CSV data file containing the HASH source data
fin = fopen(&SourceFilePath[0], "r");
iCnt = 0; //Set row count to zero

Loop through each line of the source CSV file creating the field data for each row.

Loop BEGIN

Here the rowSet is created as a List of rows and not as an Array. An application can also allocate a fixed size array of DP_ROW_DEF structures, fill it with data and pass it to Provider_Service.

//Allocate memory for the Row Define
(*pRow) = (DP_ROW_DEF *) malloc(sizeof(DP_ROW_DEF));
if(NULL == (*pRow))
{
printf("Failed to allocate memory for the row");
goto CleanRowSet;
}
//Clear the allocated memory for the Row Define
memset(*pRow, 0, sizeof(DP_ROW_DEF));
//Allocate memory for the source data field
pData = (DP_FIELD_DATA_DEF *) malloc(sizeof(DP_FIELD_DATA_DEF));
if(NULL == pData)
{
printf("Failed to allocate memory for pData");
goto CleanRowSet;
}
//Clear the allocated memory for the data field
memset(pData, 0, sizeof(DP_FIELD_DATA_DEF));
//Set the size of source data buffer
pData->iSrcBufLen = sizeof(int); //Source is 4 byte Integer
//Allocate memory for the source integer
pData->pSrcBuf = (unsigned char *) malloc(pData->iSrcBufLen);
if(NULL == pData->pSrcBuf)
{
printf("Failed to allocate memory for source buffer");
goto CleanRowSet;
}
//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 data field
(*pRow)->pFldDataDefine = pData;
//In this example the masked value will be returned in the source buffer of the destination column
//which was specified during Provider_Init() using parameter ODPP_OPR_HASH_DEST_COL and member
//bCopyToDest of the Service Definition was set to FALSE
//Allocate memory for the destination 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 CleanRowSet;
}
//Clear the allocated memory for the data field
memset(pData, 0, sizeof(DP_FIELD_DATA_DEF));
//Destination is an unsigned short value
pData->iSrcBufLen = sizeof(unsigned short);
//Allocate memory for the destination value
pData->pSrcBuf = (unsigned char *) malloc(pData->iSrcBufLen);
if(NULL == pData->pSrcBuf)
{
printf("Failed to allocate memory for source buffer");
goto CleanRowSet;
}
//Clear the allocated memory
memset(pData->pSrcBuf, 0, pData->iSrcBufLen);
//Add the destination data field to the list of fields
(*pRow)->pFldDataDefine->pNext = pData;
//Set the field count to 2 since the row consists of two columns
(*pRow)->sCount = 2;
//Increment the row count
iCnt++;
//Move to the next row in the list and continue the loop to create the list of rows
pRow = &(*pRow)->pNext;

Loop END

After the rowSet has been created invoke the Provider to mask the source data

//Close the source CSV file
fclose(fin);
//Set the count of rows in the rowSet
*piRows = iCnt;
//Set sMethod to the default
//Invoke the Service Provider
retVal = Provider_Service(iSvcToken, sMethod, NULL, &rowSet);
if(ODPPSUCCESS != retVal)
{
printf("Provider service failed %d", retVal);
goto CleanRowSet;
}

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

//Free the memory allocated in the rowSet
CleanRowSet:
//Pointer to the rowSet
pRowSet = &rowSet;
//Set pCurRow to point to the first Row Define
pCurRow = pRowSet->pRowDefine;
for(i = 0; ((i < pRowSet->iCount) && (NULL != pCurRow)); i++)
{
//pPrevRow points to the current row
pPrevRow = pCurRow;
//Set pData to point to the first data field
pData = pCurRow->pFldDataDefine;
for(j = 0; ((j < pCurRow->sCount) && (NULL != pData)); j++)
{
//pPrev points to the current data field
pPrev = pData;
if(pData->pSrcBuf != NULL)
free(pData->pSrcBuf); //Free the source buffer
if(pData->pDstBuf != NULL)
free(pData->pDstBuf); //Free the destination buffer
pData = pData->pNext; //Move to the next data field
free(pPrev); //Free the previous data field
}
//Move to the next row
pCurRow = pCurRow->pNext;
//Free the previous row
free(pPrevRow);
}
//Free the memory allocated in the Service Definition
CleanSVCDef:
for(i = 0; i < OPERANDS_MAX_SIZE; i++)
{
if(NULL != Operands[i].PV.pWC->pParmVal)
{
// Free the memory allocated for the Operand value
free(Operands[i].PV.pWC->pParmVal);
Operands[i].PV.pWC->pParmVal = NULL;
}
}
for(i = 0; i < MAX_COLUMNS; i++)
{
if(NULL != FldDef[i].CN.pWC->pColName)
{
//Free the memory allocated for the column name buffer
free(FldDef[i].CN.pWC->pColName);
FldDef[i].CN.pWC->pColName = NULL;
}
}
return retVal; //Return the error code