41 LOG_VERBOSE(
"ProcessFile: %s",FilePath);
44 fin = fopen(FilePath,
"r");
47 LOG_ERROR(
"FATAL: %s.%s.%d Failure to open file %s.\nError: %s\n",
48 __FILE__,
"ProcessFile()", __LINE__, FilePath, strerror(errno));
53 rv = fread(FileResult->
Buf,
sizeof(
char),
sizeof(FileResult->
Buf), fin);
86 char *RepoArea =
"files";
88 char *ufile_mode =
"10000000";
92 char* SelectFilename_sql =
"\ 93 SELECT pfile_pk, pfile_sha1 || '.' || pfile_md5 || '.' || pfile_size AS pfilename \ 94 FROM ( SELECT distinct(pfile_fk) AS PF FROM uploadtree \ 95 WHERE upload_fk = %d and (ufile_mode&x'%s'::int)=0 \ 97 left outer join demomod on (PF = pfile_fk ) \ 98 inner join pfile on (PF = pfile_pk) \ 99 WHERE demomod_pk IS null or agent_fk <> %d";
100 char* SelectFilename2_sql =
"\ 101 SELECT pfile_pk, pfile_sha1 || '.' || pfile_md5 || '.' || pfile_size AS pfilename \ 102 FROM ( SELECT distinct(pfile_fk) AS PF FROM %s \ 103 WHERE (ufile_mode&x'%s'::int)=0 \ 105 left outer join demomod on (PF = pfile_fk ) \ 106 inner join pfile on (PF = pfile_pk) \ 107 WHERE demomod_pk IS null or agent_fk <> %d";
111 if (!uploadtree_tablename)
113 LOG_FATAL(
"demomod passed invalid upload, upload_pk = %d", upload_pk);
120 LastChar = uploadtree_tablename[strlen(uploadtree_tablename)-1];
121 if (LastChar >=
'0' && LastChar <=
'9')
123 snprintf(sqlbuf,
sizeof(sqlbuf), SelectFilename2_sql, uploadtree_tablename, ufile_mode, agent_fk);
127 snprintf(sqlbuf,
sizeof(sqlbuf), SelectFilename_sql, upload_pk, ufile_mode, agent_fk);
129 free(uploadtree_tablename);
132 result = PQexec(
pgConn, sqlbuf);
134 numrows = PQntuples(result);
137 for (i=0; i<numrows; i++)
139 strcpy(FileName, PQgetvalue(result, i, 1));
140 pfile_pk = atoi(PQgetvalue(result, i, 0));
144 LOG_FATAL(
"demomod was unable to derive a file path for pfile %d. Check your HOSTS configuration.", pfile_pk);
154 snprintf(DataBuf,
sizeof(DataBuf),
"%d\t%d\t%s\n", pfile_pk, agent_fk, FileResult.
HexStr);
FUNCTION char * GetUploadtreeTableName(PGconn *pgConn, int upload_pk)
Get the uploadtree table name for this upload_pk If upload_pk does not exist, return "uploadtree"...
int fo_checkPQresult(PGconn *pgConn, PGresult *result, char *sql, char *FileID, int LineNumb)
Check the result status of a postgres SELECT.
FUNCTION int ProcessUpload(int upload_pk, int agent_fk)
Process a single upload - read the first 32 bytes in each file.
FUNCTION void Char2Hex(char *InBuf, int NumBytes, char *OutBuf)
Convert a character buffer to a hex string.
FUNCTION int ProcessFile(char *FilePath, pFileResult_t FileResult)
Process a single file - read the first 32 bytes.
PGconn * pgConn
Database connection.
char HexStr[(DataSize *2)+1]
Hexadecimal string.
psqlCopy_t psqlcpy
fo_sqlCopy struct used for fast data insertion
FUNCTION void ExitNow(int ExitVal)
Exit function. This does all cleanup and should be used instead of calling exit() or main() return...
char * fo_RepMkPath(const char *Type, char *Filename)
Given a filename, construct the full path to the file.
char * uploadtree_tablename
upload.uploadtree_tablename
char Buf[DataSize]
Buffer.
void fo_scheduler_heart(int i)
This function must be called by agents to let the scheduler know they are alive and how many items th...
int fo_sqlCopyAdd(psqlCopy_t pCopy, char *DataRow)
Add a data row to an sqlCopy Use '' to pass in a null.