FOSSology  4.4.0
Open Source License Compliance by Open Source Software
OjoUtils.hpp
1 /*
2  SPDX-FileCopyrightText: © 2019 Siemens AG
3 
4  SPDX-License-Identifier: GPL-2.0-only
5 */
6 
7 #ifndef OJOS_AGENT_UTILS_HPP
8 #define OJOS_AGENT_UTILS_HPP
9 
10 #define AGENT_NAME "ojo"
11 #define AGENT_DESC "ojo agent"
12 #define AGENT_ARS "ojo_ars"
13 
14 #include <vector>
15 #include <utility>
16 #include <json/json.h>
17 #include <boost/program_options.hpp>
18 
19 #include "ojomatch.hpp"
20 #include "OjoState.hpp"
21 #include "libfossologyCPP.hpp"
22 #include "OjosDatabaseHandler.hpp"
23 
24 extern "C" {
25 #include "libfossology.h"
26 }
27 
28 using namespace std;
29 
31 OjoState getState(OjoCliOptions &&cliOptions);
33 int writeARS(const OjoState &state, int arsId, int uploadId, int success,
35 void bail(int exitval);
36 bool processUploadId(const OjoState &state, int uploadId,
37  OjosDatabaseHandler &databaseHandler, bool ignoreFilesWithMimeType);
38 bool storeResultInDb(const vector<ojomatch> &matches,
39  OjosDatabaseHandler &databaseHandle, const int agent_fk,
40  const int pfile_fk);
41 bool parseCliOptions(int argc, char **argv, OjoCliOptions &dest,
42  std::vector<std::string> &fileNames, std::string &directoryToScan);
43 void appendToJson(const std::string fileName,
44  const pair<string, vector<ojomatch>> resultPair, bool &printComma);
45 void printResultToStdout(const std::string fileName,
46  const pair<string, vector<ojomatch>> resultPair);
47 
48 #endif // OJOS_AGENT_UTILS_HPP
bool storeResultInDb(const vector< ojomatch > &matches, OjosDatabaseHandler &databaseHandle, const int agent_fk, const int pfile_fk)
Store the results from scan to DB.
Definition: OjoUtils.cc:181
Database handler for OJO.
Store the options sent through the CLI.
Definition: OjoState.hpp:24
Store the state of the agent.
Definition: OjoState.hpp:51
DB wrapper for agents.
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.
int queryAgentId(PGconn *dbConn)
Get agent id, exit if agent id is incorrect.
int writeARS(int agentId, int arsId, int uploadId, int success, const fo::DbManager &dbManager)
Call C function fo_WriteARS() and translate the arguments.
CopyrightState getState(CliOptions &&cliOptions)
Create a new state for the current agent based on CliOptions.
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.
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)
void bail(int exitval)
Disconnect with scheduler returning an error code and exit.
The main FOSSology CPP library.
The main FOSSology C library.
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:16