45 using namespace dca_ipr;
47 const std::string S_ToolName =
"iprdbdownloadsample";
48 const std::string S_ToolVersion =
"1.2";
55 " <redist-folder> <ticket> <product>\n"
56 " redist-folder - the folder where the DCA is installed to\n"
57 " ticket - a valid ticket\n"
58 " product - the product associated with your ticket\n\n"
66 # define DCA_BINDIR "bin/Win32"
68 # define DCA_BINDIR "bin/linux"
75 #define DCA_INITDIR "init"
80 #define DCA_LOGDIR "./logs"
106 static void SetupLicense(
const std::string& ticket,
const std::string& product,
109 licenseData.
ticket = ticket;
130 std::cout <<
"IBM DCA Sample: " << S_ToolName <<
" (" << S_ToolVersion <<
")"
141 std::cout <<
"usage: " << name <<
S_UsageString << std::endl;
149 static void PrintUpdateResults(
const UpdateResults& results )
151 std::cout <<
"UpdateResults: size=" << results.
size() <<
", restartRequired="
155 if( !results.
size() ) {
156 std::cout <<
"Currently there are no updates available" << std::endl;
166 std::cout <<
"Result #" << i <<
" id=" << result.
id() <<
", contentUpdated="
167 << ( result.
contentUpdated() ?
"true" :
"false" ) <<
", engineUpdated="
168 << ( result.
engineUpdated() ?
"true" :
"false" ) << std::endl;
175 std::string returnMsg =
"internal error";
177 returnMsg =
"download scheduled";
180 returnMsg =
"success";
183 std::cout <<
" Detail #" << j <<
":"
187 <<
"\n available=" << ( detail.
available() ?
"true" :
"false" )
188 <<
"\n downloaded=" << ( detail.
downloaded() ?
"true" :
"false" )
189 <<
"\n installed=" << ( detail.
installed() ?
"true" :
"false" )
190 <<
"\n return=" << returnMsg << std::endl;
219 std::cout <<
"Start update process, paramater force is set to 'false'..."
225 std::cerr <<
"Got error from update. Details: '" << myFR.
getDescription()
226 <<
"' (" << myFR.
getReturnCode() <<
"). Aborting." << std::endl;
230 PrintUpdateResults( results );
234 std::cout << std::endl <<
"Starting schedule process..." << std::endl;
236 myFR = myDca.
schedule( &mySubscriber );
239 std::cerr <<
"Received error from schedule. Details: '" << myFR.
getDescription()
246 std::cout <<
"Database has been updated from version " << current_db_version <<
" to " << new_db_version << std::endl;
257 int main(
int argc,
char *argv[] )
270 std::string myRedistFolder = argv[ 1 ];
271 const std::string myTicket = argv[ 2 ];
272 const std::string myProduct = argv[ 3 ];
274 if( myRedistFolder.empty() || myTicket.empty() ||
275 myProduct.empty() ) {
281 const char c = myRedistFolder[ myRedistFolder.length() - 1 ];
282 if( c !=
'/' && c !=
'\\' )
283 myRedistFolder +=
"/";
304 std::cout <<
"DCA is not licensed!" << std::endl;
310 SetupConnectionData( myDbConnectionData );
314 const IprClassification myIprClassification = IprClassification::create( myDca, myLicense );
322 rc = PerformUpdateAndSchedule( myDca, myDbConnection, myUpdateModule );
326 catch(
const ExDca& ex ) {
327 std::cerr <<
"DCA Exception occured. Details: " << ex.
getDescription() <<
331 catch(
const std::exception& s ) {
332 std::cerr <<
"std::exception occured. Details: " << s.what() <<
"." << std::endl;
336 std::cerr <<
"Unknown exception caught." << std::endl;
Is used to create a License object. A license first must be created with DcaInstance::createLicense t...
Exception class used in the DCA.
std::string oldVersion() const
Returns the version active (installed) before the update was invoked.
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
FunctionResult schedule(ScheduleEventSubscriberIntf *pScheduleEventSubscriber=NULL) const
Invokes scheduled tasks, e.g. Database updates and processes that can take a long time.
static UpdateModule create(const DcaInstance &aDcaInstance, const License &aLicense, const ProxySettings &proxySettings=ProxySettings())
std::string getDescription() const
Returns a description of the error.
bool downloaded() const
true if an update sucessfully downloaded for this component, false otherwise
int returnCode() const
The internal code of the update, this can be any internal error code, 0 in case of success or DCA_UPD...
Encapsulates the details of a result of an update process.
DCA_RESULT_TYPE getReturnCode() const
Returns the last error code (if any).
bool restartRequired() const
true if an update has been installed that requires a restart of the DCA, false otherwise.
static void SetupInitData(const std::string &redist_folder, InitData &initData)
Sets up the given initData by substituting the given redist_folder with DCA subdirectories.
Defintion of the IprClassifier class.
The update module is used to download and install DCA content and engine updates.
bool installed() const
true if an update sucessfully installed for this component, false otherwise
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...
Encapsulates the results of an update process.
Header file for the schedule event subscriber.
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.
const int DCA_UPDATE_DOWNLOAD_SCHEDULED
Internal DCA status code to indicate that a potentially time consuming download has been scheduled....
void DeinitCUrl()
Deinitializes libcurl. Do not call any DCA function after you have called this function.
const DbType DBT_Ipr
Used to specify an IP Classification database when creating a dca::DbConnection instance.
Database connection class for a local or remote database.
Package header file for the IPR (IP Reputation) Classification Package.
bool contentUpdated() const
If true the update(s) include a content update.
#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.
std::string newVersion() const
Returns the version currently active (installed).
bool available() const
true if an update was available for this component, false otherwise
Encapsulates one of the results of an update process.
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 performUpdate(bool force, UpdateResults &results) const
Performs an update for all licensed and initialized DCA modules and classifiers.
bool isLicensed(DCA_MODULE_ID_TYPE id=0, bool force=false) const
Checks whether the given License is valid for the given module id.
std::string ticket
The ticket as provided in the license.
Example implementation of a schedule event subscriber.
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.
std::string product
The product code used with the license.
static DCA_MODULE_ID_TYPE ID
This is the module id of the update module.
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.
size_t DCA_INDEX_TYPE
Type for index access (used for arrays and collections).
DbType dbType
The type of the database.
DCA_SIZE_TYPE size() const
Returns the number of available details (if any).
IprClassifier createClassifier(const dca::DbConnection &aDbConnection, const IprClassifierOptions &aIprClassifierOptions=IprClassifierOptions()) const
Creates a IprClassifier that is used to classify dca_ipr::Ip objects.
std::string getDescription() const
Returns the description for the error or warning.
size_t DCA_SIZE_TYPE
Type for size (used for size of array and collections).
bool engineUpdated() const
If true the update(s) include an engine update.
Definition of the IprClassification class.
#define DCA_BINDIR
DCA subdirectory of the DCA binaries.
Standard function result.
IprCategoriesInfo getCategoriesInfo() const
Retrieve the IprCategoriesInfo class.
const std::string S_UsageString
Usage string, displayed if a parameter is missing.
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.
std::string getDatabaseVersion() const
Returns the currently used database version.
static DcaInstance create(const InitData &initData)
Creates a DcaInstance, starts up the DCA API and initializes the required main module.
DCA_SIZE_TYPE size() const
Returns the number of results available .
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.
License createLicense(const LicenseData &licData, const ProxySettings &proxySettings=ProxySettings(), LogLevel aLogLevel=LOG_Initial) const
Creates a License object using the given LicenseData.
DCA_MODULE_ID_TYPE id() const
Returns the module ID for which the updates have been installed.
std::string component() const
Returns the name of the component the detail applies to.
int main(int argc, char *argv[])
The main routine.