FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
nomos_utils.h
1 /***************************************************************
2  Copyright (C) 2006-2014 Hewlett-Packard Development Company, L.P.
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 
19 #ifndef NOMOS_UTILS_H_
20 #define NOMOS_UTILS_H_
21 
22 #ifndef _GNU_SOURCE
23 #define _GNU_SOURCE
24 #endif /* not defined _GNU_SOURCE */
25 #include "util.h"
26 #include "list.h"
27 #include "licenses.h"
28 #include "process.h"
29 #include "nomos.h"
30 #include "nomos_regex.h"
31 #include "_autodefs.h"
32 
33 #define PG_ERRCODE_UNIQUE_VIOLATION "23505"
34 #define FOSSY_EXIT( XY , XZ) printf(" %s %s,%d", XY , __FILE__, __LINE__); Bail( XZ );
35 #define LICENSE_REF_TABLE "ONLY license_ref"
36 #define SEM_DEFAULT_VALUE 4
37 
38 sem_t* mutexJson;
39 gboolean* printcomma;
40 
41 
43 struct cachenode
44 {
45  char *rf_shortname;
46  long rf_pk;
47 };
48 typedef struct cachenode cachenode_t;
49 
51 struct cacheroot
52 {
53  int maxnodes;
54  cachenode_t *nodes;
55 };
56 typedef struct cacheroot cacheroot_t;
57 
58 void freeAndClearScan(struct curScan *thisScan);
59 char *getFieldValue(char *inStr, char *field, int fieldMax, char *value, int valueMax, char separator);
60 void parseLicenseList();
61 void Usage(char *Name);
62 void Bail(int exitval);
63 int optionIsSet(int val);
64 void getFileLists(char *dirpath);
65 void processFile(char *fileToScan);
66 int recordScanToDB(cacheroot_t *pcroot, struct curScan *scanRecord);
67 long get_rfpk(cacheroot_t *pcroot, char *rf_shortname);
68 char convertIndexToHighlightType(int index);
69 long add2license_ref(char *licenseName);
70 long updateLicenseFile(long rfPk);
72 int initLicRefCache(cacheroot_t *pcroot);
73 long lrcache_hash(cacheroot_t *pcroot, char *rf_shortname);
74 int lrcache_add(cacheroot_t *pcroot, long rf_pk, char *rf_shortname);
75 long lrcache_lookup(cacheroot_t *pcroot, char *rf_shortname);
76 void lrcache_free(cacheroot_t *pcroot);
77 void initializeCurScan(struct curScan* cur);
78 void addLicence(GArray* theMatches, char* licenceName );
79 void cleanLicenceBuffer();
80 bool clearLastElementOfLicenceBuffer(); //returns true to be used in if-statements
82 MatchPositionAndType* getMatchfromHighlightInfo(GArray* in, int index);
84 void cleanTheMatches(GArray* in);
85 
86 #endif /* NOMOS_UTILS_H_ */
FUNCTION int recordScanToDB(cacheroot_t *pcroot, struct curScan *scanRecord)
Write out the information about the scan to the FOSSology database.
Definition: nomos_utils.c:858
FUNCTION long add2license_ref(PGconn *pgConn, char *licenseName)
Definition: liccache.c:257
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:146
int optionIsSet(int val)
Check if an CLI option is set.
Definition: nomos_utils.c:568
FUNCTION void getFileLists(char *dirpath)
Initialize the lists: regular-files list cur.regfList and buffer-offset list cur.offList.
Definition: nomos_utils.c:588
FUNCTION void parseLicenseList()
parse the comma separated list of license names found
Definition: nomos_utils.c:458
FUNCTION void cleanLicenceAndMatchPositions(LicenceAndMatchPositions *in)
Cleans the license and match positions object and free the memory.
Definition: nomos_utils.c:987
void Bail(int exitval)
Close connections and exit.
Definition: nomos_utils.c:541
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:110
FUNCTION MatchPositionAndType * getMatchfromHighlightInfo(GArray *in, int index)
Get the MatchPositionAndType for a given index in highlight array.
Definition: nomos_utils.c:909
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:37
FUNCTION int processFile(PGconn *pgConn, pbucketdef_t bucketDefArray, puploadtree_t puploadtree, int agent_pk, int hasPrules)
Process a file.
Definition: walk.c:178
FUNCTION void lrcache_free(cacheroot_t *pcroot)
Free the hash table.
Definition: liccache.c:83
FUNCTION long get_rfpk(PGconn *pgConn, cacheroot_t *pcroot, char *rf_shortname)
Get the rf_pk for rf_shortname.
Definition: liccache.c:224
FUNCTION int updateLicenseHighlighting(cacheroot_t *pcroot)
insert rf_fk, agent_fk, offset, len and type into highlight table
Definition: nomos_utils.c:684
bool clearLastElementOfLicenceBuffer()
Remove the last element from license buffer.
Definition: nomos_utils.c:1022
FUNCTION void addLicence(GArray *theMatches, char *licenceName)
Add a license to the matches array.
Definition: nomos_utils.c:999
FUNCTION void cleanTheMatches(GArray *theMatches)
Cleans the match array and free the memory.
Definition: nomos_utils.c:974
FUNCTION LicenceAndMatchPositions * getLicenceAndMatchPositions(GArray *in, int index)
Get the LicenceAndMatchPositions for a given index in match array.
Definition: nomos_utils.c:921
Usage()
Print Usage statement.
Definition: fo_dbcheck.php:75
FUNCTION void freeAndClearScan(struct curScan *thisScan)
Clean-up all the per scan data structures, freeing any old data.
Definition: nomos_utils.c:949
FUNCTION long updateLicenseFile(long rfPk)
insert rf_fk, agent_fk and pfile_fk into license_file table
Definition: nomos_utils.c:614
char * rf_shortname
License shortname.
Definition: liccache.h:42
Nomos header file.
FUNCTION char convertIndexToHighlightType(int index)
Return the highlight type (K|L|0) for a given index.
Definition: nomos_utils.c:660
void cleanLicenceBuffer()
Clean the license buffer.
Definition: nomos_utils.c:1014
long rf_pk
License id from database.
Definition: liccache.h:43
Struct that tracks state related to current file being scanned.
Definition: nomos.h:404
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:341
FUNCTION int initLicRefCache(cacheroot_t *pcroot)
build a cache the license ref db table.
Definition: nomos_utils.c:268
FUNCTION void initializeCurScan(struct curScan *cur)
Initialize the scanner.
Definition: nomos_utils.c:934