55 const std::string S_ToolName =
"customdbsample";
56 const std::string S_ToolVersion =
"1.2";
58 std::string custom_db_folder;
59 std::string categories_folder;
66 "<redist-folder> <ticket> <product> <custom-db-folder> <categories-folder>\n"
67 " redist-folder - the folder where the DCA is installed to\n"
68 " ticket - a valid ticket\n"
69 " product - the product associated with your ticket\n"
70 " custom-db-folder - the folder where the Custom Database should be created in\n"
71 " categories-folder - the folder where your XML files are located in\n"
79 # define DCA_BINDIR "bin/Win32"
81 # define DCA_BINDIR "bin/linux"
88 #define DCA_INITDIR "init"
93 #define DCA_LOGDIR "./logs"
120 static void SetupLicense(
const std::string& ticket,
const std::string& product,
123 licenseData.
ticket = ticket;
135 static void SetupConnectionData(
const std::string& custom_db_folder,
149 std::cout <<
"IBM DCA Sample: " << S_ToolName <<
" (" << S_ToolVersion <<
160 std::cout <<
" usage:" << std::endl;
173 struct tm *expirationTime = localtime( &expirationDate );
175 std::cout <<
"License Info:" << std::endl;
176 std::cout <<
" DCA is " << ( aLicense.
isLicensed() ?
"licensed." :
177 "not licensed." ) << std::endl;
178 std::cout <<
" MaxUsers:" << aLicense.
getMaxUsers() <<
182 std::cout <<
" Ticket:" << aLicense.
getTicket() <<
184 std::cout <<
" Session:" << aLicense.
getSession() <<
188 std::cout <<
" Expiration Date:" << asctime( expirationTime ) <<
198 static void PrintCategoriesInfo(
const CategoriesInfo& myCategoriesInfo )
202 if( myLocales.
size() == 0 ) {
203 std::cout <<
"There are no locales defined or not found!" <<
208 const Locale myLocale = myLocales[i];
209 std::cout <<
"Locale #" << (i+1) <<
", displayname='" <<
217 if( myGroups.
size() == 0 ) {
218 std::cout <<
"There are no groups defined or not found!" <<
223 const Group myGroup = myGroups[i];
224 std::cout <<
"Group #" << (i+1) <<
", name='" <<
225 myGroup.
name(
"" ) <<
"', id=" <<
226 myGroup.
id() <<
"." << std::endl;
232 if( myCategories.
size() == 0 ) {
233 std::cout <<
"There are no categories defined or not found!" <<
238 const Category myCategory = myCategories[i];
239 std::cout <<
"Category #" << (i+1) <<
", name='" <<
240 myCategory.
name(
"" ) <<
"', id=" <<
241 myCategory.
id() <<
", groupid=" <<
242 myCategory.
groupId() <<
"." << std::endl;
254 static void PrintUrlResult(
const std::string& myUrlString,
255 const std::set< int >& myCatSet )
257 std::cout <<
"URL '" << myUrlString <<
258 "' contains the following categories: ";
259 for( std::set< int >::const_iterator I = myCatSet.begin(),
260 IEnd = myCatSet.end(); I != IEnd; ++I ) {
262 std::cout << *I << std::endl;
264 std::cout << std::endl;
296 PrintCategoriesInfo( myCategoriesInfo );
305 std::cout <<
"Database already existing..." <<
308 std::cout <<
"Creation of Custom Database failed..." <<
315 SetupConnectionData( custom_db_folder, myDbConnectionData );
323 myUrlCustomDb = myUrlCustomDbModule.
openCustomDb( myDbConnection );
347 InitializeCustomDatabase( aDca, aLicense, myUrlCustomDb );
350 const std::string myUrlString(
"www.an_example_custom_url.com" );
354 std::set< int > myCatSet;
355 myCatSet.insert( 0 );
356 myCatSet.insert( 1 );
357 myUrlCustomDb.
setUrl( myUrlString, myCatSet );
362 std::set< int > myCatSet;
363 if( !myUrlCustomDb.
getUrl( myUrlString, myCatSet ) ) {
365 std::cout <<
"We could not retrieve the previously added URL?"
371 PrintUrlResult( myUrlString, myCatSet );
380 std::set< int > myCatSet;
381 if( myUrlCustomDb.
getUrl( myUrlString, myCatSet ) ) {
383 std::cout <<
"We could still retrieve the URL we already removed?"
389 std::cout <<
"URL has been successfully removed from " <<
390 "Custom Database." << std::endl;
406 int main(
int argc,
char *argv[] )
418 std::string myRedistFolder = argv[ 1 ];
419 const std::string myTicket = argv[ 2 ];
420 const std::string myProduct = argv[ 3 ];
421 custom_db_folder = argv[ 4 ];
422 categories_folder = argv[ 5 ];
424 if( myRedistFolder.empty() || myTicket.empty() ||
425 myProduct.empty() || custom_db_folder.empty() ||
426 categories_folder.empty() ) {
432 char c = myRedistFolder[ myRedistFolder.length() - 1 ];
433 if( c !=
'/' && c !=
'\\' )
434 myRedistFolder +=
"/";
436 c = custom_db_folder[ custom_db_folder.length() - 1 ];
437 if( c !=
'/' && c !=
'\\' )
438 custom_db_folder +=
"/";
440 c = categories_folder[ categories_folder.length() - 1 ];
441 if( c !=
'/' && c !=
'\\' )
442 categories_folder +=
"/";
469 rc = ProcessCustomDatabase( myDca, myLicense );
473 catch(
const ExDca& ex ) {
474 std::cerr <<
"DCA Exception occured. Details: " << ex.
getDescription()
478 catch(
const std::exception& s ) {
479 std::cerr <<
"std::exception occured. Details: " << s.what() <<
"." <<
484 std::cerr <<
"Unknown exception caught." << std::endl;
The Custom Database module, used to create new custom databases or open existing custom databases.
Is used to create a License object. A license first must be created with DcaInstance::createLicense t...
Exception class used in the DCA.
UrlCustomDb openCustomDb(const DbConnection &aDbConnection) const
Creates a UrlCustomDb instance that is connected to the database defined by the given DbConnection.
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
DCA_SIZE_TYPE size() const
Returns the number of categories in the container.
int getMaxSessions() const
Returns the maximum allowed sessions associated with your ticket/license.
static UrlCustomDbModule create(const DcaInstance &aDcaInstance, const License &aLicense)
Loads and initializes the custom database module.
time_t getExpirationDate() const
Returns the expiration date of the license in UTC.
std::string getDescription() const
Returns a description of the error.
std::string configDir
Specifies the complete folder path where the custom database is located, or the folder in which it sh...
Definition of a container class for Category objects.
Encapsulation of a locale class, which allows access to the language id and the display name of local...
DCA_GROUP_ID_TYPE id() const
Returns the id of the group as defined in the related categories XML schema.
DbConnectionCustomData customData
Fill out this structure only if you are using a custom database.
const int ERR_DATABASE_ALREADY_EXISTING
Error code: The specified database already exists.
DCA_RESULT_TYPE getReturnCode() const
Returns the last error code (if any).
static void SetupInitData(const std::string &redist_folder, InitData &initData)
Sets up the given initData by substituting the given redist_folder with DCA subdirectories.
std::string binDir
the directory in which the DCA binary (*.dca) files are stored
void removeUrl(const std::string &aUrlString)
Removes the given URL string from the database, if present.
This header includes initialization/deinitialization support functions for the 3rd party libraries us...
A container class that allows access to the contained Categories, Groups and Locales.
Encapsulates the Custom Database maintenance interface.
void SetOpenSslCallbacks()
Initializes the required callbacks for OpenSSL when using HTTPS or SSL connections in a multi-threade...
Stores the connection data for a database.
void UnsetOpenSslCallbacks()
Unsets the openssl callbacks. Do not call any DCA function after you have called this function.
DCA_CATEGORY_ID_TYPE id() const
The category id.
int getMaxUsers() const
Returns the maximum allowed users associated with your ticket/license.
void DeinitCUrl()
Deinitializes libcurl. Do not call any DCA function after you have called this function.
Database connection class for a local or remote database.
void setUrl(const std::string &aUrlString, const CategorySet &categories)
Updates or creates categories for the given URL string.
DCA_SIZE_TYPE size() const
Returns the number of categories in the container.
#define DCA_LOGDIR
Relative directory for logfile(s).
#define DCA_INITDIR
DCA subdirectory of the DCA initialization data.
Definition of a container class for Group objects.
DCA_RESULT_TYPE getReturnCode() const
Gets the code of the error.
std::string name(const std::string &localeString=std::string()) const
Returns the localized (display) name of the group.
Locales getLocales() const
Returns the contained Locales.
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.
FunctionResult createCustomDb(const std::string &aDatabaseFolder) const
Creates a new custom database file in the given folder.
const DbType DBT_Custom
Used for DbConnection classes of custom databases.
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.
bool useLocalDatabase
Set to true to connect to a local or custom database, set to false to use a remote database.
Encapsulates the init and deinit of the DCA API.
DCA_SIZE_TYPE size() const
The number of items in the container.
std::string product
The product code used with the license.
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).
DbType dbType
The type of the database.
Categories getCategories() const
Returns the contained Categories.
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.
CategoriesInfo createCategoriesInfo(const std::string &categoriesXmlFolder) const
Creates a CategoriesInfo object by using the provided categoriesXmlFolder.
bool getUrl(const std::string &aUrlString, CategorySet &foundCategories) const
Retrieves the categories of URL string (if found).
std::string getTicket() const
Returns the ticket of the license as string.
DCA_GROUP_ID_TYPE groupId() const
If the category is associated with a group, this is the group id.
#define DCA_BINDIR
DCA subdirectory of the DCA binaries.
Standard function result.
std::string getSession() const
Returns the session of the license as string.
Definition of a container class for Locale objects.
std::string languageId() const
Returns the language id as defined in the related categories.xml.
const std::string S_UsageString
Usage string, displayed if a parameter is missing.
Encapsulates a group as defined in the related categories XML schema (see Categories XML: Groups).
DbConnection createDbConnection(const License &aLicense, const DbConnectionData &dbcData, const ProxySettings &proxySettings=ProxySettings(), LogLevel aLogLevel=LOG_Initial) const
Creates a DbConnection object using the given DbConnectionData.
This structure is used to initialize the DcaInstance.
Encapsulates a category as defined in the categories XML schema (see Categories XML: Categories).
Groups getGroups() const
Returns the contained Groups.
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.
static DCA_MODULE_ID_TYPE ID
The unique ID of the Custom DB module.
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.