FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
utils.hpp
1 /*
2  * Copyright (C) 2014-2015, 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 NINKA_AGENT_UTILS_HPP
19 #define NINKA_AGENT_UTILS_HPP
20 
21 #define AGENT_NAME "ninka"
22 #define AGENT_DESC "ninka agent"
23 #define AGENT_ARS "ninka_ars"
24 
25 #include <string>
26 #include <vector>
27 #include "files.hpp"
28 #include "licensematch.hpp"
29 #include "state.hpp"
30 
31 extern "C" {
32 #include "libfossology.h"
33 }
34 
35 using namespace std;
36 
39 int writeARS(const State& state, int arsId, int uploadId, int success, fo::DbManager& dbManager);
40 void bail(int exitval);
41 bool processUploadId(const State& state, int uploadId, NinkaDatabaseHandler& databaseHandler);
42 bool matchPFileWithLicenses(const State& state, unsigned long pFileId, NinkaDatabaseHandler& databaseHandler);
43 bool matchFileWithLicenses(const State& state, const fo::File& file, NinkaDatabaseHandler& databaseHandler);
44 bool saveLicenseMatchesToDatabase(const State& state, const vector<LicenseMatch>& matches, unsigned long pFileId, NinkaDatabaseHandler& databaseHandler);
45 
46 #endif // NINKA_AGENT_UTILS_HPP
void bail(int exitval)
Disconnect with scheduler returning an error code and exit.
DB wrapper for agents.
CopyrightState getState(CliOptions &&cliOptions)
Create a new state for the current agent based on CliOptions.
void matchFileWithLicenses(const string &sContent, unsigned long pFileId, CopyrightState const &state, int agentId, CopyrightDatabaseHandler &databaseHandler)
Scan a given file with all available scanners and save findings to database.
Class to handle file related operations.
Definition: files.hpp:29
Definition: state.hpp:26
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.
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.
void matchPFileWithLicenses(CopyrightState const &state, int agentId, unsigned long pFileId, CopyrightDatabaseHandler &databaseHandler)
Get the file contents, scan for statements and save findings to database.
Utility functions for file handling.