wac_samples: wacsample


Introduction

Note:
It's useful to first download a complete WAC database before starting this sample, since the DCA initially only contains an empty WAC and URL database. To get URL classification matches its also necessary to first download a complete URL database. You may use the urldbdownload_sample for this.

All results are printed out to std::out.

Syntax:

wacdbdownloadsample <dca-redist-folder> <ticket> <product> <url-input-file>
url-input-file
This file contains Request, URLs and Response data. Each URL is first used for URL and after that for WAC Classification. Response and Request data are not used currently, they are just here to give an example how to add them in the dca_wac::InputData structure. Some sample data is provided in the inital WAC database, the coresponding input for the sample program can be found in: wac_test_app_207.txt wac_test_app_246.txt wac_test_app_247.txt
See also:

Files

file  wac_samples/wacsample/main.cpp
 

WAC classification sample using a provided file that contains sample data such as HTTP requests, URLs and responses.


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 &redist_folder, InitData &initData)
 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 &ticket, const std::string &product, LicenseData &licenseData)
 Sets up the given licenseData by copying the given ticket and product strings.
static void SetupWacConnectionData (DbConnectionData &cData)
 Sets up the given cData to use a local WAC database.
static void SetupUrlConnectionData (DbConnectionData &cData)
 Sets up the given cData to use a local URL database.
static void PrintDbConnectionInfo (const DbConnection &aDbConnection)
 Prints out the version and datestamp of the database the given aDbConnection is connected to.
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 *name)
 Prints out the syntax of the sample.
void PrintResults (const WacClassificationResult &aWacClassificationResult, const WacCategoriesInfo &aCategoriesInfo)
 Prints out the results of the WAC classification.
void DoCallWacClassification (const WacClassifier &aWacClassifier, const WacInputData &aWacInputData, WacClassificationResult &aWacClassificationResult)
 Performs the classification and in case of an error prints out the details.
void SubstituteCRLF (std::string &s)
 Replaces -> \r -> \n and -> \r\n in given string s.
void TestWacClassification (const dca::DcaInstance &aDcaInstance, const dca::UrlDbClassifier &aUrlClassifier, const WacClassification &aWacClassification, const WacClassifier &aWacClassifier, const WacCategoriesInfo &aCategoriesInfo, const std::string &aFile)
 Reads in WAC input data from a file, calls the URL classifier and WAC 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 &  redist_folder,
InitData initData 
) [static]

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

Parameters:
[in] redist_folder This is the folder where the DCA has been installed to (assuming trailing fileslash)
[out] initData 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 122 of file wac_samples/wacsample/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 140 of file wac_samples/wacsample/main.cpp.

static void SetupLicense ( const std::string &  ticket,
const std::string &  product,
LicenseData licenseData 
) [static]

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

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

Definition at line 186 of file wac_samples/wacsample/main.cpp.

static void SetupWacConnectionData ( DbConnectionData cData  )  [static]

Sets up the given cData to use a local WAC database.

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

Definition at line 199 of file wac_samples/wacsample/main.cpp.

static void SetupUrlConnectionData ( DbConnectionData cData  )  [static]

Sets up the given cData to use a local URL database.

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

Definition at line 211 of file wac_samples/wacsample/main.cpp.

static void PrintDbConnectionInfo ( const DbConnection aDbConnection  )  [static]

Prints out the version and datestamp of the database the given aDbConnection is connected to.

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

Definition at line 222 of file wac_samples/wacsample/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 237 of file wac_samples/wacsample/main.cpp.

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

Prints out the syntax of the sample.

Parameters:
[in] name The name of the executable

Definition at line 273 of file wac_samples/wacsample/main.cpp.

void PrintResults ( const WacClassificationResult aWacClassificationResult,
const WacCategoriesInfo aCategoriesInfo 
)

Prints out the results of the WAC classification.

Parameters:
[in] aWacClassificationResult The result of the classification
[in] aCategoriesInfo A WacCategoriesInfo class to retrieve names of actions and applications

Definition at line 285 of file wac_samples/wacsample/main.cpp.

void DoCallWacClassification ( const WacClassifier aWacClassifier,
const WacInputData aWacInputData,
WacClassificationResult aWacClassificationResult 
)

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

Parameters:
[in] aWacClassifier The WAC classifier to use
[in] aWacInputData WacInputData class to classify
[in] aWacClassificationResult WAC classification result retrieved as result of a WAC classification

Definition at line 315 of file wac_samples/wacsample/main.cpp.

void TestWacClassification ( const dca::DcaInstance aDcaInstance,
const dca::UrlDbClassifier aUrlClassifier,
const WacClassification aWacClassification,
const WacClassifier aWacClassifier,
const WacCategoriesInfo aCategoriesInfo,
const std::string &  aFile 
)

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

Parameters:
[in] aDcaInstance A DcaInstance used to create dca::Url objects for URL classification call
[in] aUrlClassifier A UrlDbClassifier used to call the URL classification
[in] aWacClassification A WacClassification used to retrieve WAC related flags out of the UrlClassificationResults
[in] aWacClassifier The WAC classifier to use
[in] aCategoriesInfo A valid set up WacCategoriesInfo
[in] aFile Input data filename

Definition at line 381 of file wac_samples/wacsample/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 477 of file wac_samples/wacsample/main.cpp.


Variable Documentation

const std::string S_UsageString
Initial value:
        "<redist-folder> <ticket> <product> <input-file>\n"
        "  redist-folder - the folder where the DCA is installed to\n"
        "  ticket - a valid ticket\n"
        "  product - the product associated with your ticket\n\n"
        "  input-file - a file with sample input data in the following format:\n"
        "     1st line: requestdata\n"
        "     2nd line: URL\n"
        "     3rd line: response\n"
        "     4th line: requestdata...\n"
        "   Leave line blank if no request data URL or response data should be used\n"
        "   Note: At least one of the 3 lines must be non blank.\n"
        "       Note: A $(CR), $(LF) or $(CRLF) will be substituted with \\r, \\n and \\r\\n\n\n"

Usage string, displayed if a parameter is missing.

Definition at line 78 of file wac_samples/wacsample/main.cpp.


Generated on 26 Sep 2016 for dca_interface by  doxygen 1.6.1