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

In the following example, the Service Provider performs the masking.

RETVAL retval = ODPPSUCCESS;
int iRowCount = 0; // To loop through all rows
int *piDstSize = NULL; // bytes of dest buffer
int *piOutLen = NULL; // Bytes of out data
short sMyColCnt = 0; // To hold column count
short sSrvMethod; // Masking method
short sLoopCol = 0; // to loop through src columns
unsigned char *pDstBuf = NULL; // Destination buffer value
unsigned char *pSrc1Buf = NULL;
unsigned char *pSrc2Buf = NULL;
DP_ROW_DEF *pRowDef = NULL; // contains rows
DP_FIELD_DATA_DEF *pData = NULL; // contains data
DP_MYCTRL_DEF *pMyCtrlBlk = NULL; //Service provider specific control block
DP_SRCCOL_DEF_X *pSrcCol = NULL;
int iSrcVal1 = 0;
int iSrcVal2 = 0;
int iResult = 0;
//Get the Service provider control block from framework control block
pMyCtrlBlk = (DP_MYCTRL_DEF*)pCtrlBlk->pExt;
if(NULL == pMyCtrlBlk)
{
//There is no provider control block allocated in framework
//control block. Capture the specific error code and return
retval = MY_ERR_MYCTRLBLK_NOT_FOUND;
return retval;
}
//Check if Rowset and dataset is empty, return if there is no record
if((pRowSet->iCount <= 0) || (pRowSet->pRowDefine == NULL))
{
// RowSet is empty,Capture the specific error and return
retval = MY_ERR_ROWSET_EMPTY;
return retval;
}
else
{
// Assign row list address to DP_ROW_DEF pointer
pRowDef = pRowSet->pRowDefine;
}
//Check if RowSet has enough data fields required for operation of service provider
sMyColCnt = pCtrlBlk->sSrcColCount + 1;//(Add 1 For destination column)
if(pRowDef->sCount < sMyColCnt)
{
// RowDef has less number of data fields than required
retval = MY_ERR_NOT_ENOUGH_DATA_BLOCKS;
return retval;
}
//Check if Source1, source2 indexes provided by the user are in range
if((pMyCtrlBlk->sSrc1ColIndex >= pRowDef->sCount) ||
(pMyCtrlBlk->sSrc2ColIndex >= pRowDef->sCount))
{
// Source column index is greater than number of column
retval = MY_ERR_SRCCOLIDX_EXCEEDS_ROWDEF_COLCOUNT;
return retval;
}
//Check if destination column index provided by the user is in range
if(pMyCtrlBlk->sDestColIndex >= pRowDef->sCount)
{
// Destination column index is greater than number of column
retval = MY_ERR_DSTCOLIDX_EXCEEDS_ROWDEF_COLCOUNT;
return retval;
}
// Check the method for masking
if(sMethod == ODPP_METHOD_DEFAULT)
{
sSrvMethod = pCtrlBlk->sMethod;
}
else if(sMethod == ODPP_METHOD_MASK ||
sMethod == ODPP_METHOD_RANDOM)
{
sSrvMethod = sMethod;
}
else
{
//Invalid MASK method provided
retval = MY_ERR_INVALID_METHOD;
return retval;
}
// Process each row in rowset
// Find the Destination Column data block pointer
pData = pRowDef->pFldDataDefine;
// Get the data block pointer for the supplied destination column
for(sLoopCol=0; sLoopCol < pMyCtrlBlk->sDestColIndex; sLoopCol++)
{
MOVENEXT(pData)
}
if(NULL == pData)
{
//Could not find the destination column data block for this row,
//there is no point to move ahead with this row so break
retval = MY_ERR_NO_DEST_DATA_COL;
goto OnRowError;
}
//Check the destination column buffer and check where to copy result
if(pCtrlBlk->bCopyToDest &&
(NULL == pData->pDstBuf || TRUE == pData->bDstNull))
{ //We were told to copy to destination buffer but destination
//buffer is NULL so error out
retval = MY_ERR_NULL_DEST_BUFFER;
goto OnRowError;
}
else if(!pCtrlBlk->bCopyToDest &&
(NULL == pData->pSrcBuf || TRUE == pData->bSrcNull))
{
//We were told to copy to source buffer but source
//buffer is NULL so error out
retval = MY_ERR_NULL_DEST_BUFFER;
goto OnRowError;
}
//Perform the operation
switch(pMyCtrlBlk->iOperator)
{
case PARAM_OPERATOR_ADD:
{
iResult = iSrcVal1 + iSrcVal2;
}
break;
default:
retval = MY_ERR_INVALID_OPERATOR;
goto OnRowError;
break;
}// End switch
//If bCopyToDest is TRUE then copy result in destination buffer.
//If bCopyToDest is FALSE then copy result in source buffer.
if(!pCtrlBlk->bCopyToDest)
{
// Return value in source buffer
pDstBuf = pData->pSrcBuf;
piDstSize = &pData->iSrcBufLen;
}
else
{
// Return value in destination buffer
pDstBuf = pData->pDstBuf;
piDstSize = &pData->iDstBufLen;
}
piOutLen = &pData->iOutBufLen;
// Convert the destination value to dest datatype
//Everything was success Reset the error codes for the Row
//and move to the next row
pData->iErrorCode = ODPPSUCCESS;
pRowDef->bHasError = FALSE;
// move to next row
MOVENEXT(pRowDef)
continue;
// Row encounter error, set the error code and move to next row
OnRowError:
if(NULL != pData)
{
pData->iErrorCode = retval;
}
pRowDef->bHasError = TRUE;
// Move to the next row
MOVENEXT(pRowDef)
}//End for(iRowCount = 0; iRowCount <= pRowSet->iCount; iRowCount++)
return ODPPSUCCESS;