25 char *fcnName =
"getBucketpool";
31 sprintf(sqlbuf,
"select bucketpool_pk from bucketpool where (bucketpool_name='%s') and (active='Y') order by version desc",
33 result = PQexec(
pgConn, sqlbuf);
35 if (PQntuples(result) > 0) bucketpool_pk = atoi(PQgetvalue(result, 0, 0));
54 char *fcnName =
"initBuckets";
65 if ((!
pgConn) || (!bucketpool_pk))
67 printf(
"ERROR: %s.%s.%d Invalid input pgConn: %lx, bucketpool_pk: %d.\n",
68 __FILE__, fcnName, __LINE__, (
unsigned long)
pgConn, bucketpool_pk);
73 sprintf(sqlbuf,
"select bucket_pk, bucket_type, bucket_regex, bucket_filename, stopon, bucket_name, applies_to from bucket_def where bucketpool_fk=%d order by bucket_evalorder asc", bucketpool_pk);
74 result = PQexec(
pgConn, sqlbuf);
76 numRows = PQntuples(result);
79 printf(
"ERROR: %s.%s.%d No bucket defs for pool %d.\n",
80 __FILE__, fcnName, __LINE__, bucketpool_pk);
85 bucketDefList = calloc(numRows+1,
sizeof(
bucketdef_t));
86 if (bucketDefList == 0)
88 printf(
"ERROR: %s.%s.%d No memory to allocate %d bucket defs.\n",
89 __FILE__, fcnName, __LINE__, numRows);
94 for (rowNum=0; rowNum<numRows; rowNum++)
96 bucketDefList[rowNum].
bucket_pk = atoi(PQgetvalue(result, rowNum, 0));
97 bucketDefList[rowNum].
bucket_type = atoi(PQgetvalue(result, rowNum, 1));
98 bucketDefList[rowNum].bucketpool_pk = bucketpool_pk;
101 if (bucketDefList[rowNum].bucket_type == 3)
103 rv = regcomp(&bucketDefList[rowNum].compRegex, PQgetvalue(result, rowNum, 2),
104 REG_NOSUB | REG_ICASE | REG_EXTENDED);
107 printf(
"ERROR: %s.%s.%d Invalid regular expression for bucketpool_pk: %d, bucket: %s\n",
108 __FILE__, fcnName, __LINE__, bucketpool_pk, PQgetvalue(result, rowNum, 5));
111 bucketDefList[rowNum].
regex = strdup(PQgetvalue(result, rowNum, 2));
114 bucketDefList[rowNum].
dataFilename = strdup(PQgetvalue(result, rowNum, 3));
117 if (strlen(bucketDefList[rowNum].dataFilename) > 0)
119 snprintf(filepath,
sizeof(filepath),
"%s/bucketpools/%d/%s",
120 PROJECTSTATEDIR, bucketpool_pk, bucketDefList[rowNum].dataFilename);
121 if (stat(filepath, &statbuf) == -1)
124 gethostname(hostname,
sizeof(hostname));
125 printf(
"ERROR: %s.%s.%d File: %s is missing on host: %s. bucketpool_pk: %d, bucket: %s\n",
126 __FILE__, fcnName, __LINE__, filepath, hostname, bucketpool_pk, PQgetvalue(result, rowNum, 5));
132 if (bucketDefList[rowNum].bucket_type == 1)
136 if (bucketDefList[rowNum].bucket_type == 2)
142 if (bucketDefList[rowNum].bucket_type == 5)
147 bucketDefList[rowNum].
stopon = *PQgetvalue(result, rowNum, 4);
148 bucketDefList[rowNum].
bucket_name = strdup(PQgetvalue(result, rowNum, 5));
149 bucketDefList[rowNum].
applies_to = *PQgetvalue(result, rowNum, 6);
152 if (numErrors)
return 0;
156 for (rowNum=0; rowNum<numRows; rowNum++)
158 printf(
"\nbucket_pk[%d] = %d\n", rowNum, bucketDefList[rowNum].bucket_pk);
159 printf(
"bucket_name[%d] = %s\n", rowNum, bucketDefList[rowNum].bucket_name);
160 printf(
"bucket_type[%d] = %d\n", rowNum, bucketDefList[rowNum].bucket_type);
161 printf(
"dataFilename[%d] = %s\n", rowNum, bucketDefList[rowNum].dataFilename);
162 printf(
"stopon[%d] = %c\n", rowNum, bucketDefList[rowNum].stopon);
163 printf(
"applies_to[%d] = %c\n", rowNum, bucketDefList[rowNum].applies_to);
164 printf(
"nomos_agent_pk[%d] = %d\n", rowNum, bucketDefList[rowNum].nomos_agent_pk);
165 printf(
"bucket_agent_pk[%d] = %d\n", rowNum, bucketDefList[rowNum].bucket_agent_pk);
166 printf(
"regex[%d] = %s\n", rowNum, bucketDefList[rowNum].regex);
170 return bucketDefList;
188 char *fcnName =
"getMatchOnly";
189 char *delims =
",\t\n\r";
200 snprintf(filepath,
sizeof(filepath),
"%s/bucketpools/%d/%s",
201 PROJECTSTATEDIR, bucketpool_pk, filename);
204 fin = fopen(filepath,
"r");
207 printf(
"FATAL: %s.%s.%d Failure to open bucket file %s (pool=%d).\nError: %s\n",
208 __FILE__, fcnName, __LINE__, filepath, bucketpool_pk, strerror(errno));
213 while (fgets(inbuf,
sizeof(inbuf), fin)) line_count++;
217 match_only = calloc(line_count+1,
sizeof(
int));
220 printf(
"FATAL: %s.%s.%d Unable to allocate %d int array.\n",
221 __FILE__, fcnName, __LINE__, line_count+1);
231 while (fgets(inbuf,
sizeof(inbuf), fin))
234 sp = strtok(inbuf, delims);
237 if ((sp == 0) || (*sp ==
'#'))
continue;
244 match_only[matchNumb++] = lr_pk;
272 char *fcnName =
"getMatchEvery";
275 int **match_every = 0;
276 int **match_every_head = 0;
283 snprintf(filepath,
sizeof(filepath),
"%s/bucketpools/%d/%s",
284 PROJECTSTATEDIR, bucketpool_pk, filename);
287 fin = fopen(filepath,
"r");
290 printf(
"FATAL: %s.%s.%d Failure to initialize bucket %s (pool=%d).\nError: %s\n",
291 __FILE__, fcnName, __LINE__, filepath, bucketpool_pk, strerror(errno));
296 while (fgets(inbuf,
sizeof(inbuf), fin)) line_count++;
300 match_every = calloc(line_count+1,
sizeof(
int *));
303 printf(
"FATAL: %s.%s.%d Unable to allocate %d int array.\n",
304 __FILE__, fcnName, __LINE__, line_count+1);
308 match_every_head = match_every;
315 while (fgets(inbuf,
sizeof(inbuf), fin))
318 if (inbuf[0] ==
'#')
continue;
323 match_every[matchNumb++] = lr_pkArray;
329 free(match_every_head);
330 match_every_head = 0;
333 return match_every_head;
363 char *fcnName =
"getRegexFile";
371 char *Delims =
" \t\n\r";
377 snprintf(filepath,
sizeof(filepath),
"%s/bucketpools/%d/%s",
378 PROJECTSTATEDIR, bucketpool_pk, filename);
381 fin = fopen(filepath,
"r");
384 printf(
"FATAL: %s.%s.%d Failure to initialize bucket %s (pool=%d).\nError: %s\n",
385 __FILE__, fcnName, __LINE__, filepath, bucketpool_pk, strerror(errno));
386 printf(
"In v1.3, files were in %s. To be LSB compliate, v1.4 now requires them to be in %s\n",
387 DATADIR, PROJECTSTATEDIR);
392 while (fgets(inbuf,
sizeof(inbuf), fin)) line_count++;
396 regex_row_head = calloc(line_count+1,
sizeof(
regex_file_t));
399 printf(
"FATAL: %s.%s.%d Unable to allocate %d regex_file_t array.\n",
400 __FILE__, fcnName, __LINE__, line_count+1);
410 while (fgets(inbuf,
sizeof(inbuf), fin))
413 if (inbuf[0] ==
'#')
continue;
416 token = strtok_r(inbuf, Delims, &saveptr);
419 if (token[0] == 0)
continue;
422 if (regex_row_head[rowNumb].ftype1 == 0)
break;
425 token = strtok_r(NULL, Delims, &saveptr);
426 regex_row_head[rowNumb].
regex1 = strdup(token);
427 rv = regcomp(®ex_row_head[rowNumb].compRegex1, token, REG_NOSUB | REG_ICASE);
430 printf(
"ERROR: %s.%s.%d Invalid regular expression for file: %s, [%s], row: %d\n",
431 __FILE__, fcnName, __LINE__, filepath, token, rowNumb+1);
437 token = strtok_r(NULL, Delims, &saveptr);
445 if (strcasecmp(token,
"and") == 0) regex_row_head[rowNumb].
op = 1;
447 if (strcasecmp(token,
"or") == 0) regex_row_head[rowNumb].
op = 2;
449 if (strcasecmp(token,
"not") == 0) regex_row_head[rowNumb].
op = 3;
452 printf(
"ERROR: %s.%s.%d Invalid operator in file: %s, [%s], row: %d\n",
453 __FILE__, fcnName, __LINE__, filepath, token, rowNumb+1);
460 token = strtok_r(NULL, Delims, &saveptr);
462 if (regex_row_head[rowNumb].ftype2 == 0)
break;
465 token = strtok_r(NULL, Delims, &saveptr);
466 regex_row_head[rowNumb].
regex2 = strdup(token);
467 rv = regcomp(®ex_row_head[rowNumb].compRegex2, token, REG_NOSUB | REG_ICASE);
470 printf(
"ERROR: %s.%s.%d Invalid regular expression for file: %s, [%s], row: %d\n",
471 __FILE__, fcnName, __LINE__, filepath, token, rowNumb+1);
482 if (errorCount) exit(-1);
486 free(regex_row_head);
490 return regex_row_head;
506 if (strcasecmp(token,
"filename") == 0)
return(1);
508 if (strcasecmp(token,
"license") == 0)
return(2);
509 printf(
"FATAL: Invalid bucket file (%s), unknown filetype (%s)\n",
532 char *fcnName =
"getLicsInStr";
533 char *delims =
"|\n\r ";
536 int *pkArrayHead = 0;
541 if (!nameStr)
return 0;
546 while (*sp)
if (*sp++ == *delims) lic_count++;
550 pkArray = calloc(lic_count+1,
sizeof(
int));
553 printf(
"FATAL: %s.%s.%d Unable to allocate %d int array.\n",
554 __FILE__, fcnName, __LINE__, lic_count+1);
557 pkArrayHead = pkArray;
562 while ((sp = strtok(nameStr, delims)) != 0)
569 pkArray[matchNumb++] = lr_pk;
605 char *fcnName =
"LatestNomosAgent";
608 int nomos_agent_pk = 0;
612 snprintf(sql,
sizeof(sql),
613 "select agent_fk from nomos_ars, agent \
614 WHERE agent_pk=agent_fk and ars_success=true and upload_fk='%d' \
615 and agent_enabled=true order by agent_ts desc limit 1",
617 result = PQexec(
pgConn, sql);
619 if (PQntuples(result) == 0)
return 0;
620 nomos_agent_pk = atoi(PQgetvalue(result,0,0));
622 return nomos_agent_pk;
641 char *fcnName =
"childParent";
644 int childParent_pk = 0;
648 snprintf(sql,
sizeof(sql),
649 "select uploadtree_pk,ufile_mode from uploadtree where parent=%d limit 1",
651 result = PQexec(
pgConn, sql);
653 if (PQntuples(result) == 0)
break;
656 if ((atoi(PQgetvalue(result, 0, 1)) & 1<<28) == 0)
658 childParent_pk = uploadtree_pk;
661 uploadtree_pk = atoi(PQgetvalue(result, 0, 0));
663 }
while (childParent_pk == 0);
666 return childParent_pk;
PGconn * pgConn
Database connection.
FUNCTION int ** getMatchEvery(PGconn *pgConn, int bucketpool_pk, char *filename, cacheroot_t *pcroot)
Read the match every file filename, for bucket type 1.
FUNCTION int * getMatchOnly(PGconn *pgConn, int bucketpool_pk, char *filename, cacheroot_t *pcroot)
Read the match only file (bucket type 2)
FUNCTION int LatestNomosAgent(PGconn *pgConn, int upload_pk)
Get the latest nomos agent_pk that has data for this this uploadtree.
FUNCTION int getRegexFiletype(char *token, char *filepath)
Given a filetype token from REGEX-FILE return the token int representation.
FUNCTION int getBucketpool_pk(PGconn *pgConn, char *bucketpool_name)
Get a bucketpool_pk based on the bucketpool_name.
FUNCTION int childParent(PGconn *pgConn, int uploadtree_pk)
Given an uploadtree_pk of a container, find the uploadtree_pk of it's children (i....
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.
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:
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.
int fo_checkPQresult(PGconn *pgConn, PGresult *result, char *sql, char *FileID, int LineNumb)
Check the result status of a postgres SELECT.
FUNCTION long lrcache_lookup(cacheroot_t *pcroot, char *rf_shortname)
Lookup rf_pk in the license_ref cache rf_shortname is the key.