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

In the following example the available Providers are enumerated and the details of each Provider is displayed.

RETVAL retVal; //return value
short sCnt = 0; //Counter
short sPrvCount = 0; //Provider count
DP_PRV_DETAILS *pPrvDetails = NULL; //Pointer to the DP_PRV_DETAILS
DP_PRV_DEF *pPrvDef = NULL; //Pointer to the DP_PRV_DEF
DP_PRV_DEF PrvDef;
//Point the pPrvDef to DP_PRV_DEF structure
pPrvDef = &PrvDef;
//Invoke Provider_Enumerate passing NULL as the first argument to get a count of the available Service Providers in sPrvCount.
retVal = Provider_Enumerate(NULL, &sPrvCount);
if(ODPPSUCCESS != retVal)
{
printf("Provider Enumerate failed Err=%#x", retVal);
return retVal;
}
//Display the Service Provider count.
printf("Provider Count=%d\n", sPrvCount);
//Allocate the provider definition block to retrieve the provider details.
//Initialize the DP_PRV_DEF structure
memset(&PrvDef, 0, sizeof(DP_PRV_DEF));
//Allocate the memory for provider details block for all available service provider
pPrvDetails = (DP_PRV_DETAILS *) malloc(sizeof(DP_PRV_DETAILS) * sPrvCount);
if(NULL == pPrvDetails)
{
printf("\nFailed to allocate memory for Provider details list\n");
return ODPPFAILURE;
}
//Clear the memory for DP_PRV_DETAILS
memset(pPrvDetails, 0, sizeof(DP_PRV_DETAILS) * sPrvCount);
//Set the details list pointer
PrvDef.pPrvDetails = pPrvDetails; //Copy the Service provider details pointer to the Provider definition block
//To get formatted error messages in mixed character (SBCS/MBCS) format, you have to define USE_ODPP_MBCS_CHAR_CALLS in visual studio
//settings in preprocessors definition
#ifndef USE_ODPP_MBCS_CHAR_CALLS
//If wide character (Unicode) format is used
//To indicate that service provider details will be in wide character (Unicode) format and DPPD_WC_SS structure will be used to retrieve Service provider details.
PrvDef.cSubType = 'W';
//Allocate the memory for all service provider to get provider name and description
for(sCnt = 0; sCnt < sPrvCount; sCnt++)
{
//Allocate pWC for each pPrvDetails
(pPrvDetails + sCnt)->PD.pWC = (DPPD_WC_SS *) malloc(sizeof(DPPD_WC_SS));
if(NULL == (pPrvDetails + sCnt)->PD.pWC)
{
printf("\nMem Alloc failed for pWC of DP_PRV_DETAILS\n");
goto CleanPRVDetails;
}
memset((pPrvDetails + sCnt)->PD.pWC, 0, sizeof(DPPD_WC_SS));
//Once pWC structure is allocated, allocate the memory for pProviderName and pDescription bufferes to hold
//Service Provider name and description
//Store the maximum size of pProviderName buffer, in bytes
(pPrvDetails + sCnt)->iPrvNameBufBytes = (ODPP_PROVIDER_NAME_LEN + 1) * sizeof(ODPP_WCHAR);
//Allocate the provider name with maximum buffer size
(pPrvDetails + sCnt)->PD.pWC->pProviderName = (ODPP_WCHAR *) malloc ((pPrvDetails + sCnt)->iPrvNameBufBytes);
if(NULL == (pPrvDetails + sCnt)->PD.pWC->pProviderName)
{
printf("\nMem Alloc failed for pWC->Provider Name\n");
goto CleanPRVDetails;
}
memset((pPrvDetails + sCnt)->PD.pWC->pProviderName, 0, (pPrvDetails + sCnt)->iPrvNameBufBytes);
//Store the size of pDescription buffer, in bytes.
(pPrvDetails + sCnt)->iPrvDescBufBytes = (ODPP_PROVIDER_DESCRIPTION_LEN + 1) * sizeof(ODPP_WCHAR);
//Allocate the provider description with maximum buffer size
(pPrvDetails + sCnt)->PD.pWC->pDescription = (ODPP_WCHAR *) malloc ((pPrvDetails + sCnt)->iPrvDescBufBytes);
if(NULL == (pPrvDetails + sCnt)->PD.pWC->pDescription)
{
printf("\nMem Alloc failed for pWC->Provider Description\n");
goto CleanPRVDetails;
}
memset((pPrvDetails + sCnt)->PD.pWC->pDescription, 0, (pPrvDetails + sCnt)->iPrvDescBufBytes);
}
#else
//If mixed character (MBCS/SBCS) format is used
//To indicate that service provider details will be in mixed character(MBCS/SBCS) format
//and DPPD_MC_SS structure will be used to retrieve service provider details.
PrvDef.cSubType = 'M';
//For system default codepage
PrvDef.iPDCodePage = -1;
//DBMS Type code
PrvDef.cPDDBMSType = RDB_NONE;
//Allocate the memory for provider name and provider description for all service provider
for(sCnt=0; sCnt < sPrvCount; sCnt++)
{
//Allocate pMC for each pPrvDtls
(pPrvDetails + sCnt)->PD.pMC = (DPPD_MC_SS *) malloc(sizeof(DPPD_MC_SS));
if(NULL == (pPrvDetails + sCnt)->PD.pMC)
{
printf("\nMem Alloc failed for pMC of DP_PRV_DETAILS\n");
goto CleanPRVDetails;
}
memset((pPrvDetails + sCnt)->PD.pMC, 0, sizeof(DPPD_MC_SS));
//Store the size of pProviderName buffer, in bytes
(pPrvDetails + sCnt)->iPrvNameBufBytes = (ODPP_PROVIDER_NAME_LEN + 1) * ODPP_MBCS_CHAR_BYTES;
//Allocate the provider name with maximum buffer size
(pPrvDetails + sCnt)->PD.pMC->pProviderName = (char *) malloc ((pPrvDetails + sCnt)->iPrvNameBufBytes);
if(NULL == (pPrvDetails + sCnt)->PD.pMC->pProviderName)
{
printf("\nMem Alloc failed for pMC->Provider Name\n");
goto CleanPRVDetails;
}
memset((pPrvDetails + sCnt)->PD.pMC->pProviderName, 0, (pPrvDetails + sCnt)->iPrvNameBufBytes);
//Store the size of pDescription buffer, in bytes.
(pPrvDetails + sCnt)->iPrvDescBufBytes = (ODPP_PROVIDER_DESCRIPTION_LEN + 1) * ODPP_MBCS_CHAR_BYTES;
//Allocate the provider description with maximum buffer size
(pPrvDetails + sCnt)->PD.pMC->pDescription = (char *) malloc ((pPrvDetails + sCnt)->iPrvDescBufBytes);
if(NULL == (pPrvDetails + sCnt)->PD.pMC->pDescription)
{
printf("\nMem Alloc failed for pMC->Provider Description\n");
goto CleanPRVDetails;
}
memset((pPrvDetails + sCnt)->PD.pMC->pDescription, 0, (pPrvDetails + sCnt)->iPrvDescBufBytes);
}
#endif
//Call Provider_Enumerate() to get details of all available service providers
retVal = Provider_Enumerate(&PrvDef, &sPrvCount);
if(ODPPSUCCESS != retVal)
{
printf("Provider Enumerate failed Err=%#x", retVal);
goto CleanPRVDetails;
}
//Print details of all service provider retrieved in call to Provider_Enumerate()
for(int iCnt=0; iCnt < sPrvCount; iCnt++)
{
#ifndef USE_ODPP_MBCS_CHAR_CALLS
wprintf(L"\nProvider %d: %ws,\t%ws\n",iCnt, (pPrvDef->pPrvDetails +iCnt)->PD.pWC->pProviderName,
(pPrvDef->pPrvDetails +iCnt)->PD.pWC->pDescription);
#else
printf("\nProvider %d: %s,\t%s\n",iCnt, (pPrvDef->pPrvDetails +iCnt)->PD.pMC->pProviderName,
(pPrvDef->pPrvDetails +iCnt)->PD.pMC->pDescription);
#endif
}

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

CleanPRVDetails:
// Clean privider details block
for(sCnt=0; sCnt < sPrvCount; sCnt++)
{
if(NULL != (PrvDef.pPrvDetails + sCnt))
{
#ifndef USE_ODPP_MBCS_CHAR_CALLS
// Clear the DPPD_WC_SS structures
if(NULL != (PrvDef.pPrvDetails + sCnt)->PD.pWC)
{
if(NULL != (PrvDef.pPrvDetails + sCnt)->PD.pWC->pProviderName)
{
free((PrvDef.pPrvDetails + sCnt)->PD.pWC->pProviderName);
(PrvDef.pPrvDetails + sCnt)->PD.pWC->pProviderName = NULL;
}
if(NULL != (PrvDef.pPrvDetails + sCnt)->PD.pWC->pDescription)
{
free((PrvDef.pPrvDetails + sCnt)->PD.pWC->pDescription);
(PrvDef.pPrvDetails + sCnt)->PD.pWC->pDescription = NULL;
}
free((PrvDef.pPrvDetails + sCnt)->PD.pWC);
(PrvDef.pPrvDetails + sCnt)->PD.pWC = NULL;
}
#else
// Clear the DPPD_MC_SS structures
if(NULL != (PrvDef.pPrvDetails + sCnt)->PD.pMC)
{
if(NULL != (PrvDef.pPrvDetails + sCnt)->PD.pMC->pProviderName)
{
free((PrvDef.pPrvDetails + sCnt)->PD.pMC->pProviderName);
(PrvDef.pPrvDetails + sCnt)->PD.pMC->pProviderName = NULL;
}
if(NULL != (PrvDef.pPrvDetails + sCnt)->PD.pMC->pDescription)
{
free((PrvDef.pPrvDetails + sCnt)->PD.pMC->pDescription);
(PrvDef.pPrvDetails + sCnt)->PD.pMC->pDescription = NULL;
}
free((PrvDef.pPrvDetails + sCnt)->PD.pMC);
(PrvDef.pPrvDetails + sCnt)->PD.pMC = NULL;
}
#endif
}
}
free(PrvDef.pPrvDetails);
return retVal;