ipr_samples: iprsample


Introduction

This IPR classification sample takes a list if IP addresses from a text file and classifies them by using the IprClassification.

Syntax:

iprsample <dca-redist-folder> <ticket> <product> <ip-text-file>
ip-text-file
A file that contains IP addresses (one per line). This file is used to call the IPR classification.
See also:

Files

file  ipr_samples/iprsample/main.cpp
 

IPR classification sample that takes a list if IP addresses from a text file and classifies them.


Defines

#define DCA_BINDIR   "bin/linux"
 DCA subdirectory of the DCA binaries.
#define DCA_INITDIR   "init"
 DCA subdirectory of the DCA initialization data.
#define DCA_LOGDIR   "./logs"
 Relative directory for logfile(s).

Functions

static void SetupInitData (const std::string &strRedistFolder, InitData &aInitData)
 Sets up the given initData by substituting the given redist_folder with DCA subdirectories.
static bool StartupLibraries ()
 Initializes 3rd party library libcurl and set up open ssl callbacks to startdard implementation.
static void ShutdownLibraries ()
 Shuts down 3rd party libraries. On Windows also WSACleanup is called to shutdown Windows sockets for this process.
static void SetupLicense (const std::string &strTicket, const std::string &strProduct, LicenseData &aLicenseData)
 Sets up the given licenseData by copying the given ticket and product strings.
static void SetupConnectionData (DbConnectionData &aDbConnectionData)
 Sets up the given cData to use a local database.
static void PrintDbConnectionInfo (const DbConnection &aDbConnection)
 Prints out the version and datestamp of the local IPR database.
static void PrintLicenseInfo (const License &aLicense)
 Prints out the information about the provided License.
static void PrintToolHeader ()
 Prints out the name and the version of this sample.
static void PrintUsage (const char *pSampleName)
 Prints out the syntax of the sample.
void PrintResult (const IprClassificationResult &aIprClassificationResult, const IprCategories &aIprCategories, const IprEnums &aIprEnums, const std::string &strIndent="")
 Prints out one result item of the IPR classification (and translate ids to names).
void PrintResults (const IprClassificationResults &aIprClassificationResults, const IprCategoriesInfo &aIprCategoriesInfo)
 Prints out the results of the IPR classification.
void DoCallIprClassification (const std::vector< std::string > &aIpStrings, const IprClassifier &aIprClassifier, const IprCategoriesInfo &aIprCategoriesInfo)
 Performs the classification and in case of an error prints out the details.
void TestIprClassification (const IprClassifier &aIprClassifier, const IprCategoriesInfo &aIprCategoriesInfo, const std::string &strFileName)
 Reads in IP input data from a file, calls the IPR classifier on this data and prints out the results.
int main (int argc, char *argv[])
 The main routine.

Variables

const std::string S_UsageString
 Usage string, displayed if a parameter is missing.

Function Documentation

static void SetupInitData ( const std::string &  strRedistFolder,
InitData aInitData 
) [static]

Sets up the given initData by substituting the given redist_folder with DCA subdirectories.

Parameters:
[in] strRedistFolder This is the folder where the DCA has been installed to (assuming trailing fileslash)
[out] aInitData The InitData structure to set up
Note:
Only DCA_BINDIR differs between Windows and Linux
The directory ./logs is used for the logfile(s)

Definition at line 98 of file ipr_samples/iprsample/main.cpp.

static bool StartupLibraries (  )  [static]

Initializes 3rd party library libcurl and set up open ssl callbacks to startdard implementation.

On Windows its necessary to initalize Windows sockets to support IP(v6) addresses as input data.

Returns:
true if nothing fails, false only on Windows if WSAStartup returned an error

Definition at line 117 of file ipr_samples/iprsample/main.cpp.

static void SetupLicense ( const std::string &  strTicket,
const std::string &  strProduct,
LicenseData aLicenseData 
) [static]

Sets up the given licenseData by copying the given ticket and product strings.

Parameters:
[in] strTicket This is the ticket data as provided with your DCA license
[in] strProduct This is the product shortcut e.g. DC oder MS etc
[out] aLicenseData The LicenseData structure to set up

Definition at line 164 of file ipr_samples/iprsample/main.cpp.

static void SetupConnectionData ( DbConnectionData aDbConnectionData  )  [static]

Sets up the given cData to use a local database.

Parameters:
[in] aDbConnectionData The DbConnectionData structure to set up
Note:
Assuming the DCA has already downloaded an initial IPR database.

Definition at line 180 of file ipr_samples/iprsample/main.cpp.

static void PrintDbConnectionInfo ( const DbConnection aDbConnection  )  [static]

Prints out the version and datestamp of the local IPR database.

Parameters:
[in] aDbConnection The database connection for which a version should be displayed

Definition at line 193 of file ipr_samples/iprsample/main.cpp.

static void PrintLicenseInfo ( const License aLicense  )  [static]

Prints out the information about the provided License.

Parameters:
[in] aLicense The license for which information should be displayed

Definition at line 208 of file ipr_samples/iprsample/main.cpp.

static void PrintUsage ( const char *  pSampleName  )  [static]

Prints out the syntax of the sample.

Parameters:
[in] pSampleName The name of the executable

Definition at line 246 of file ipr_samples/iprsample/main.cpp.

void PrintResult ( const IprClassificationResult aIprClassificationResult,
const IprCategories aIprCategories,
const IprEnums aIprEnums,
const std::string &  strIndent = "" 
)

Prints out one result item of the IPR classification (and translate ids to names).

Parameters:
[in] aIprClassificationResult One IprClassificationResult object to print out
[in] aIprCategories IprCategories object to retrieve the matched IprCategory
[in] aIprEnums IprEnums object to retrieve the matched IprNum (if any)
[in] strIndent Indent string to be used for each line

Definition at line 261 of file ipr_samples/iprsample/main.cpp.

void PrintResults ( const IprClassificationResults aIprClassificationResults,
const IprCategoriesInfo aIprCategoriesInfo 
)

Prints out the results of the IPR classification.

Parameters:
[in] aIprClassificationResults The results of the IPR classification
[in] aIprCategoriesInfo An IprCategoriesInfo class to retrieve names

Definition at line 301 of file ipr_samples/iprsample/main.cpp.

void DoCallIprClassification ( const std::vector< std::string > &  aIpStrings,
const IprClassifier aIprClassifier,
const IprCategoriesInfo aIprCategoriesInfo 
)

Performs the classification and in case of an error prints out the details.

Parameters:
[in] aIpStrings Vector of IPs that should be classified
[in] aIprClassifier The IPR classifier to use
[in] aIprCategoriesInfo A valid and initialized IprCategoriesInfo

Definition at line 330 of file ipr_samples/iprsample/main.cpp.

void TestIprClassification ( const IprClassifier aIprClassifier,
const IprCategoriesInfo aIprCategoriesInfo,
const std::string &  strFileName 
)

Reads in IP input data from a file, calls the IPR classifier on this data and prints out the results.

Parameters:
[in] aIprClassifier The IPR classifier to use
[in] aIprCategoriesInfo A valid and initialized IprCategoriesInfo
[in] strFileName Input data file

Definition at line 364 of file ipr_samples/iprsample/main.cpp.

int main ( int  argc,
char *  argv[] 
)

The main routine.

Parameters:
[in] argc The count of arguments provided
[in] argv An array of provided arguments
Returns:
5 on usage error, 10 on exception and internal error and 0 on success

Definition at line 412 of file ipr_samples/iprsample/main.cpp.


Variable Documentation

const std::string S_UsageString
Initial value:
        "<dca-redist-folder> <ticket> <product> <input-file>\n"
        "  dca-redist-folder - the folder where the DCA is installed\n"
        "  ticket - a valid ticket\n"
        "  product - the product associated with your ticket\n"
        "  input-file - a file with sample IP addresses\n\n"

Usage string, displayed if a parameter is missing.

Definition at line 59 of file ipr_samples/iprsample/main.cpp.


Generated on 26 Sep 2016 for dca_interface by  doxygen 1.6.1