FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
validate.c
Go to the documentation of this file.
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  ***************************************************************/
23 #include "buckets.h"
24 extern int debug;
25 
35 FUNCTION int arrayAinB(int *arrayA, int *arrayB)
36 {
37  int *arrayBHead;
38 
39  if (!arrayA || !arrayB) return 0;
40 
41  arrayBHead = arrayB;
42  while(*arrayA)
43  {
44  arrayB = arrayBHead;
45  while (*arrayB)
46  {
47  if (*arrayA == *arrayB) break;
48  arrayB++;
49  }
50  if (!*arrayB) return 0;
51  arrayA++;
52  }
53  return 1;
54 }
55 
65 FUNCTION int intAinB(int intA, int *arrayB)
66 {
67 
68  if (!arrayB) return 0;
69 
70  while(*arrayB)
71  {
72  if (intA == *arrayB) return 1;
73  arrayB++;
74  }
75  return 0;
76 }
77 
78 
95 FUNCTION int validate_pk(PGconn *pgConn, char *sql)
96 {
97  char *fcnName = "validate_pk";
98  int pk = 0;
99  PGresult *result;
100 
101  /* Skip file if it has already been processed for buckets. */
102  result = PQexec(pgConn, sql);
103  if (fo_checkPQresult(pgConn, result, sql, fcnName, __LINE__)) return 0;
104  if (PQntuples(result) > 0) pk = atoi(PQgetvalue(result, 0, 0));
105  PQclear(result);
106  return pk;
107 }
108 
114 FUNCTION void Usage(char *Name)
115 {
116  printf("Usage: %s [debug options]\n", Name);
117  printf(" Debug options are:\n");
118  printf(" -i :: Initialize the database, then exit.\n");
119  printf(" -n :: bucketpool name of bucketpool to use.\n");
120  printf(" -p :: bucketpool_pk of bucketpool to use.\n");
121  printf(" -r :: rerun buckets.\n");
122  printf(" -t :: uploadtree_pk, root of tree to scan.\n");
123  printf(" -u :: upload_pk to scan.\n");
124  printf(" -v :: verbose (turns on copious debugging output)\n");
125  printf(" -V :: print the version info, then exit.\n");
126  printf(" -c SYSCONFDIR :: Specify the directory for the system configuration. \n");
127  printf(" NOTE: -n and -p are mutually exclusive. If both are specified\n");
128  printf(" -p is used. One of these is required.\n");
129  printf(" NOTE: -t and -u are mutually exclusive. If both are specified\n");
130  printf(" -u is used. One of these is required.\n");
131  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");
132 } /* Usage() */
133 
134 
150 FUNCTION int processed(PGconn *pgConn, int agent_pk, int nomos_agent_pk, int pfile_pk, int uploadtree_pk,
151  int bucketpool_pk, int bucket_pk)
152 {
153  char *fcnName = "processed";
154  int numRecs=0;
155  char sqlbuf[512];
156  PGresult *result;
157 
158  /* Skip file if it has already been processed for buckets.
159  See if this pfile or uploadtree_pk has any buckets. */
160  if (bucket_pk)
161  {
162  sprintf(sqlbuf,
163  "select bf_pk from bucket_file, bucket_def \
164  where pfile_fk=%d and agent_fk=%d and nomosagent_fk=%d and bucketpool_fk=%d \
165  and bucket_pk=%d and bucket_fk=bucket_pk \
166  union \
167  select bf_pk from bucket_container, bucket_def \
168  where uploadtree_fk=%d and agent_fk=%d and nomosagent_fk=%d and bucketpool_fk=%d \
169  and bucket_pk=%d and bucket_fk=bucket_pk limit 1",
170  pfile_pk, agent_pk, nomos_agent_pk, bucketpool_pk, bucket_pk,
171  uploadtree_pk, agent_pk, nomos_agent_pk, bucketpool_pk, bucket_pk);
172  }
173  else
174  {
175  sprintf(sqlbuf,
176  "select bf_pk from bucket_file, bucket_def \
177  where pfile_fk=%d and agent_fk=%d and nomosagent_fk=%d and bucketpool_fk=%d \
178  and bucket_fk=bucket_pk \
179  union \
180  select bf_pk from bucket_container, bucket_def \
181  where uploadtree_fk=%d and agent_fk=%d and nomosagent_fk=%d and bucketpool_fk=%d \
182  and bucket_fk=bucket_pk limit 1",
183  pfile_pk, agent_pk, nomos_agent_pk, bucketpool_pk,
184  uploadtree_pk, agent_pk, nomos_agent_pk, bucketpool_pk);
185  }
186  result = PQexec(pgConn, sqlbuf);
187  if (fo_checkPQresult(pgConn, result, sqlbuf, __FILE__, __LINE__)) return -1;
188  numRecs = PQntuples(result);
189  PQclear(result);
190 
191  if (debug) printf("%s: returning %d, for pfile_pk %d, uploadtree_pk %d\n",fcnName,numRecs,pfile_pk, uploadtree_pk);
192  return numRecs;
193 }
194 
195 
215 FUNCTION int UploadProcessed(PGconn *pgConn, int bucketagent_pk, int nomosagent_pk,
216  int pfile_pk, int uploadtree_pk,
217  int upload_pk, int bucketpool_pk)
218 {
219  char *fcnName = "UploadProcessed";
220  int numRecs=0;
221  char sqlbuf[512];
222  PGresult *result;
223 
224  /* Check bucket_ars to see if there has been a successful run */
225  sprintf(sqlbuf,
226  "select ars_pk from bucket_ars \
227  where agent_fk=%d and nomosagent_fk=%d and upload_fk=%d and bucketpool_fk=%d \
228  and ars_success=true limit 1",
229  bucketagent_pk, nomosagent_pk, upload_pk, bucketpool_pk);
230  result = PQexec(pgConn, sqlbuf);
231  if (fo_checkPQresult(pgConn, result, sqlbuf, fcnName, __LINE__)) return -1;
232  numRecs = PQntuples(result);
233  PQclear(result);
234 
235  return numRecs;
236 }
int fo_checkPQresult(PGconn *pgConn, PGresult *result, char *sql, char *FileID, int LineNumb)
Check the result status of a postgres SELECT.
Definition: libfossdb.c:181
FUNCTION int arrayAinB(int *arrayA, int *arrayB)
Verify that all the values in array A are also in B.
Definition: validate.c:35
PGconn * pgConn
Database connection.
Definition: adj2nest.c:98
FUNCTION void Usage(char *Name)
Definition: validate.c:114
FUNCTION int validate_pk(PGconn *pgConn, char *sql)
Verify a primary key exists.
Definition: validate.c:95
int debug
Definition: buckets.c:68
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
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 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
const char * upload_pk
Definition: sqlstatements.h:93