FOSSology
4.4.0
Open Source License Compliance by Open Source Software
|
Utilities used by copyright and ecc agent. More...
#include "copyrightUtils.hpp"
#include <boost/program_options.hpp>
#include <iostream>
#include <sstream>
Go to the source code of this file.
Macros | |
#define | RGX_FMT_SEPARATOR "@@" |
Functions | |
int | queryAgentId (PGconn *dbConn) |
Get agent id, exit if agent id is incorrect. More... | |
int | writeARS (int agentId, int arsId, int uploadId, int success, const fo::DbManager &dbManager) |
Call C function fo_WriteARS() and translate the arguments. More... | |
void | bail (int exitval) |
Disconnect with scheduler returning an error code and exit. More... | |
bool | parseCliOptions (int argc, char **argv, CliOptions &dest, std::vector< std::string > &fileNames, std::string &directoryToScan) |
Parse the options sent by CLI to CliOptions object. More... | |
static void | addDefaultScanners (CopyrightState &state) |
Add default scanners to the agent state. More... | |
scanner * | makeRegexScanner (const std::string ®exDesc, const std::string &defaultType) |
Make a boost regex scanner object based on regex desc and type. More... | |
CopyrightState | getState (CliOptions &&cliOptions) |
Create a new state for the current agent based on CliOptions. More... | |
bool | saveToDatabase (const string &s, const list< match > &matches, unsigned long pFileId, int agentId, const CopyrightDatabaseHandler ©rightDatabaseHandler) |
Save findings to the database if agent was called by scheduler. More... | |
void | matchFileWithLicenses (const string &sContent, unsigned long pFileId, CopyrightState const &state, int agentId, CopyrightDatabaseHandler &databaseHandler) |
Scan a given file with all available scanners and save findings to database. More... | |
void | matchPFileWithLicenses (CopyrightState const &state, int agentId, unsigned long pFileId, CopyrightDatabaseHandler &databaseHandler) |
Get the file contents, scan for statements and save findings to database. More... | |
bool | processUploadId (const CopyrightState &state, int agentId, int uploadId, CopyrightDatabaseHandler &databaseHandler, bool ignoreFilesWithMimeType) |
Process a given upload id, scan from statements and add to database. More... | |
pair< string, list< match > > | processSingleFile (const CopyrightState &state, const string fileName) |
void | appendToJson (const std::string fileName, const std::pair< string, list< match >> resultPair, bool &printComma) |
void | printResultToStdout (const std::string fileName, const std::pair< string, list< match >> resultPair) |
Utilities used by copyright and ecc agent.
Definition in file copyrightUtils.cc.
|
static |
Add default scanners to the agent state.
state | State to which scanners are being added |
Definition at line 208 of file copyrightUtils.cc.
void appendToJson | ( | const std::string | fileName, |
const std::pair< string, list< match >> | resultPair, | ||
bool & | printComma | ||
) |
Append a new result from scanner to main output json object
fileName | File which was scanned |
resultPair | The result pair from scanSingleFile() |
printComma | Set true to print comma. Will be set true after first data is printed |
Definition at line 469 of file copyrightUtils.cc.
void bail | ( | int | exitval | ) |
Disconnect with scheduler returning an error code and exit.
exitval | Error code |
Definition at line 62 of file copyrightUtils.cc.
CopyrightState getState | ( | CliOptions && | cliOptions | ) |
Create a new state for the current agent based on CliOptions.
Called during instantiation of agent.
cliOptions | CliOptions passed to the agent |
Definition at line 279 of file copyrightUtils.cc.
scanner* makeRegexScanner | ( | const std::string & | regexDesc, |
const std::string & | defaultType | ||
) |
Make a boost regex scanner object based on regex desc and type.
regexDesc | Regex format for scanner |
defaultType | Type of scanner |
Definition at line 248 of file copyrightUtils.cc.
void matchFileWithLicenses | ( | const string & | sContent, |
unsigned long | pFileId, | ||
CopyrightState const & | state, | ||
int | agentId, | ||
CopyrightDatabaseHandler & | databaseHandler | ||
) |
Scan a given file with all available scanners and save findings to database.
sContent | Content of file |
pFileId | id of the pfile sent for scan |
state | State of the agent |
agentId | Agent id |
databaseHandler | Database handler used by agent |
Definition at line 337 of file copyrightUtils.cc.
void matchPFileWithLicenses | ( | CopyrightState const & | state, |
int | agentId, | ||
unsigned long | pFileId, | ||
CopyrightDatabaseHandler & | databaseHandler | ||
) |
Get the file contents, scan for statements and save findings to database.
Reads the file contents of the pFileId and send it for scanning to matchFileWithLicenses().
If the pfile is not found for pFileId, bails with error code 8.
If the pfile is not found in repository, bails with error code 7.
state | State of the agent |
agentId | Agent id |
pFileId | pFile to be scanned |
databaseHandler | Database handler used by agent |
Definition at line 361 of file copyrightUtils.cc.
bool parseCliOptions | ( | int | argc, |
char ** | argv, | ||
CliOptions & | dest, | ||
std::vector< std::string > & | fileNames, | ||
std::string & | directoryToScan | ||
) |
Parse the options sent by CLI to CliOptions object.
[in] | argc | |
[in] | argv | |
[out] | dest | The parsed CliOptions object |
[out] | fileNames | List of files to be scanned |
[out] | directoryToScan | Directory to be scanned |
Definition at line 78 of file copyrightUtils.cc.
void printResultToStdout | ( | const std::string | fileName, |
const std::pair< string, list< match >> | resultPair | ||
) |
Print the result of current scan to stdout
fileName | File which was scanned |
resultPair | Result pair from scanSingleFile() |
Definition at line 535 of file copyrightUtils.cc.
pair<string, list<match> > processSingleFile | ( | const CopyrightState & | state, |
const string | fileName | ||
) |
Read a single file and run all scanners on it based of CopyrightState.
state | Copyright state |
fileName | Location of the file to be scanned |
Definition at line 439 of file copyrightUtils.cc.
bool processUploadId | ( | const CopyrightState & | state, |
int | agentId, | ||
int | uploadId, | ||
CopyrightDatabaseHandler & | databaseHandler, | ||
bool | ignoreFilesWithMimeType | ||
) |
Process a given upload id, scan from statements and add to database.
The agent runs in parallel with the help of omp. A new thread is created for every pfile.
state | State of the agent |
agentId | Agent id |
uploadId | Upload id to be processed |
databaseHandler | Database handler object |
ignoreFilesWithMimeType | To ignore files with particular mimetype |
Definition at line 405 of file copyrightUtils.cc.
int queryAgentId | ( | PGconn * | dbConn | ) |
Get agent id, exit if agent id is incorrect.
[in] | dbConn | Database connection object |
Definition at line 25 of file copyrightUtils.cc.
bool saveToDatabase | ( | const string & | s, |
const list< match > & | matches, | ||
unsigned long | pFileId, | ||
int | agentId, | ||
const CopyrightDatabaseHandler & | copyrightDatabaseHandler | ||
) |
Save findings to the database if agent was called by scheduler.
s | Statement found |
matches | List of regex matches for highlight |
pFileId | Id of pfile on which the statement was found |
agentId | Id of agent who discovered the statements |
copyrightDatabaseHandler | Database handler object |
Definition at line 296 of file copyrightUtils.cc.
int writeARS | ( | int | agentId, |
int | arsId, | ||
int | uploadId, | ||
int | success, | ||
const fo::DbManager & | dbManager | ||
) |
Call C function fo_WriteARS() and translate the arguments.
Definition at line 53 of file copyrightUtils.cc.