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

In the following example, the Hash Service Provider is initialized with a literal seed.

DP_SVC_DEF SvcDef; //Service Definition structure
DP_FIELD_DEF FldDef[MAX_COLUMNS]; //Array of DP_FIELD_DEF structures
DP_INIT_OP_DEF InitParameters[PARAMETER_MAX_SIZE]; //Array of DP_INIT_OP_DEF structures
DP_ROWSET_DEF rowSet; //RowSet which contains the rows to be masked
DP_ROW_DEF **pRow; //Pointer used to create the list of rows in rowSet
DP_FIELD_DATA_DEF *pData; //Pointer used to create the list of data fields
int iSvcToken; //Service Token
RETVAL retVal; //return code
short sMethod; //Method to use for masking
char Line[INPUT_LINE_MAX_SIZE]; //character buffer used to store the input value read from the CSV file
int *piRows = NULL; //Integer pointer to hold the row count in rowSet
int i = 0; //Counter
int j = 0; //Counter
int iLen = 0; //Length of the buffer
int iCnt = 0; //Count of rows in the rowSet
FILE *fin = NULL; //File handle for input CSV file
char PrvName[] = "HASH"; //Provider name in MBCS
DP_ROWSET_DEF *pRowSet = NULL; //RowSet pointer
DP_ROW_DEF *pCurRow = NULL; //Row pointer
DP_ROW_DEF *pPrevRow = NULL; //Row pointer
DP_FIELD_DATA_DEF *pPrev = NULL; //data field pointer
//Clear the Field Definition
memset(FldDef, 0, MAX_COLUMNS * sizeof(DP_FIELD_DEF));
//Clear the Parameter definition
memset(InitParameters, 0, PARAMETER_MAX_SIZE * sizeof(DP_INIT_OP_DEF));
//Clear the Service Definition
memset(&SvcDef, 0, sizeof(DP_SVC_DEF));
//Initialize the DP_FIELD_DEF structure
for(iTempCnt=0; iTempCnt < MAX_COLUMNS; iTempCnt++)
{
}
//Initialize the DP_INIT_OP_DEF structure
for(iTempCnt=0; iTempCnt < PARAMETER_MAX_SIZE; iTempCnt++)
{
INITIALIZE_ODPP_STRUCT(InitParameters[iTempCnt], DP_INIT_OP_DEF)
}
//Initialize the DP_SVC_DEF structure
//list of operands
// Set the parameter list to the Service Definition
SvcDef.pParams = &InitParameters[0];
//Set the field list to the field definition
SvcDef.pFldDef = &FldDef[0];
//Set this value to FALSE to return the masked value in the source buffer of the destination column
SvcDef.bCopyToDest = FALSE;
//Create the list of Field Defines
#ifndef USE_ODPP_MBCS_CHAR_CALLS
//For wide character (Unicode) format
//Column 1
//To indicate that column name is in wide character format and USE_ODPP_MBCS_CHAR_CALLS is not defined
FldDef[0].cSubType = 'W';
// Allocate the pWC struct
FldDef[0].CN.pWC = (DPFD_WC_SS *) malloc(sizeof(DPFD_WC_SS));
if(NULL == FldDef[0].CN.pWC)
{
printf("\nFailed to allocate pWC struct of DP_FIELD_DEF\n");
goto CleanSvcDef;
}
memset(FldDef[0].CN.pWC, 0, sizeof(DPFD_WC_SS));
//Code page
FldDef[0].iDataCodePage = 0;
//DBMS type
FldDef[0].cDataDBMSType = 0;
//Store the maximum size for column name buffer
FldDef[0].iColNameBytes = (MAX_COLNAME_SIZE + 1) * sizeof(ODPP_WCHAR);
//Allocate buffer for column name in wide character (Unicode) format
FldDef[0].CN.pWC->pColName = (ODPP_WCHAR *) malloc(FldDef[0].iColNameBytes);
if(NULL == FldDef[0].CN.pWC->pColName)
{
printf("\nFailed to allocate memory for Column name\n");
goto CleanSvcDef;
}
memset(FldDef[0].CN.pWC->pColName, 0, FldDef[0].iColNameBytes);
//Set the source column name in FldDef
wcscpy(FldDef[0].CN.pWC->pColName, L"SrcCol");
//Set the data type for the source column
FldDef[0].sDatatype = ODPPDATATYPE_INTEGER;
//Column 2
// To indicate that column name is in wide character(Unicode) format and USE_ODPP_MBCS_CHAR_CALLS is not defined
FldDef[1].cSubType = 'W';
//Allocate the pWC struct
FldDef[1].CN.pWC = (DPFD_WC_SS *) malloc(sizeof(DPFD_WC_SS));
if(NULL == FldDef[1].CN.pWC)
{
printf("\nFailed to allocate pWC struct of DP_FIELD_DEF\n");
goto CleanSvcDef;
}
memset(FldDef[1].CN.pWC, 0, sizeof(DPFD_WC_SS));
//code page
FldDef[1].iDataCodePage = 0;
//DBMS type
FldDef[1].cDataDBMSType = 0;
//Store the maximum size for column name buffer in bytes
FldDef[1].iColNameBytes = (MAX_COLNAME_SIZE + 1) * sizeof(ODPP_WCHAR);
// Allocate buffer for column name in wide character (Unicode) format
FldDef[1].CN.pWC->pColName = (ODPP_WCHAR *) malloc(FldDef[1].iColNameBytes);
if(NULL == FldDef[1].CN.pWC->pColName)
{
printf("\nFailed to allocate memory for Column name\n");
goto CleanSvcDef;
}
memset(FldDef[1].CN.pWC->pColName, 0, FldDef[1].iColNameBytes);
//Set the destination column name in FldDef
wcscpy(FldDef[1].CN.pWC->pColName, L"DestCol");
//Set the data type for the destination column
FldDef[1].sDatatype = ODPPDATATYPE_USMALLINT;
#else
//For mixed character (SBCS/MBCS) format
//Column 1
//To indicate that column name is in mixed character (SBCS/MBCS) format and USE_ODPP_MBCS_CHAR_CALLS is defined
FldDef[0].cSubType = 'M';
//Allocate the pMC struct
FldDef[0].CN.pMC = (DPFD_MC_SS *) malloc(sizeof(DPFD_MC_SS));
if(NULL == FldDef[0].CN.pMC)
{
printf("\nFailed to allocate pMC struct of DP_FIELD_DEF\n");
return ODPPFAILURE;
}
//Clear the DPFD_MC_SS structure
memset(FldDef[0].CN.pMC, 0, sizeof(DPFD_MC_SS));
//For system default codepage
FldDef[0].iDataCodePage = -1;
//DBMS type code
FldDef[0].cDataDBMSType = RDB_NONE;
//Store the maximum size for column name buffer in bytes
FldDef[0].iColNameBytes = (MAX_COLNAME_SIZE + 1) * ODPP_MBCS_CHAR_BYTES;
//Allocate buffer for column name is in mixed character (SBCS/MBCS) format
FldDef[0].CN.pMC->pColName = (char *) malloc(FldDef[0].iColNameBytes);
if(NULL == FldDef[0].CN.pMC->pColName)
{
printf("\nFailed to allocate memory for Column name\n");
goto CleanSvcDef;
}
memset(FldDef[0].CN.pMC->pColName, 0, FldDef[0].iColNameBytes);
//Set the source column name in FldDef
strcpy(FldDef[0].CN.pMC->pColName, "SrcCol");
//Set the data type for the source column
FldDef[0].sDatatype = ODPPDATATYPE_INTEGER;
//Column 2
//To indicate that column name is mixed character (SBCS/MBCS) format and USE_ODPP_MBCS_CHAR_CALLS is defined
FldDef[1].cSubType = 'M';
//Allocate the pMC struct
FldDef[1].CN.pMC = (DPFD_MC_SS *) malloc(sizeof(DPFD_MC_SS));
if(NULL == FldDef[1].CN.pMC)
{
printf("\nFailed to allocate pMC struct of DP_FIELD_DEF\n");
goto CleanSvcDef;
}
//Clear the DPFD_MC_SS structure
memset(FldDef[1].CN.pMC, 0, sizeof(DPFD_MC_SS));
//For system default codepage
FldDef[1].iDataCodePage = -1;
//DBMS type code
FldDef[1].cDataDBMSType = RDB_NONE;
//Store the maximum size for column name buffer in bytes
FldDef[1].iColNameBytes = (MAX_COLNAME_SIZE + 1) * ODPP_MBCS_CHAR_BYTES ;
//Allocate buffer for column name in mixed character (SBCS/MBCS) format
FldDef[1].CN.pMC->pColName = (char *) malloc(FldDef[1].iColNameBytes);
if(NULL == FldDef[1].CN.pMC->pColName)
{
printf("\nFailed to allocate memory for Column name\n");
goto CleanSvcDef;
}
memset(FldDef[1].CN.pMC->pColName, 0, FldDef[1].iColNameBytes);
//Set the destination column name in FldDef
strcpy(FldDef[1].CN.pMC->pColName, "DestCol");
//Set the data type for the destination column
FldDef[1].sDatatype = ODPPDATATYPE_USMALLINT;
#endif
//Set the Field count to 2 since two columns are being supplied.
SvcDef.sFldCount = 2;
//Create the list of Operands
//Parameter 1
//Switch is not needed but it is a mandatory operand so set it to ODPP_OPR_SWITCH_NA (Switch Not Applicable)
InitParameters[0].usParameterID = ODPP_OPR_SWITCH_NA;
//To indicate that current parameter does not hold any value.
InitParameters[0].iValueSubType = PARAM_VAL_NONE;
#ifndef USE_ODPP_MBCS_CHAR_CALLS
//For wide character (Unicode) format
//Parameter 2
//ODPP_OPR_SOURCE_COLNAME, ODPP_OPR_SOURCE_COLINDEX and ODPP_OPR_SOURCE_COLS are mutually
//exclusive and any one of them can be provided
InitParameters[1].usParameterID = ODPP_OPR_SOURCE_COLS;
//To indicate that current parameter will hold wide character (Unicode)string value
InitParameters[1].iValueBufBytes = PARAM_VAL_WC;
//Allocate the pWC struct DPPRM_VAL_WC_SS
InitParameters[1].PV.pWC = (DPPRM_VAL_WC_SS *) malloc(sizeof(DPPRM_VAL_WC_SS));
if(NULL == InitParameters[1].PV.pWC)
{
printf("Failed to allocate memory for pWC->DPPRM_VAL_WC_SS");
goto CleanSvcDef;
}
memset(InitParameters[1].PV.pWC, 0, sizeof(DPPRM_VAL_WC_SS));
iLen = (int)wcslen(FldDef[0].CN.pWC->pColName); //Get length of source column name
//Set the size of the parameter value buffer in bytes
InitParameters[1].iValueBufBytes = (iLen + 1) * sizeof(ODPP_WCHAR);
//Allocate memory for the source column name in wide character (Unicode) format
InitParameters[1].PV.pWC->pParamVal = (ODPP_WCHAR *) malloc(InitParameters[1].iValueBufBytes);
if(NULL == InitParameters[1].PV.pWC->pParamVal)
{
printf("Failed to allocate memory for parameter value pParamVal");
goto CleanSvcDef;
}
memset(InitParameters[1].PV.pWC->pParamVal, 0, (iLen +1));
//Copy source column name from FldDef[0].CN.pWC->pColName to pParmVal
wcsncpy(InitParameters[1].PV.pWC->pParamVal, FldDef[0].CN.pWC->pColName, iLen);
//NULL terminate the pParmVal buffer
InitParameters[1].PV.pWC->pParamVal[iLen] = '\0';
//ODPP_OPR_SOURCE_COLNAME and ODPP_OPR_SOURCE_COLINDEX and ODPP_OPR_SOURCE_COLS are mutually exclusive and any one of them can be provided
// You can use ODPP_OPR_SOURCE_COLINDEX as follow
// InitParameters[1].usParameterID = ODPP_OPR_SOURCE_COLINDEX;
// InitParameters[1].iValueSubType = PARAM_VAL_NUM; //To indicate that current parameter will hold numeric value.
// InitParameters[1].PV.uiVal = 0; // index values always start with 0
//Parameter 3
//Destination column name
InitParameters[2].usParameterID = ODPP_OPR_HASH_DEST_COL;
//To indicate that current parameter will hold wide character (Unicode) string value
InitParameters[2].iValueSubType = PARAM_VAL_WC;
//Allocate the pWC struct DPPRM_VAL_WC_SS
InitParameters[2].PV.pWC = (DPPRM_VAL_WC_SS *) malloc(sizeof(DPPRM_VAL_WC_SS));
if(NULL == InitParameters[2].PV.pWC)
{
printf("Failed to allocate memory for pWC->DPPRM_VAL_WC_SS");
goto CleanSvcDef;
}
memset(InitParameters[2].PV.pWC, 0, sizeof(DPPRM_VAL_WC_SS));
//Get length of destination column name
iLen = (int)wcslen(FldDef[1].CN.pWC->pColName);
//Set the size of the parameter value buffer in bytes
InitParameters[2].iValueBufBytes = (iLen + 1) * sizeof(ODPP_WCHAR);
//Allocate memory for the source column name in wide character (Unicode) format
InitParameters[2].PV.pWC->pParamVal = (ODPP_WCHAR *) malloc(InitParameters[2].iValueBufBytes);
if(NULL == InitParameters[2].PV.pWC->pParamVal)
{
printf("Failed to allocate memory for parameter value pParamVal");
goto CleanSvcDef;
}
memset(InitParameters[2].PV.pWC->pParamVal, 0, (iLen+1));
//Copy source column name from FldDef[1].CN.pWC->pColName to pParmVal
wcsncpy(InitParameters[2].PV.pWC->pParamVal, FldDef[1].CN.pWC->pColName, iLen);
//NULL terminate the pParmVal buffer
InitParameters[2].PV.pWC->pParamVal[iLen] = '\0';
#else
//For mixed character (MBCS/SBCS) format
//Parameter 2
//ODPP_OPR_SOURCE_COLNAME, ODPP_OPR_SOURCE_COLINDEX and ODPP_OPR_SOURCE_COLS are mutually
//exclusive and any one of them can be provided
InitParameters[1].usParameterID = ODPP_OPR_SOURCE_COLS;
//To indicate that current parameter will hold mixed character (MBCS/SBCS) string value
InitParameters[1].iValueSubType = PARAM_VAL_MC;
//Allocate the pMC struct DPPRM_VAL_MC_SS
InitParameters[1].PV.pMC = (DPPRM_VAL_MC_SS *) malloc(sizeof(DPPRM_VAL_MC_SS));
if(NULL == InitParameters[1].PV.pMC)
{
printf("Failed to allocate memory for pMC->DPPRM_VAL_MC_SS");
goto CleanSvcDef;
}
memset(InitParameters[1].PV.pMC, 0, sizeof(DPPRM_VAL_MC_SS));
//Get length of source column name
iLen = (int)strlen(FldDef[0].CN.pMC->pColName);
//Set the size of the parameter value buffer in bytes
InitParameters[1].iValueBufBytes = (iLen + 1) * ODPP_MBCS_CHAR_BYTES;
//Allocate memory for the source column name in mixed character (MBCS/SBCS) format
InitParameters[1].PV.pMC->pParamVal = (char *) malloc(InitParameters[1].iValueBufBytes);
if(NULL == InitParameters[1].PV.pMC->pParamVal)
{
printf("Failed to allocate memory for parameter value pParamVal");
goto CleanSvcDef;
}
memset(InitParameters[1].PV.pMC->pParamVal, 0, (iLen+1));
//Copy source column name from FldDef[0].CN.pMC->pColName to pParmVal
strncpy(InitParameters[1].PV.pMC->pParamVal, FldDef[0].CN.pMC->pColName, iLen);
//NULL terminate the pParmVal buffer
InitParameters[1].PV.pMC->pParamVal[iLen] = '\0';
//For system default codepage
InitParameters[1].PV.pMC->iParamValCodePage = -1;
//DBMS Type code
InitParameters[1].PV.pMC->cParamValDBMSType = RDB_NONE;
//You Can use ODPP_OPR_SOURCE_COLINDEX as follow
//InitParameters[1].usParameterID = ODPP_OPR_SOURCE_COLINDEX;
//InitParameters[1].iValueSubType = PARAM_VAL_NUM; //To indicate that current parameter will hold numeric value.
//InitParameters[1].PV.uiVal = 0; // index values always start with 0
//Parameter 3
//Destination column name
InitParameters[2].usParameterID = ODPP_OPR_HASH_DEST_COL;
//To indicate that current parameter will hold mixed character (SBCS/MBCS)string value
InitParameters[2].iValueSubType = PARAM_VAL_MC;
//Allocate the pMC struct DPPRM_VAL_MC_SS
InitParameters[2].PV.pMC = (DPPRM_VAL_MC_SS *) malloc(sizeof(DPPRM_VAL_MC_SS));
if(NULL == InitParameters[2].PV.pMC)
{
printf("Failed to allocate memory for pMC->DPPRM_VAL_MC_SS");
goto CleanSvcDef;
}
memset(InitParameters[2].PV.pMC, 0, sizeof(DPPRM_VAL_MC_SS));
//Get length of destination column name
iLen = (int)strlen(FldDef[1].CN.pMC->pColName);
//Set the size of the parameter value buffer in bytes
InitParameters[2].iValueBufBytes = (iLen + 1) * ODPP_MBCS_CHAR_BYTES;
//Allocate memory for the destination column name in mixed character (SBCS/MBCS) format
InitParameters[2].PV.pMC->pParamVal = (char *) malloc(InitParameters[2].iValueBufBytes);
if(NULL == InitParameters[2].PV.pMC->pParamVal)
{
printf("Failed to allocate memory for parameter value pParamVal");
goto CleanSvcDef;
}
memset(InitParameters[2].PV.pMC->pParamVal, 0, (iLen+1));
//Copy source column name from FldDef[1].CN.pMC->pColName to pParmVal
strncpy(InitParameters[2].PV.pMC->pParamVal, FldDef[1].CN.pMC->pColName, iLen);
//NULL terminate the pParmVal buffer
InitParameters[2].PV.pMC->pParamVal[iLen] = '\0';
//For system default codepage
InitParameters[2].PV.pMC->iParamValCodePage = -1;
//DBMS Type code
InitParameters[2].PV.pMC->cParamValDBMSType = RDB_NONE;
#endif
//Parameter 4
//Method to choose during masking
InitParameters[3].usParameterID = ODPP_OPR_METHOD;
//To indicate that current parameter will hold numeric value.
InitParameters[3].iValueSubType = PARAM_VAL_NUM;
//Generates a consistently masked output
InitParameters[3].PV.uiVal = ODPP_METHOD_HASH;
//Parameter 5
//This parameter is used to specify the literal seed
InitParameters[4].usParameterID = ODPP_OPR_HASH_SEED_LIT;
//To indicate that current parameter will hold numeric value
InitParameters[4].iValueSubType = PARAM_VAL_NUM;
//seed value
InitParameters[4].PV.uiVal = 1975;
//Setting the Operand count to 5 as we are supplying five operands Count information should always be correct and should never be skipped
SvcDef.sParamCount = 5;
//Initialize the Service Provider
retVal = Provider_Init(&iSvcToken, &PrvName[0], strlen(PrvName), &SvcDef, FALSE);
if(ODPPSUCCESS != retVal)
{
printf("Provider Init Failed Err=%#x", retVal);
goto CleanSvcDef;
}

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

CleanSVCDef:
//Clear the field definition
for(i=0; i < MAX_COLUMNS; i++)
{
#ifndef USE_ODPP_MBCS_CHAR_CALLS
if(NULL != FldDef[i].CN.pWC)
{
if(NULL != FldDef[i].CN.pWC->pColName)
{
free(FldDef[i].CN.pWC->pColName);
FldDef[i].CN.pWC->pColName = NULL;
free(FldDef[i].CN.pWC);
FldDef[i].CN.pWC = NULL;
}
}
#else
if(NULL != FldDef[i].CN.pMC)
{
if(NULL != FldDef[i].CN.pMC->pColName)
{
free(FldDef[i].CN.pMC->pColName);
FldDef[i].CN.pMC->pColName = NULL;
free(FldDef[i].CN.pMC);
FldDef[i].CN.pMC = NULL;
}
}
#endif
}
//clear the Initialization parameter definition
for(i=0; i<PARAMETER_MAX_SIZE; i++)
{
#ifndef USE_ODPP_MBCS_CHAR_CALLS
if(PARAM_VAL_WC == InitParameters[i].iValueSubType)
{
if(NULL != InitParameters[i].PV.pWC)
{
if(NULL != InitParameters[i].PV.pWC->pParamVal)
{
free(InitParameters[i].PV.pWC->pParamVal);
InitParameters[i].PV.pWC->pParamVal = NULL;
free(InitParameters[i].PV.pWC);
InitParameters[i].PV.pWC = NULL;
}
}
}
#else
if(PARAM_VAL_MC == InitParameters[i].iValueSubType)
{
if(NULL != InitParameters[i].PV.pMC)
{
if(NULL != InitParameters[i].PV.pMC->pParamVal)
{
free(InitParameters[i].PV.pMC->pParamVal);
InitParameters[i].PV.pMC->pParamVal = NULL;
free(InitParameters[i].PV.pMC);
InitParameters[i].PV.pMC = NULL;
}
}
}
#endif
}
return retVal; //Return the error code