FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
copyrightUtils.hpp
1 /*
2  * Copyright (C) 2014, Siemens AG
3  * Author: Daniele Fognini, Johannes Najjar
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2
7  * as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12  * See the GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
19 #ifndef COPYRIGHTUTILS_HPP_
20 #define COPYRIGHTUTILS_HPP_
21 
22 #include "identity.hpp"
23 
24 #define AGENT_NAME IDENTITY
25 #define AGENT_DESC IDENTITY " agent"
26 #define AGENT_ARS IDENTITY "_ars"
27 
28 #include <string>
29 #include <vector>
30 #include <list>
31 #include <json/json.h>
32 
33 #include "scanners.hpp"
34 #include "regscan.hpp"
35 #include "copyscan.hpp"
36 
37 #include "copyrightState.hpp"
38 #include "database.hpp"
39 #include "cleanEntries.hpp"
40 
41 extern "C" {
42 #include "libfossology.h"
43 }
44 
45 int queryAgentId(PGconn* dbConn);
46 
47 void bail(int exitval);
48 
49 int writeARS(int agentId, int arsId, int uploadId, int success, const fo::DbManager& dbManager);
50 
51 bool parseCliOptions(int argc, char** argv, CliOptions& dest,
52  std::vector<std::string>& fileNames, std::string& directoryToScan);
53 
54 CopyrightState getState(CliOptions&& cliOptions);
55 
56 scanner* makeRegexScanner(const std::string& regexDesc, const std::string& defaultType);
57 /*
58 std::vector<CopyrightMatch> matchStringToRegexes(const std::string& content, std::vector<RegexMatcher> matchers);
59 */
60 void normalizeContent(std::string& content);
61 
62 bool processUploadId(const CopyrightState& state, int agentId, int uploadId, CopyrightDatabaseHandler& handler, bool ignoreFilesWithMimeType);
63 
64 std::pair<std::string, std::list<match>> processSingleFile(const CopyrightState& state,
65  const std::string fileName);
66 
67 void appendToJson(const std::string fileName,
68  const std::pair<string, list<match>> resultPair, bool &printComma);
69 
70 void printResultToStdout(const std::string fileName,
71  const std::pair<string, list<match>> resultPair);
72 
73 #endif /* COPYRIGHTUTILS_HPP_ */
74 
void bail(int exitval)
Disconnect with scheduler returning an error code and exit.
void printResultToStdout(const std::string fileName, const std::pair< string, list< match >> resultPair)
DB wrapper for agents.
Utilities to help scanners.
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)
Manages database related requests for agent.
Definition: database.hpp:63
scanner * makeRegexScanner(const std::string &regexDesc, const std::string &defaultType)
Make a boost regex scanner object based on regex desc and type.
Abstract class to provide interface to scanners.
Definition: scanners.hpp:62
Holds information about state of one agent.
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.
list_t type structure used to keep various lists. (e.g. there are multiple lists).
Definition: nomos.h:321
Store the options sent through the CLI.
int writeARS(int agentId, int arsId, int uploadId, int success, const fo::DbManager &dbManager)
Call C function fo_WriteARS() and translate the arguments.
pair< string, list< match > > processSingleFile(const CopyrightState &state, const string fileName)