FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
buckets.h
1 /***************************************************************
2  Copyright (C) 2010-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 #ifndef _BUCKETS_H
19 #define _BUCKETS_H 1
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <unistd.h>
23 #include <string.h>
24 #include <strings.h>
25 #include <ctype.h>
26 #include <regex.h>
27 #include <libgen.h>
28 #include <getopt.h>
29 #include <errno.h>
30 #include <signal.h>
31 #include <sys/types.h>
32 #include <sys/stat.h>
33 #include <sys/wait.h>
34 
35 #include <libfossology.h>
36 #include "liccache.h"
37 #define FUNCTION
38 
39 #define myBUFSIZ 2048
40 #define MAXSQL 1024
41 
42 #define IsContainer(mode) ((mode & 1<<29) != 0)
43 #define IsArtifact(mode) ((mode & 1<<28) != 0)
44 
45 
53 {
54  int ftype1;
55  char *regex1;
56  regex_t compRegex1;
57  int op;
58  int ftype2;
59  char *regex2;
60  regex_t compRegex2;
61 };
63 
69 {
70  int bucket_pk;
71  char *bucket_name;
73  char *regex;
74  regex_t compRegex;
75  char *dataFilename;
76  int *match_only;
77  int **match_every;
79  char stopon;
80  char applies_to;
83  int bucketpool_pk;
85 };
87 
96 {
97  int bucketpool_pk;
98  int bucketpool_name;
99  int bucketpool_version;
100  int nomos_agent_pk;
101  int bucket_agent_pk;
102  pbucketdef_t pbucketdef;
103 };
105 
111 {
113  char *ufile_name;
114  int upload_fk;
116  int pfile_fk;
117  int lft;
118  int rgt;
119 };
121 
127 {
128  char pkgname[256];
129  char pkgvers[256];
130  char vendor[256];
131  char srcpkgname[256];
132 };
133 typedef struct package_struct package_t, *ppackage_t;
134 
135 /* walk.c */
136 int walkTree(PGconn *pgConn, pbucketdef_t bucketDefArray, int agent_pk,
137  int uploadtree_pk, int skipProcessedCheck,
138  int hasPrules);
139 
140 int processFile(PGconn *pgConn, pbucketdef_t bucketDefArray,
141  puploadtree_t puploadtree, int agent_pk, int hasPrules);
142 
143 /* leaf.c */
144 int processLeaf(PGconn *pgConn, pbucketdef_t bucketDefArray,
145  puploadtree_t puploadtree, ppackage_t ppackage,
146  int agent_pk, int hasPrules);
147 
148 int *getLeafBuckets(PGconn *pgConn, pbucketdef_t bucketDefArray,
149  puploadtree_t puploadtree, ppackage_t ppackage,
150  int hasPrules);
151 
152 /* container.c */
153 int *getContainerBuckets(PGconn *pgConn, pbucketdef_t bucketDefArray, int uploadtree_pk);
154 
155 /* child.c */
156 int childInBucket(PGconn *pgConn, pbucketdef_t in_bucketDef, puploadtree_t puploadtree);
157 
158 /* write.c */
159 int writeBuckets(PGconn *pgConn, int pfile_pk, int uploadtree_pk,
160  int *bucketList, int agent_pk, int nomosagent_pk, int bucketpool_pk);
161 
162 /* match.c */
163 int matchAnyLic(PGresult *result, int numLics, regex_t *compRegex);
164 
165 
166 /* validate.c */
167 int arrayAinB (int *arrayA, int *arrayB);
168 int intAinB (int intA, int *arrayB);
169 int validate_pk (PGconn *pgConn, char *sql);
170 void Usage (char *Name);
171 int processed (PGconn *pgConn, int agent_pk, int nomos_agent_pk, int pfile_pk, int uploadtree_pk, int bucketpool_pk, int bucket_pk);
172 int UploadProcessed (PGconn *pgConn, int bucketagent_pk, int nomosagent_pk, int pfile_pk, int uploadtree_pk, int upload_pk, int bucketpool_pk);
173 
174 /* inits.c */
175 pbucketdef_t initBuckets (PGconn *pgConn, int bucketpool_pk, cacheroot_t *pcroot);
176 int *getMatchOnly (PGconn *pgConn, int bucketpool_pk, char *filename, cacheroot_t *pcroot);
177 int **getMatchEvery (PGconn *pgConn, int bucketpool_pk, char *filename, cacheroot_t *pcroot);
178 regex_file_t *getRegexFile (PGconn *pgConn, int bucketpool_pk, char *filename, cacheroot_t *pcroot);
179 int getRegexFiletype (char *token, char *filepath);
180 int getBucketpool_pk (PGconn *pgConn, char * bucketpool_name);
181 int LatestNomosAgent(PGconn *pgConn, int upload_pk);
182 int *getLicsInStr (PGconn *pgConn, char *nameStr, cacheroot_t *pcroot);
183 int childParent (PGconn *pgConn, int uploadtree_pk);
184 
185 #endif /* _BUCKETS_H */
int bucket_agent_pk
Definition: buckets.h:82
pbucketdef_t pbucketdef
Definition: buckets.h:102
char * regex
Definition: buckets.h:73
FUNCTION int arrayAinB(int *arrayA, int *arrayB)
Verify that all the values in array A are also in B.
Definition: validate.c:35
char * regex1
Definition: buckets.h:55
PGconn * pgConn
Database connection.
Definition: adj2nest.c:98
int * match_only
Definition: buckets.h:76
FUNCTION int childParent(PGconn *pgConn, int uploadtree_pk)
Given an uploadtree_pk of a container, find the uploadtree_pk of it&#39;s children (i.e. scan down through artifacts to get the children&#39;s parent.
Definition: inits.c:650
FUNCTION int LatestNomosAgent(PGconn *pgConn, int upload_pk)
Get the latest nomos agent_pk that has data for this this uploadtree.
Definition: inits.c:614
char * dataFilename
Definition: buckets.h:75
regex_file_t * regex_row
Definition: buckets.h:78
REGEX-FILE bucket type.
Definition: buckets.h:52
FUNCTION int * getMatchOnly(PGconn *pgConn, int bucketpool_pk, char *filename, cacheroot_t *pcroot)
Read the match only file (bucket type 2)
Definition: inits.c:196
FUNCTION int processFile(PGconn *pgConn, pbucketdef_t bucketDefArray, puploadtree_t puploadtree, int agent_pk, int hasPrules)
Process a file.
Definition: walk.c:178
FUNCTION int getBucketpool_pk(PGconn *pgConn, char *bucketpool_name)
Get a bucketpool_pk based on the bucketpool_name.
Definition: inits.c:34
FUNCTION int validate_pk(PGconn *pgConn, char *sql)
Verify a primary key exists.
Definition: validate.c:95
char applies_to
Definition: buckets.h:80
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:80
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:40
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:280
Usage()
Print Usage statement.
Definition: fo_dbcheck.php:75
regex_t compRegex
Definition: buckets.h:74
The main FOSSology C library.
FUNCTION int getRegexFiletype(char *token, char *filepath)
Given a filetype token from REGEX-FILE return the token int representation.
Definition: inits.c:515
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:42
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:48
char * uploadtree_tablename
upload.uploadtree_tablename
Definition: adj2nest.c:112
int ** match_every
Definition: buckets.h:77
int agent_pk
Definition: agent.h:85
FUNCTION int intAinB(int intA, int *arrayB)
Verify that all the value A is a member of array B.
Definition: validate.c:65
char * bucket_name
Definition: buckets.h:71
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:45
int nomos_agent_pk
Definition: buckets.h:81
char * ufile_name
Definition: buckets.h:113
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:150
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:371
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:215
FUNCTION int * getLicsInStr(PGconn *pgConn, char *nameStr, cacheroot_t *pcroot)
Given a string with | separated license names return an integer array of rf_pk&#39;s. ...
Definition: inits.c:540
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:63
const char * upload_pk
Definition: sqlstatements.h:93
char * regex2
Definition: buckets.h:59
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:37