45 using namespace dca_ipr;
47 const std::string S_ToolName =
"iprenumsample";
48 const std::string S_ToolVersion =
"1.2";
55 "<redist-folder> <ticket> <product> [<locale>]\n"
56 " redist-folder - the folder where the DCA is installed\n"
57 " ticket - a valid ticket\n"
58 " product - the product associated with your ticket\n"
59 " locale - optional locale for the IPR category info names and descriptions, default = en_US\n\n"
67 # define DCA_BINDIR "bin/Win32"
69 # define DCA_BINDIR "bin/linux"
76 #define DCA_INITDIR "init"
82 #define DCA_LOGDIR "./logs"
94 static void SetupInitData(
const std::string& strRedistFolder,
111 const std::string& strProduct,
114 aLicenseData.
ticket = strTicket;
115 aLicenseData.
product = strProduct;
127 struct tm *expirationTime = localtime( &expirationDate );
129 std::cout <<
"License Info:" << std::endl;
130 std::cout <<
" DCA is " << ( aLicense.
isLicensed() ?
"licensed." :
131 "not licensed." ) << std::endl;
132 std::cout <<
" MaxUsers:" << aLicense.
getMaxUsers() <<
136 std::cout <<
" Ticket:" << aLicense.
getTicket() <<
138 std::cout <<
" Session:" << aLicense.
getSession() <<
142 std::cout <<
" Expiration Date:" << asctime( expirationTime ) <<
152 std::cout <<
"IBM DCA Sample: " << S_ToolName <<
" (" << S_ToolVersion <<
")" << std::endl;
161 static void PrintUsage(
const char *pSampleName )
163 std::cout << pSampleName <<
" usage:" << std::endl;
174 void PrintLocale(
const IprLocale& aIprLocale,
175 const std::string& strIndent =
"" )
177 std::cout << strIndent <<
"\tIprLocale '" << aIprLocale.
languageId() <<
178 "' (displayName=" << aIprLocale.
displayName() <<
")" << std::endl;
187 void EnumLocales(
const IprLocales& aIprLocales )
190 if( numOfLocales > 0 ) {
191 std::cout << std::endl <<
"IprLocales (size=" << numOfLocales <<
")" << std::endl;
193 const IprLocale myIprLocale = aIprLocales[ i ];
194 PrintLocale( myIprLocale,
"\t" );
197 else std::cout << std::endl;
208 void PrintEnum(
const IprEnum& aIprEnum,
209 const std::string& strLocale,
210 const std::string& strIndent =
"" )
212 std::cout << strIndent <<
"IprEnum: '" << aIprEnum.
name( strLocale )
213 <<
"' (id=" << aIprEnum.
id() <<
")" << std::endl;
226 const std::string& strLocale )
231 if( numOfEnums > 0 ) {
233 std::cout <<
" (enumsSize=" << numOfEnums <<
")" << std::endl;
237 if( i > maxEnumsToDisplay && numOfEnums > maxEnumsToDisplay ) {
239 std::cout <<
"\t\t ...(" << (numOfEnums - maxEnumsToDisplay - 2) <<
240 " more)..." << std::endl;
243 const IprEnum myLastIprEnum = myIprEnums.
byId( myLastEnumId );
244 PrintEnum( myLastIprEnum, strLocale,
"\t\t" );
248 const IprEnum myIprEnum = myIprEnums.
byId( enumId );
249 PrintEnum( myIprEnum, strLocale,
"\t\t" );
252 else std::cout << std::endl;
263 void PrintCategory(
const IprCategory& aIprCategory,
264 const std::string& strLocale,
265 const std::string& strIndent =
"" )
267 std::cout << strIndent <<
"IprCategory: '" << aIprCategory.
name( strLocale ) <<
268 "' (id=" << aIprCategory.
id() <<
")";
281 const std::string& strLocale )
285 if( numOfCategories > 0 ) {
286 std::cout << std::endl <<
"IprCategories (size=" << numOfCategories <<
290 const IprCategory myIprCategory = aIprCategories[ i ];
291 PrintCategory( myIprCategory, strLocale,
"\t" );
292 EnumCategoryEnums( aIprCategoriesInfo, myIprCategory, strLocale );
295 else std::cout << std::endl;
305 void EnumEnums(
const IprEnums& aIprEnums,
306 const std::string& strLocale )
311 if( numOfEnums > 0 ) {
312 std::cout << std::endl <<
"IprEnums (size=" << numOfEnums <<
317 if( i > maxEnumsToDisplay && numOfEnums > maxEnumsToDisplay ) {
319 std::cout <<
"\t ...(" << (numOfEnums - maxEnumsToDisplay - 2) <<
320 " more)..." << std::endl;
323 const IprEnum myLastIprEnum = aIprEnums[ numOfEnums - 1 ];
324 PrintEnum( myLastIprEnum, strLocale,
"\t" );
327 const IprEnum myIprEnum = aIprEnums[i];
328 PrintEnum( myIprEnum, strLocale,
"\t" );
331 else std::cout << std::endl;
342 const std::string& strLocale )
344 std::cout <<
"Enumeration of all available IprLocale, IprCategory and IprEnum objects:"
348 EnumLocales( myIprLocales );
351 EnumCategories( aIprCategoriesInfo, myIprCategories, strLocale );
354 EnumEnums( myIprEnums, strLocale );
364 int main(
int argc,
char *argv[] )
376 std::string strRedistFolder = argv[ 1 ];
377 const std::string strTicket = argv[ 2 ];
378 const std::string strProduct = argv[ 3 ];
379 std::string strLocale =
"en_US";
385 if( strRedistFolder.empty() ||
394 const char c = strRedistFolder[ strRedistFolder.length() - 1 ];
395 if( c !=
'/' && c !=
'\\' )
396 strRedistFolder +=
"/";
398 std::cout << std::endl;
419 if( myLicense.
isLicensed( IprClassification::ID ) ) {
421 const IprClassification myIprClassification = IprClassification::create( myDca, myLicense );
427 EnumIprCategoriesInfo( myCategoriesInfo, strLocale );
432 catch(
const ExDca& ex ) {
433 std::cerr <<
"DCA Exception occured. Details: " << ex.
getDescription() <<
437 catch(
const std::exception& s ) {
438 std::cerr <<
"std::exception occured. Details: " << s.what() <<
"." << std::endl;
442 std::cerr <<
"Unknown exception caught." << std::endl;
Encapsulation of a locale class, which allows access to the language id and the display name of local...
DCA_SIZE_TYPE enumsSize() const
Returns the count of IprEnum items associated with current IprCategory.
Is used to create a License object. A license first must be created with DcaInstance::createLicense t...
DCA_SIZE_TYPE size() const
Returns the number of locales in the container.
Exception class used in the DCA.
DCA_SIZE_TYPE size() const
Returns the number of enums in the container.
void InitCUrl()
Initializes libcurl. Do not use any DCA function before initializing libcurl.
std::string initDir
the directory in which the DCA init files are stored
int getMaxSessions() const
Returns the maximum allowed sessions associated with your ticket/license.
time_t getExpirationDate() const
Returns the expiration date of the license in UTC.
std::string getDescription() const
Returns a description of the error.
IprEnums getEnums() const
Returns the contained IprEnums.
static void SetupInitData(const std::string &redist_folder, InitData &initData)
Sets up the given initData by substituting the given redist_folder with DCA subdirectories.
Container class for all IPR enumeration objects.
std::string binDir
the directory in which the DCA binary (*.dca) files are stored
This header includes initialization/deinitialization support functions for the 3rd party libraries us...
int DCA_ENUM_ID_TYPE
Id type for IprEnum class.
void SetOpenSslCallbacks()
Initializes the required callbacks for OpenSSL when using HTTPS or SSL connections in a multi-threade...
DCA_ENUM_ID_TYPE id() const
Returns the internal id of the enumerable item.
void UnsetOpenSslCallbacks()
Unsets the openssl callbacks. Do not call any DCA function after you have called this function.
IprCategories getCategories() const
Returns the contained IprCategories.
IprEnum byId(DCA_ENUM_ID_TYPE id) const
Returns the IprEnum with the given id.
int getMaxUsers() const
Returns the maximum allowed users associated with your ticket/license.
DCA_SIZE_TYPE size() const
Returns the number of categories in the container.
void DeinitCUrl()
Deinitializes libcurl. Do not call any DCA function after you have called this function.
Package header file for the IPR (IP Reputation) Classification Package.
#define DCA_LOGDIR
Relative directory for logfile(s).
#define DCA_INITDIR
DCA subdirectory of the DCA initialization data.
DCA_RESULT_TYPE getReturnCode() const
Gets the code of the error.
static void PrintToolHeader()
Prints out the name and the version of this sample.
Use a License to initialize a classification package or a toolbox package.
bool isLicensed(DCA_MODULE_ID_TYPE id=0, bool force=false) const
Checks whether the given License is valid for the given module id.
static void PrintLicenseInfo(const License &aLicense)
Prints out the information about the provided License.
std::string ticket
The ticket as provided in the license.
This header includes all header files of the DCA Base Package.
std::string name(const std::string &localeString=std::string()) const
Returns the localized (display) name of the category.
std::string displayName() const
Returns the display name of the locale.
Encapsulates the init and deinit of the DCA API.
The IprEnum class describes a single enumerable item, for example the Geo Location "Greenland".
std::string product
The product code used with the license.
std::string name(const std::string &localeString=std::string()) const
Returns the localized (display) name of the enumerable item.
Definition of a container class for IprEnum objects.
DCA_CATEGORY_ID_TYPE id() const
Returns the internal id of a IprCategory class.
std::string logDir
the directory in which the DCA log file should be created
static void PrintUsage(const char *name)
Prints out the syntax of the sample.
std::string getLastMessage() const
Returns the last message received from our license server or if none available the last available mes...
size_t DCA_INDEX_TYPE
Type for index access (used for arrays and collections).
size_t DCA_SIZE_TYPE
Type for size (used for size of array and collections).
Definition of a container class for IprCategory objects.
std::string getTicket() const
Returns the ticket of the license as string.
Definition of the IprClassification class.
#define DCA_BINDIR
DCA subdirectory of the DCA binaries.
IprCategoriesInfo getCategoriesInfo() const
Retrieve the IprCategoriesInfo class.
std::string getSession() const
Returns the session of the license as string.
Definition of a container class for IprLocale objects.
The IprCategory class contains information for a single category. An IP address can be assigned to on...
DCA_ENUM_ID_TYPE enumId(DCA_INDEX_TYPE index) const
Returns the id of an enum item associated with the current IprCategory.
const std::string S_UsageString
Usage string, displayed if a parameter is missing.
This structure is used to initialize the DcaInstance.
IprLocales getLocales() const
Returns the contained IprLocales.
static DcaInstance create(const InitData &initData)
Creates a DcaInstance, starts up the DCA API and initializes the required main module.
static void SetupLicense(const std::string &ticket, const std::string &product, LicenseData &licenseData)
Sets up the given licenseData by copying the given ticket and product strings.
std::string languageId() const
Returns the language id of the locale.
License createLicense(const LicenseData &licData, const ProxySettings &proxySettings=ProxySettings(), LogLevel aLogLevel=LOG_Initial) const
Creates a License object using the given LicenseData.
int main(int argc, char *argv[])
The main routine.