The following example invokes the Credit Card Service Provider to generate random CCNs that include the first six digits of the source issuer identifier number.
Service Provider Initialization:
int iSvcToken;
short sMethod;
char Line[INPUT_LINE_MAX_SIZE];
int *piRows = NULL;
int i = 0;
int j = 0;
int iLen = 0;
int iCnt = 0;
FILE *fin = NULL;
char PrvName[] = "CCN";
memset(InitParameters, 0, PARAMETER_MAX_SIZE *
sizeof(
DP_INIT_OP_DEF));
for(iTempCnt=0; iTempCnt < MAX_COLUMNS; iTempCnt++)
{
}
for(iTempCnt=0; iTempCnt < PARAMETER_MAX_SIZE; iTempCnt++)
{
}
SvcDef.pParams = &InitParameters[0];
SvcDef.pFldDef = &FldDef[0];
SvcDef.bCopyToDest = TRUE;
#ifndef USE_ODPP_MBCS_CHAR_CALLS
FldDef[0].cSubType = 'W';
if(NULL == FldDef[0].CN.pWC)
{
printf("\nFailed to allocate pWC struct of DP_FIELD_DEF\n");
goto CleanSvcDef;
}
FldDef[0].iDataCodePage = 0;
FldDef[0].cDataDBMSType = 0;
FldDef[0].iColNameBytes = (MAX_COLNAME_SIZE + 1) * sizeof(ODPP_WCHAR);
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);
wcscpy(FldDef[0].CN.pWC->pColName, L"CreditCard");
FldDef[0].iLength = 0;
#else
FldDef[0].cSubType = 'M';
if(NULL == FldDef[0].CN.pMC)
{
printf("\nFailed to allocate pMC struct of DP_FIELD_DEF\n");
return ODPPFAILURE;
}
FldDef[0].iDataCodePage = -1;
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);
strcpy(FldDef[0].CN.pMC->pColName, "CreditCard");
FldDef[0].iLength = 0;
#endif
InitParameters[1].PV.uiVal = 0;
SvcDef.sOprCount = 4;
retVal =
Provider_Init(&iSvcToken, &PrvName[0], strlen(PrvName), &SvcDef, FALSE);
if(ODPPSUCCESS != retVal)
{
printf("Provider Init Failed Err=%#x", retVal);
goto CleanSvcDef;
}
Service Provider Execution:
fin = fopen(&SourceFilePath[0],"r");
iCnt = 0;
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().
if(NULL == (*pRow))
{
printf("Failed to allocate memory for the row");
goto CleanRowSet;
}
if(NULL == pData)
{
printf("Failed to allocate memory for pData");
goto CleanRowSet;
}
{
printf("Failed to allocate memory for source buffer");
goto CleanRowSet;
}
strncpy((
char*)pData->
pSrcBuf, &Line[0], iLen);
pData->
pDstBuf = (
unsigned char*)malloc(DST_BUF_MAX_SIZE);
{
printf("Failed to allocate memory for destination buffer");
goto CleanRowSet;
}
memset(pData->
pDstBuf,0,DST_BUF_MAX_SIZE);
(*pRow)->pFldDataDefine = pData;
(*pRow)->sCount = 1;
iCnt++;
Loop END
After the rowSet has been created invoke the Service Provider
fclose(fin);
*piRows = iCnt;
if(ODPPSUCCESS != retVal)
{
printf("Provider service failed %d", retVal);
goto CleanRowSet;
}
Service Provider Termination:
if(ODPPSUCCESS != retVal)
{
printf("Provider Terminate failed %d", retVal);
goto CleanRowSet;
}
Free the memory that has been allocated if an error occured
CleanRowSet:
pRowSet = &rowSet;
for(i = 0; ((i < pRowSet->
iCount) && (NULL != pCurRow)); i++)
{
pPrevRow = pCurRow;
for(j = 0; ((j < pCurRow->
sCount) && (NULL != pData)); j++)
{
pPrev = pData;
free(pPrev);
}
pCurRow = pCurRow->
pNext;
free(pPrevRow);
}
CleanSVCDef:
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
}
for(i=0; i<PARAMETER_MAX_SIZE; i++)
{
#ifndef USE_ODPP_MBCS_CHAR_CALLS
{
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(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;