FOSSology  4.5.1
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 processUploadId(const CompatibilityState &state, int uploadId, CompatibilityDatabaseHandler &databaseHandler, int groupId)
bool parseCliOptions(int argc, char **argv, CompatibilityCliOptions &dest, std::string &types, std::string &rules, string &jFile, string &mainLicense)
Parse the options sent by CLI to CliOptions object.
void printResultToStdout(const std::vector< tuple< string, string, bool >> &resultPair, const std::string &fileName)
CompatibilityState getState(DbManager &dbManager, CompatibilityCliOptions &&cliOptions)
Create a new state for the current agent based on CliOptions.
int writeARS(const CompatibilityState &state, int arsId, int uploadId, int success, DbManager &dbManager)
int queryAgentId(DbManager &dbManager)
void appendToJson(const std::vector< tuple< string, string, bool >> &resultPair, const std::string &fileName, bool &printComma)
void bail(int exitval)
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.
The main FOSSology CPP library.
The main FOSSology C library.
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:16