FOSSology  4.5.1
Open Source License Compliance by Open Source Software
CompatibilityUtils.hpp
1 /*
2  SPDX-FileCopyrightText: © 2024 Siemens AG
3 
4  SPDX-License-Identifier: GPL-2.0-only
5 */
6 
7 #ifndef COMPATIBILITY_AGENT_UTILS_HPP
8 #define COMPATIBILITY_AGENT_UTILS_HPP
9 
10 #define AGENT_NAME "compatibility"
11 #define AGENT_DESC "compatibility agent"
12 #define AGENT_ARS "compatibility_ars"
13 
15 #include "CompatibilityState.hpp"
16 #include "libfossologyCPP.hpp"
17 
18 #include <boost/program_options.hpp>
19 #include "yaml-cpp/yaml.h"
20 #include "json/json.h"
21 #include <utility>
22 #include <vector>
23 
24 extern "C"
25 {
26 #include "libfossology.h"
27 }
28 
29 using namespace std;
30 
32  CompatibilityCliOptions&& cliOptions);
35 int writeARS(const CompatibilityState& state, int arsId, int uploadId,
36  int success, fo::DbManager& dbManager);
37 void bail(int exitval);
38 bool processUploadId(const CompatibilityState& state, int uploadId,
39  CompatibilityDatabaseHandler& databaseHandler,
40  int groupId);
41 bool parseCliOptions(int argc, char** argv, CompatibilityCliOptions& dest,
42  std::string& types, std::string& rules, string& jFile,
43  string& mainLicense);
44 void appendToJson(const std::vector<tuple<string, string, bool>>& resultPair,
45  const std::string& fileName, bool& printComma);
47  const std::vector<tuple<string, string, bool>>& resultPair,
48  const std::string& fileName);
49 std::set<std::string> mainLicenseToSet(const string& mainLicense);
50 bool are_licenses_compatible(const string& first_name, const string& first_type,
51  const string& second_name, const string& second_type,
52  const map<tuple<string, string, string, string>, bool>& rule_list);
53 map<tuple<string, string, string, string>, bool> initialize_rule_list(
54  const string& file_location);
55 unordered_map<string, string> initialize_license_map(
56  const string& file_location);
57 
58 #endif // COMPATIBILITY_AGENT_UTILS_HPP
Database handler for COMPATIBILITY.
map< tuple< string, string, string, string >, bool > initialize_rule_list(const string &file_location)
Read YAML file of rules and parse it as map.
unordered_map< string, string > initialize_license_map(const string &file_location)
Parse license type CSV and create a map.
bool processUploadId(const CompatibilityState &state, int uploadId, CompatibilityDatabaseHandler &databaseHandler, int groupId)
bool parseCliOptions(int argc, char **argv, CompatibilityCliOptions &dest, std::string &types, std::string &rules, string &jFile, string &mainLicense)
Parse the options sent by CLI to CliOptions object.
void printResultToStdout(const std::vector< tuple< string, string, bool >> &resultPair, const std::string &fileName)
CompatibilityState getState(DbManager &dbManager, CompatibilityCliOptions &&cliOptions)
Create a new state for the current agent based on CliOptions.
int writeARS(const CompatibilityState &state, int arsId, int uploadId, int success, DbManager &dbManager)
int queryAgentId(DbManager &dbManager)
std::set< std::string > mainLicenseToSet(const string &mainLicense)
void appendToJson(const std::vector< tuple< string, string, bool >> &resultPair, const std::string &fileName, bool &printComma)
void bail(int exitval)
bool are_licenses_compatible(const string &first_name, const string &first_type, const string &second_name, const string &second_type, const map< tuple< string, string, string, string >, bool > &rule_list)
Check the licenses against rules and get the compatibility result.
Store the options sent through the CLI.
Store the state of the agent.
DB wrapper for agents.
The main FOSSology CPP library.
The main FOSSology C library.
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:16