FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
OjoUtils.hpp
1 /*
2  * Copyright (C) 2019, Siemens AG
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * version 2 as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16  */
17 
18 #ifndef OJOS_AGENT_UTILS_HPP
19 #define OJOS_AGENT_UTILS_HPP
20 
21 #define AGENT_NAME "ojo"
22 #define AGENT_DESC "ojo agent"
23 #define AGENT_ARS "ojo_ars"
24 
25 #include <vector>
26 #include <utility>
27 #include <json/json.h>
28 #include <boost/program_options.hpp>
29 
30 #include "ojomatch.hpp"
31 #include "OjoState.hpp"
32 #include "libfossologyCPP.hpp"
33 #include "OjosDatabaseHandler.hpp"
34 
35 extern "C" {
36 #include "libfossology.h"
37 }
38 
39 using namespace std;
40 
42 OjoState getState(OjoCliOptions &&cliOptions);
44 int writeARS(const OjoState &state, int arsId, int uploadId, int success,
46 void bail(int exitval);
47 bool processUploadId(const OjoState &state, int uploadId,
48  OjosDatabaseHandler &databaseHandler, bool ignoreFilesWithMimeType);
49 bool storeResultInDb(const vector<ojomatch> &matches,
50  OjosDatabaseHandler &databaseHandle, const int agent_fk,
51  const int pfile_fk);
52 bool parseCliOptions(int argc, char **argv, OjoCliOptions &dest,
53  std::vector<std::string> &fileNames, std::string &directoryToScan);
54 void appendToJson(const std::string fileName,
55  const pair<string, vector<ojomatch>> resultPair, bool &printComma);
56 void printResultToStdout(const std::string fileName,
57  const pair<string, vector<ojomatch>> resultPair);
58 
59 #endif // OJOS_AGENT_UTILS_HPP
void bail(int exitval)
Disconnect with scheduler returning an error code and exit.
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:190
void printResultToStdout(const std::string fileName, const std::pair< string, list< match >> resultPair)
DB wrapper for agents.
CopyrightState getState(CliOptions &&cliOptions)
Create a new state for the current agent based on CliOptions.
void appendToJson(const std::string fileName, const std::pair< string, list< match >> resultPair, bool &printComma)
Database handler for OJO.
Store the state of the agent.
Definition: OjoState.hpp:54
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 main FOSSology C library.
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.
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:28
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.
The main FOSSology CPP library.
Store the options sent through the CLI.
Definition: OjoState.hpp:34