FOSSology  4.4.0
Open Source License Compliance by Open Source Software
copyrightUtils.hpp
1 /*
2  SPDX-FileCopyrightText: © 2014,2022, Siemens AG
3  Author: Daniele Fognini, Johannes Najjar
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
8 #ifndef COPYRIGHTUTILS_HPP_
9 #define COPYRIGHTUTILS_HPP_
10 
11 #include "identity.hpp"
12 
13 #define AGENT_NAME IDENTITY
14 #define AGENT_DESC IDENTITY " agent"
15 #define AGENT_ARS IDENTITY "_ars"
16 
17 #include <string>
18 #include <vector>
19 #include <list>
20 #include <json/json.h>
21 
22 #include "scanners.hpp"
23 #include "regscan.hpp"
24 #include "copyscan.hpp"
25 
26 #include "copyrightState.hpp"
27 #include "database.hpp"
28 #include "cleanEntries.hpp"
29 #define THREADS 2
30 
31 extern "C" {
32 #include "libfossology.h"
33 }
34 
35 int queryAgentId(PGconn* dbConn);
36 
37 void bail(int exitval);
38 
39 int writeARS(int agentId, int arsId, int uploadId, int success, const fo::DbManager& dbManager);
40 
41 bool parseCliOptions(int argc, char** argv, CliOptions& dest,
42  std::vector<std::string>& fileNames, std::string& directoryToScan);
43 
44 CopyrightState getState(CliOptions&& cliOptions);
45 
46 scanner* makeRegexScanner(const std::string& regexDesc, const std::string& defaultType);
47 /*
48 std::vector<CopyrightMatch> matchStringToRegexes(const std::string& content, std::vector<RegexMatcher> matchers);
49 */
50 void normalizeContent(std::string& content);
51 
52 bool processUploadId(const CopyrightState& state, int agentId, int uploadId, CopyrightDatabaseHandler& handler, bool ignoreFilesWithMimeType);
53 
54 std::pair<std::string, std::list<match>> processSingleFile(const CopyrightState& state,
55  const std::string fileName);
56 
57 void appendToJson(const std::string fileName,
58  const std::pair<string, list<match>> resultPair, bool &printComma);
59 
60 void printResultToStdout(const std::string fileName,
61  const std::pair<string, list<match>> resultPair);
62 
63 #endif /* COPYRIGHTUTILS_HPP_ */
64 
Store the options sent through the CLI.
Manages database related requests for agent.
Definition: database.hpp:53
Holds information about state of one agent.
DB wrapper for agents.
Abstract class to provide interface to scanners.
Definition: scanners.hpp:52
scanner * makeRegexScanner(const std::string &regexDesc, const std::string &defaultType)
Make a boost regex scanner object based on regex desc and type.
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.
pair< string, list< match > > processSingleFile(const CopyrightState &state, const string fileName)
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 C library.
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:16
Utilities to help scanners.
list_t type structure used to keep various lists. (e.g. there are multiple lists).
Definition: nomos.h:308