FOSSology  4.4.0
Open Source License Compliance by Open Source Software
buckets.h
1 /*
2  SPDX-FileCopyrightText: © 2010-2014 Hewlett-Packard Development Company, L.P.
3 
4  SPDX-License-Identifier: GPL-2.0-only
5 */
6 
7 #ifndef _BUCKETS_H
8 #define _BUCKETS_H 1
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <unistd.h>
12 #include <string.h>
13 #include <strings.h>
14 #include <ctype.h>
15 #include <regex.h>
16 #include <libgen.h>
17 #include <getopt.h>
18 #include <errno.h>
19 #include <signal.h>
20 #include <sys/types.h>
21 #include <sys/stat.h>
22 #include <sys/wait.h>
23 
24 #include <libfossology.h>
25 #include "liccache.h"
26 #define FUNCTION
27 
28 #define myBUFSIZ 2048
29 #define MAXSQL 1024
30 
31 #define IsContainer(mode) ((mode & 1<<29) != 0)
32 #define IsArtifact(mode) ((mode & 1<<28) != 0)
33 
34 
42 {
43  int ftype1;
44  char *regex1;
45  regex_t compRegex1;
46  int op;
47  int ftype2;
48  char *regex2;
49  regex_t compRegex2;
50 };
52 
58 {
59  int bucket_pk;
60  char *bucket_name;
62  char *regex;
63  regex_t compRegex;
64  char *dataFilename;
65  int *match_only;
66  int **match_every;
68  char stopon;
69  char applies_to;
72  int bucketpool_pk;
73  char *uploadtree_tablename;
74 };
76 
85 {
86  int bucketpool_pk;
87  int bucketpool_name;
88  int bucketpool_version;
89  int nomos_agent_pk;
90  int bucket_agent_pk;
92 };
94 
100 {
102  char *ufile_name;
103  int upload_fk;
105  int pfile_fk;
106  int lft;
107  int rgt;
108 };
110 
116 {
117  char pkgname[256];
118  char pkgvers[256];
119  char vendor[256];
120  char srcpkgname[256];
121 };
122 typedef struct package_struct package_t, *ppackage_t;
123 
124 /* walk.c */
125 int walkTree(PGconn *pgConn, pbucketdef_t bucketDefArray, int agent_pk,
126  int uploadtree_pk, int skipProcessedCheck,
127  int hasPrules);
128 
129 int processFile(PGconn *pgConn, pbucketdef_t bucketDefArray,
130  puploadtree_t puploadtree, int agent_pk, int hasPrules);
131 
132 /* leaf.c */
133 int processLeaf(PGconn *pgConn, pbucketdef_t bucketDefArray,
134  puploadtree_t puploadtree, ppackage_t ppackage,
135  int agent_pk, int hasPrules);
136 
137 int *getLeafBuckets(PGconn *pgConn, pbucketdef_t bucketDefArray,
138  puploadtree_t puploadtree, ppackage_t ppackage,
139  int hasPrules);
140 
141 /* container.c */
142 int *getContainerBuckets(PGconn *pgConn, pbucketdef_t bucketDefArray, int uploadtree_pk);
143 
144 /* child.c */
145 int childInBucket(PGconn *pgConn, pbucketdef_t in_bucketDef, puploadtree_t puploadtree);
146 
147 /* write.c */
148 int writeBuckets(PGconn *pgConn, int pfile_pk, int uploadtree_pk,
149  int *bucketList, int agent_pk, int nomosagent_pk, int bucketpool_pk);
150 
151 /* match.c */
152 int matchAnyLic(PGresult *result, int numLics, regex_t *compRegex);
153 
154 
155 /* validate.c */
156 int arrayAinB (int *arrayA, int *arrayB);
157 int intAinB (int intA, int *arrayB);
158 int validate_pk (PGconn *pgConn, char *sql);
159 void Usage (char *Name);
160 int processed (PGconn *pgConn, int agent_pk, int nomos_agent_pk, int pfile_pk, int uploadtree_pk, int bucketpool_pk, int bucket_pk);
161 int UploadProcessed (PGconn *pgConn, int bucketagent_pk, int nomosagent_pk, int pfile_pk, int uploadtree_pk, int upload_pk, int bucketpool_pk);
162 
163 /* inits.c */
164 pbucketdef_t initBuckets (PGconn *pgConn, int bucketpool_pk, cacheroot_t *pcroot);
165 int *getMatchOnly (PGconn *pgConn, int bucketpool_pk, char *filename, cacheroot_t *pcroot);
166 int **getMatchEvery (PGconn *pgConn, int bucketpool_pk, char *filename, cacheroot_t *pcroot);
167 regex_file_t *getRegexFile (PGconn *pgConn, int bucketpool_pk, char *filename, cacheroot_t *pcroot);
168 int getRegexFiletype (char *token, char *filepath);
169 int getBucketpool_pk (PGconn *pgConn, char * bucketpool_name);
170 int LatestNomosAgent(PGconn *pgConn, int upload_pk);
171 int *getLicsInStr (PGconn *pgConn, char *nameStr, cacheroot_t *pcroot);
172 int childParent (PGconn *pgConn, int uploadtree_pk);
173 
174 #endif /* _BUCKETS_H */
PGconn * pgConn
Database connection.
Definition: adj2nest.c:86
int agent_pk
Definition: agent.h:74
FUNCTION int matchAnyLic(PGresult *result, int numLics, regex_t *compRegex)
Does this regex match any license name for this pfile?
Definition: match.c:24
FUNCTION int childInBucket(PGconn *pgConn, pbucketdef_t bucketDef, puploadtree_t puploadtree)
Given a container uploadtree_pk and bucketdef, determine if any child is in this bucket.
Definition: child.c:26
FUNCTION int * getContainerBuckets(PGconn *pgConn, pbucketdef_t bucketDefArray, int uploadtree_pk)
Given a container uploadtree_pk and bucketdef, determine what buckets the container is in.
Definition: container.c:36
Usage()
Print Usage statement.
Definition: fo_dbcheck.php:63
FUNCTION int ** getMatchEvery(PGconn *pgConn, int bucketpool_pk, char *filename, cacheroot_t *pcroot)
Read the match every file filename, for bucket type 1.
Definition: inits.c:269
FUNCTION int * getMatchOnly(PGconn *pgConn, int bucketpool_pk, char *filename, cacheroot_t *pcroot)
Read the match only file (bucket type 2)
Definition: inits.c:185
FUNCTION int LatestNomosAgent(PGconn *pgConn, int upload_pk)
Get the latest nomos agent_pk that has data for this this uploadtree.
Definition: inits.c:603
FUNCTION int getRegexFiletype(char *token, char *filepath)
Given a filetype token from REGEX-FILE return the token int representation.
Definition: inits.c:504
FUNCTION int getBucketpool_pk(PGconn *pgConn, char *bucketpool_name)
Get a bucketpool_pk based on the bucketpool_name.
Definition: inits.c:23
FUNCTION int childParent(PGconn *pgConn, int uploadtree_pk)
Given an uploadtree_pk of a container, find the uploadtree_pk of it's children (i....
Definition: inits.c:639
FUNCTION int * getLicsInStr(PGconn *pgConn, char *nameStr, cacheroot_t *pcroot)
Given a string with | separated license names return an integer array of rf_pk's.
Definition: inits.c:529
FUNCTION regex_file_t * getRegexFile(PGconn *pgConn, int bucketpool_pk, char *filename, cacheroot_t *pcroot)
Parse filename, for bucket type 5 REGEX-FILE Lines are in format:
Definition: inits.c:360
FUNCTION pbucketdef_t initBuckets(PGconn *pgConn, int bucketpool_pk, cacheroot_t *pcroot)
Initialize the bucket definition list. If an error occured, write the error to stdout.
Definition: inits.c:52
FUNCTION int processLeaf(PGconn *pgConn, pbucketdef_t bucketDefArray, puploadtree_t puploadtree, ppackage_t ppackage, int agent_pk, int hasPrules)
Determine which bucket(s) a leaf node is in and write results.
Definition: leaf.c:30
FUNCTION int * getLeafBuckets(PGconn *pgConn, pbucketdef_t in_bucketDefArray, puploadtree_t puploadtree, ppackage_t ppackage, int hasPrules)
Determine what buckets the pfile is in.
Definition: leaf.c:68
The main FOSSology C library.
const char * upload_pk
Definition: sqlstatements.h:82
char * bucket_name
Definition: buckets.h:60
char * regex
Definition: buckets.h:62
int ** match_every
Definition: buckets.h:66
int nomos_agent_pk
Definition: buckets.h:70
int bucket_agent_pk
Definition: buckets.h:71
char applies_to
Definition: buckets.h:69
regex_file_t * regex_row
Definition: buckets.h:67
regex_t compRegex
Definition: buckets.h:63
char * dataFilename
Definition: buckets.h:64
int * match_only
Definition: buckets.h:65
pbucketdef_t pbucketdef
Definition: buckets.h:91
char vendor[256]
Definition: buckets.h:119
char pkgname[256]
Definition: buckets.h:117
char srcpkgname[256]
Definition: buckets.h:120
char pkgvers[256]
Definition: buckets.h:118
REGEX-FILE bucket type.
Definition: buckets.h:42
char * regex1
Definition: buckets.h:44
char * regex2
Definition: buckets.h:48
char * ufile_name
Definition: buckets.h:102
FUNCTION int UploadProcessed(PGconn *pgConn, int bucketagent_pk, int nomosagent_pk, int pfile_pk, int uploadtree_pk, int upload_pk, int bucketpool_pk)
Has this upload already been bucket processed? This function checks buckets_ars to see if the upload ...
Definition: validate.c:204
FUNCTION int intAinB(int intA, int *arrayB)
Verify that all the value A is a member of array B.
Definition: validate.c:54
FUNCTION int validate_pk(PGconn *pgConn, char *sql)
Verify a primary key exists.
Definition: validate.c:84
FUNCTION int processed(PGconn *pgConn, int agent_pk, int nomos_agent_pk, int pfile_pk, int uploadtree_pk, int bucketpool_pk, int bucket_pk)
Has this pfile or uploadtree_pk already been bucket processed? This only works if the bucket has been...
Definition: validate.c:139
FUNCTION int arrayAinB(int *arrayA, int *arrayB)
Verify that all the values in array A are also in B.
Definition: validate.c:24
FUNCTION int walkTree(PGconn *pgConn, pbucketdef_t bucketDefArray, int agent_pk, int uploadtree_pk, int skipProcessedCheck, int hasPrules)
This function does a recursive depth first walk through a file tree (uploadtree).
Definition: walk.c:34
FUNCTION int processFile(PGconn *pgConn, pbucketdef_t bucketDefArray, puploadtree_t puploadtree, int agent_pk, int hasPrules)
Process a file.
Definition: walk.c:167
FUNCTION int writeBuckets(PGconn *pgConn, int pfile_pk, int uploadtree_pk, int *bucketList, int agent_pk, int nomosagent_pk, int bucketpool_pk)
Write bucket results to either db (bucket_file, bucket_container) or stdout.
Definition: write.c:29