FOSSology  4.4.0
Open Source License Compliance by Open Source Software
scancode_utils.hpp
1 /*
2  SPDX-FileCopyrightText: © 2021 Sarita Singh <saritasingh.0425@gmail.com>
3 
4  SPDX-License-Identifier: GPL-2.0-only
5 */
6 
7 #ifndef SCANCODE_AGENT_UTILS_HPP
8 #define SCANCODE_AGENT_UTILS_HPP
9 
10 #define AGENT_NAME "scancode"
11 #define AGENT_DESC "scancode agent"
12 #define AGENT_ARS "scancode_ars"
13 
14 #include <iostream>
15 #include <string>
16 #include <vector>
17 #include <unordered_map>
18 
19 #include <boost/program_options.hpp>
20 
21 #include "files.hpp"
22 #include "match.hpp"
23 #include "scancode_state.hpp"
24 #include "scancode_wrapper.hpp"
25 
26 extern "C" {
27 #include "libfossology.h"
28 }
29 
30 using namespace std;
31 
35 using namespace fo;
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, ScancodeDatabaseHandler& databaseHandler, bool ignoreFilesWithMimeType);
42 void mapFileNameWithId(unsigned long pFileId, unordered_map<unsigned long, string> &fileIdsMap, unordered_map<string, unsigned long> &fileIdsMapReverse, ScancodeDatabaseHandler &databaseHandler);
43 void writeFileNameToTextFile(unordered_map<unsigned long, string> &fileIdsMap, string fileLocation);
44 string getScanResult(const string& line);
45 bool matchFileWithLicenses(const State& state, ScancodeDatabaseHandler& databaseHandler, string scancodeResult, string& fileName, unsigned long fileId);
46 bool saveLicenseMatchesToDatabase(const State& state, const vector<Match>& matches, unsigned long pFileId, ScancodeDatabaseHandler& databaseHandler);
47 bool saveOtherMatchesToDatabase(const State& state, const vector<Match>& matches, unsigned long pFileId, ScancodeDatabaseHandler& databaseHandler);
48 bool parseCommandLine(int argc, char** argv, string& cliOption, bool& ignoreFilesWithMimeType);
49 
50 #endif // SCANCODE_AGENT_UTILS_HPP
Definition: state.hpp:16
DB wrapper for agents.
int queryAgentId(PGconn *dbConn)
Get agent id, exit if agent id is incorrect.
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.
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 bail(int exitval)
Disconnect with scheduler returning an error code and exit.
Utility functions for file handling.
The main FOSSology C library.
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:16
fo namespace holds the FOSSology library functions.