FOSSology  4.4.0
Open Source License Compliance by Open Source Software
nomos_utils.h
1 /*
2  SPDX-FileCopyrightText: © 2006-2014 Hewlett-Packard Development Company, L.P.
3 
4  SPDX-License-Identifier: GPL-2.0-only
5 */
6 
7 #ifndef NOMOS_UTILS_H_
8 #define NOMOS_UTILS_H_
9 
10 #ifndef _GNU_SOURCE
11 #define _GNU_SOURCE
12 #endif /* not defined _GNU_SOURCE */
13 #include "util.h"
14 #include "list.h"
15 #include "licenses.h"
16 #include "process.h"
17 #include "nomos.h"
18 #include "nomos_regex.h"
19 #include <_autodefs.h>
20 
21 #define PG_ERRCODE_UNIQUE_VIOLATION "23505"
22 #define FOSSY_EXIT( XY , XZ) printf(" %s %s,%d", XY , __FILE__, __LINE__); Bail( XZ );
23 #define LICENSE_REF_TABLE "ONLY license_ref"
24 #define SEM_DEFAULT_VALUE 4
25 
26 extern sem_t* mutexJson;
27 extern gboolean* printcomma;
28 
29 
31 struct cachenode
32 {
33  char *rf_shortname;
34  long rf_pk;
35 };
36 typedef struct cachenode cachenode_t;
37 
39 struct cacheroot
40 {
41  int maxnodes;
43 };
44 typedef struct cacheroot cacheroot_t;
45 
46 void freeAndClearScan(struct curScan *thisScan);
47 char *getFieldValue(char *inStr, char *field, int fieldMax, char *value, int valueMax, char separator);
48 void parseLicenseList();
49 void Usage(char *Name);
50 void Bail(int exitval);
51 int optionIsSet(int val);
52 void getFileLists(char *dirpath);
53 void processFile(char *fileToScan);
54 int recordScanToDB(cacheroot_t *pcroot, struct curScan *scanRecord);
55 long get_rfpk(cacheroot_t *pcroot, char *rf_shortname);
56 char convertIndexToHighlightType(int index);
57 long add2license_ref(char *licenseName);
58 long updateLicenseFile(long rfPk);
60 int initLicRefCache(cacheroot_t *pcroot);
61 long lrcache_hash(cacheroot_t *pcroot, char *rf_shortname);
62 int lrcache_add(cacheroot_t *pcroot, long rf_pk, char *rf_shortname);
63 long lrcache_lookup(cacheroot_t *pcroot, char *rf_shortname);
64 void lrcache_free(cacheroot_t *pcroot);
65 void initializeCurScan(struct curScan* cur);
66 void addLicence(GArray* theMatches, char* licenceName );
67 void cleanLicenceBuffer();
68 bool clearLastElementOfLicenceBuffer(); //returns true to be used in if-statements
70 MatchPositionAndType* getMatchfromHighlightInfo(GArray* in, int index);
72 void cleanTheMatches(GArray* in);
73 
74 #endif /* NOMOS_UTILS_H_ */
Usage()
Print Usage statement.
Definition: fo_dbcheck.php:63
FUNCTION void lrcache_free(cacheroot_t *pcroot)
Free the hash table.
Definition: liccache.c:72
FUNCTION long lrcache_lookup(cacheroot_t *pcroot, char *rf_shortname)
Lookup rf_pk in the license_ref cache rf_shortname is the key.
Definition: liccache.c:135
FUNCTION long add2license_ref(PGconn *pgConn, char *licenseName)
Definition: liccache.c:246
FUNCTION int lrcache_add(cacheroot_t *pcroot, long rf_pk, char *rf_shortname)
Add a rf_shortname, rf_pk to the license_ref cache rf_shortname is the key.
Definition: liccache.c:99
FUNCTION long get_rfpk(PGconn *pgConn, cacheroot_t *pcroot, char *rf_shortname)
Get the rf_pk for rf_shortname.
Definition: liccache.c:213
FUNCTION long lrcache_hash(cacheroot_t *pcroot, char *rf_shortname)
Calculate the hash of an rf_shortname rf_shortname is the key.
Definition: liccache.c:26
Nomos header file.
void Bail(int exitval)
Close connections and exit.
Definition: nomos_utils.c:533
int optionIsSet(int val)
Check if an CLI option is set.
Definition: nomos_utils.c:560
FUNCTION void freeAndClearScan(struct curScan *thisScan)
Clean-up all the per scan data structures, freeing any old data.
Definition: nomos_utils.c:941
FUNCTION char * getFieldValue(char *inStr, char *field, int fieldMax, char *value, int valueMax, char separator)
Given a string that contains field='value' pairs, save the items.
Definition: nomos_utils.c:333
sem_t * mutexJson
Mutex to handle JSON writes.
Definition: nomos_utils.c:21
FUNCTION void cleanTheMatches(GArray *theMatches)
Cleans the match array and free the memory.
Definition: nomos_utils.c:966
FUNCTION void parseLicenseList()
parse the comma separated list of license names found
Definition: nomos_utils.c:450
FUNCTION long updateLicenseFile(long rfPk)
insert rf_fk, agent_fk and pfile_fk into license_file table
Definition: nomos_utils.c:606
FUNCTION void initializeCurScan(struct curScan *cur)
Initialize the scanner.
Definition: nomos_utils.c:926
FUNCTION int recordScanToDB(cacheroot_t *pcroot, struct curScan *scanRecord)
Write out the information about the scan to the FOSSology database.
Definition: nomos_utils.c:850
void cleanLicenceBuffer()
Clean the license buffer.
Definition: nomos_utils.c:1006
FUNCTION void addLicence(GArray *theMatches, char *licenceName)
Add a license to the matches array.
Definition: nomos_utils.c:991
FUNCTION MatchPositionAndType * getMatchfromHighlightInfo(GArray *in, int index)
Get the MatchPositionAndType for a given index in highlight array.
Definition: nomos_utils.c:901
FUNCTION void getFileLists(char *dirpath)
Initialize the lists: regular-files list cur.regfList and buffer-offset list cur.offList.
Definition: nomos_utils.c:580
FUNCTION LicenceAndMatchPositions * getLicenceAndMatchPositions(GArray *in, int index)
Get the LicenceAndMatchPositions for a given index in match array.
Definition: nomos_utils.c:913
gboolean * printcomma
True to print comma while printing JSON object.
Definition: nomos_utils.c:22
FUNCTION void cleanLicenceAndMatchPositions(LicenceAndMatchPositions *in)
Cleans the license and match positions object and free the memory.
Definition: nomos_utils.c:979
FUNCTION int initLicRefCache(cacheroot_t *pcroot)
build a cache the license ref db table.
Definition: nomos_utils.c:260
bool clearLastElementOfLicenceBuffer()
Remove the last element from license buffer.
Definition: nomos_utils.c:1014
FUNCTION char convertIndexToHighlightType(int index)
Return the highlight type (K|L|0) for a given index.
Definition: nomos_utils.c:652
FUNCTION int updateLicenseHighlighting(cacheroot_t *pcroot)
insert rf_fk, agent_fk, offset, len and type into highlight table
Definition: nomos_utils.c:676
long rf_pk
License id from database.
Definition: liccache.h:32
char * rf_shortname
License shortname.
Definition: liccache.h:31
int maxnodes
No. of nodes in the list.
Definition: liccache.h:42
cachenode_t * nodes
Array of nodes.
Definition: liccache.h:43
Struct that tracks state related to current file being scanned.
Definition: nomos.h:391
FUNCTION int processFile(PGconn *pgConn, pbucketdef_t bucketDefArray, puploadtree_t puploadtree, int agent_pk, int hasPrules)
Process a file.
Definition: walk.c:167