FOSSology  4.4.0
Open Source License Compliance by Open Source Software
validate.c
Go to the documentation of this file.
1 /*
2  SPDX-FileCopyrightText: © 2010-2014 Hewlett-Packard Development Company, L.P.
3 
4  SPDX-License-Identifier: GPL-2.0-only
5 */
6 
12 #include "buckets.h"
13 extern int debug;
14 
24 FUNCTION int arrayAinB(int *arrayA, int *arrayB)
25 {
26  int *arrayBHead;
27 
28  if (!arrayA || !arrayB) return 0;
29 
30  arrayBHead = arrayB;
31  while(*arrayA)
32  {
33  arrayB = arrayBHead;
34  while (*arrayB)
35  {
36  if (*arrayA == *arrayB) break;
37  arrayB++;
38  }
39  if (!*arrayB) return 0;
40  arrayA++;
41  }
42  return 1;
43 }
44 
54 FUNCTION int intAinB(int intA, int *arrayB)
55 {
56 
57  if (!arrayB) return 0;
58 
59  while(*arrayB)
60  {
61  if (intA == *arrayB) return 1;
62  arrayB++;
63  }
64  return 0;
65 }
66 
67 
84 FUNCTION int validate_pk(PGconn *pgConn, char *sql)
85 {
86  char *fcnName = "validate_pk";
87  int pk = 0;
88  PGresult *result;
89 
90  /* Skip file if it has already been processed for buckets. */
91  result = PQexec(pgConn, sql);
92  if (fo_checkPQresult(pgConn, result, sql, fcnName, __LINE__)) return 0;
93  if (PQntuples(result) > 0) pk = atoi(PQgetvalue(result, 0, 0));
94  PQclear(result);
95  return pk;
96 }
97 
103 FUNCTION void Usage(char *Name)
104 {
105  printf("Usage: %s [debug options]\n", Name);
106  printf(" Debug options are:\n");
107  printf(" -i :: Initialize the database, then exit.\n");
108  printf(" -n :: bucketpool name of bucketpool to use.\n");
109  printf(" -p :: bucketpool_pk of bucketpool to use.\n");
110  printf(" -r :: rerun buckets.\n");
111  printf(" -t :: uploadtree_pk, root of tree to scan.\n");
112  printf(" -u :: upload_pk to scan.\n");
113  printf(" -v :: verbose (turns on copious debugging output)\n");
114  printf(" -V :: print the version info, then exit.\n");
115  printf(" -c SYSCONFDIR :: Specify the directory for the system configuration. \n");
116  printf(" NOTE: -n and -p are mutually exclusive. If both are specified\n");
117  printf(" -p is used. One of these is required.\n");
118  printf(" NOTE: -t and -u are mutually exclusive. If both are specified\n");
119  printf(" -u is used. One of these is required.\n");
120  printf(" NOTE: If none of -nptu are specified, the bucketpool_pk and upload_pk are read from stdin, one comma delimited pair per line. For example, 'bppk=123, upk=987' where 123 is the bucketpool_pk and 987 is the upload_pk. This is the normal execution from the scheduler.\n");
121 } /* Usage() */
122 
123 
139 FUNCTION int processed(PGconn *pgConn, int agent_pk, int nomos_agent_pk, int pfile_pk, int uploadtree_pk,
140  int bucketpool_pk, int bucket_pk)
141 {
142  char *fcnName = "processed";
143  int numRecs=0;
144  char sqlbuf[512];
145  PGresult *result;
146 
147  /* Skip file if it has already been processed for buckets.
148  See if this pfile or uploadtree_pk has any buckets. */
149  if (bucket_pk)
150  {
151  sprintf(sqlbuf,
152  "select bf_pk from bucket_file, bucket_def \
153  where pfile_fk=%d and agent_fk=%d and nomosagent_fk=%d and bucketpool_fk=%d \
154  and bucket_pk=%d and bucket_fk=bucket_pk \
155  union \
156  select bf_pk from bucket_container, bucket_def \
157  where uploadtree_fk=%d and agent_fk=%d and nomosagent_fk=%d and bucketpool_fk=%d \
158  and bucket_pk=%d and bucket_fk=bucket_pk limit 1",
159  pfile_pk, agent_pk, nomos_agent_pk, bucketpool_pk, bucket_pk,
160  uploadtree_pk, agent_pk, nomos_agent_pk, bucketpool_pk, bucket_pk);
161  }
162  else
163  {
164  sprintf(sqlbuf,
165  "select bf_pk from bucket_file, bucket_def \
166  where pfile_fk=%d and agent_fk=%d and nomosagent_fk=%d and bucketpool_fk=%d \
167  and bucket_fk=bucket_pk \
168  union \
169  select bf_pk from bucket_container, bucket_def \
170  where uploadtree_fk=%d and agent_fk=%d and nomosagent_fk=%d and bucketpool_fk=%d \
171  and bucket_fk=bucket_pk limit 1",
172  pfile_pk, agent_pk, nomos_agent_pk, bucketpool_pk,
173  uploadtree_pk, agent_pk, nomos_agent_pk, bucketpool_pk);
174  }
175  result = PQexec(pgConn, sqlbuf);
176  if (fo_checkPQresult(pgConn, result, sqlbuf, __FILE__, __LINE__)) return -1;
177  numRecs = PQntuples(result);
178  PQclear(result);
179 
180  if (debug) printf("%s: returning %d, for pfile_pk %d, uploadtree_pk %d\n",fcnName,numRecs,pfile_pk, uploadtree_pk);
181  return numRecs;
182 }
183 
184 
204 FUNCTION int UploadProcessed(PGconn *pgConn, int bucketagent_pk, int nomosagent_pk,
205  int pfile_pk, int uploadtree_pk,
206  int upload_pk, int bucketpool_pk)
207 {
208  char *fcnName = "UploadProcessed";
209  int numRecs=0;
210  char sqlbuf[512];
211  PGresult *result;
212 
213  /* Check bucket_ars to see if there has been a successful run */
214  sprintf(sqlbuf,
215  "select ars_pk from bucket_ars \
216  where agent_fk=%d and nomosagent_fk=%d and upload_fk=%d and bucketpool_fk=%d \
217  and ars_success=true limit 1",
218  bucketagent_pk, nomosagent_pk, upload_pk, bucketpool_pk);
219  result = PQexec(pgConn, sqlbuf);
220  if (fo_checkPQresult(pgConn, result, sqlbuf, fcnName, __LINE__)) return -1;
221  numRecs = PQntuples(result);
222  PQclear(result);
223 
224  return numRecs;
225 }
PGconn * pgConn
Database connection.
Definition: adj2nest.c:86
int agent_pk
Definition: agent.h:74
int fo_checkPQresult(PGconn *pgConn, PGresult *result, char *sql, char *FileID, int LineNumb)
Check the result status of a postgres SELECT.
Definition: libfossdb.c:170
const char * upload_pk
Definition: sqlstatements.h:82
FUNCTION void Usage(char *Name)
Definition: validate.c:103
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
int debug
Definition: buckets.c:57
FUNCTION int arrayAinB(int *arrayA, int *arrayB)
Verify that all the values in array A are also in B.
Definition: validate.c:24