FOSSology  4.4.0
Open Source License Compliance by Open Source Software
OjoUtils.cc File Reference
#include <iostream>
#include "OjoUtils.hpp"
#include "OjoAgent.hpp"
Include dependency graph for OjoUtils.cc:

Go to the source code of this file.

Functions

OjoState getState (DbManager &dbManager, OjoCliOptions &&cliOptions)
 Create a new state for the current agent based on CliOptions. More...
 
OjoState getState (OjoCliOptions &&cliOptions)
 Create a new state for the agent without DB manager. More...
 
int queryAgentId (DbManager &dbManager)
 
int writeARS (const OjoState &state, int arsId, int uploadId, int success, DbManager &dbManager)
 
void bail (int exitval)
 Disconnect with scheduler returning an error code and exit. More...
 
bool processUploadId (const OjoState &state, int uploadId, OjosDatabaseHandler &databaseHandler, bool ignoreFilesWithMimeType)
 
bool storeResultInDb (const vector< ojomatch > &matches, OjosDatabaseHandler &databaseHandle, const int agent_fk, const int pfile_fk)
 Store the results from scan to DB. More...
 
bool parseCliOptions (int argc, char **argv, OjoCliOptions &dest, std::vector< std::string > &fileNames, string &directoryToScan)
 Parse the options sent by CLI to CliOptions object. More...
 
void appendToJson (const std::string fileName, const std::pair< string, vector< ojomatch >> resultPair, bool &printComma)
 
void printResultToStdout (const std::string fileName, const std::pair< string, vector< ojomatch >> resultPair)
 

Detailed Description

The utility functions for OJO agent

Definition in file OjoUtils.cc.

Function Documentation

◆ appendToJson()

void appendToJson ( const std::string  fileName,
const std::pair< string, vector< ojomatch >>  resultPair,
bool &  printComma 
)

Append a new result from scanner to STDOUT

Parameters
fileNameFile which was scanned
resultPairThe result pair from scanSingleFile()
printCommaSet true to print comma. Will be set true after first data is printed

Definition at line 355 of file OjoUtils.cc.

◆ bail()

void bail ( int  exitval)

Disconnect with scheduler returning an error code and exit.

Disconnect scheduler and exit in case of failure.

Parameters
exitvalExit code to be sent to scheduler and returned by program

Definition at line 88 of file OjoUtils.cc.

◆ getState() [1/2]

OjoState getState ( DbManager dbManager,
OjoCliOptions &&  cliOptions 
)

Create a new state for the current agent based on CliOptions.

Called during instantiation of agent.

Parameters
cliOptionsCLI options passed to the agent
Returns
New OjoState object for the agent

Definition at line 25 of file OjoUtils.cc.

◆ getState() [2/2]

OjoState getState ( OjoCliOptions &&  cliOptions)

Create a new state for the agent without DB manager.

Parameters
cliOptionsCLI options passed
Returns
New OjoState object

Definition at line 36 of file OjoUtils.cc.

◆ parseCliOptions()

bool parseCliOptions ( int  argc,
char **  argv,
OjoCliOptions dest,
std::vector< std::string > &  fileNames,
string &  directoryToScan 
)

Parse the options sent by CLI to CliOptions object.

Parameters
[in]argc
[in]argv
[out]destThe parsed OjoCliOptions object
[out]fileNamesList of files to be scanned
[out]directoryToScanPath of the directory to be scanned
Returns
True if success, false otherwise

Definition at line 228 of file OjoUtils.cc.

◆ printResultToStdout()

void printResultToStdout ( const std::string  fileName,
const std::pair< string, vector< ojomatch >>  resultPair 
)

Print the result of current scan to stdout

Parameters
fileNameFile which was scanned
resultPairResult pair from scanSingleFile()

Definition at line 421 of file OjoUtils.cc.

◆ processUploadId()

bool processUploadId ( const OjoState state,
int  uploadId,
OjosDatabaseHandler databaseHandler,
bool  ignoreFilesWithMimeType 
)

Process a given upload id

Parameters
stateState of the agent
uploadIdUpload ID to be scanned
databaseHandlerDatabase handler to be used
ignoreFilesWithMimeTypeTo ignore files with particular mimetype
Returns
True in case of successful scan, false otherwise.

Definition at line 102 of file OjoUtils.cc.

◆ queryAgentId()

int queryAgentId ( DbManager dbManager)

Query the agent ID from the DB.

Parameters
dbManagerDbManager to be used
Returns
The agent if found, bail otherwise.

Definition at line 46 of file OjoUtils.cc.

◆ storeResultInDb()

bool storeResultInDb ( const vector< ojomatch > &  matches,
OjosDatabaseHandler databaseHandle,
const int  agent_fk,
const int  pfile_fk 
)

Store the results from scan to DB.

Store the license finding (if found) and highlight to the database.

Store not found entries for empty matches to the database.

Parameters
matchesList of matches.
databaseHandleDatabase handler to be used
agent_fkCurrent agent id
pfile_fkCurrent pfile id
Returns
True on success, false otherwise.

Definition at line 181 of file OjoUtils.cc.

◆ writeARS()

int writeARS ( const OjoState state,
int  arsId,
int  uploadId,
int  success,
DbManager dbManager 
)

Write ARS to the agent's ars table

Parameters
stateState of the agent
arsIdARS id (0 for new entry)
uploadIdUpload ID
successSuccess status
dbManagerDbManager to use
Returns
ARS ID.

Definition at line 74 of file OjoUtils.cc.