41 char BuildVersion[]=
"demomod build version: " VERSION_S
" r(" COMMIT_HASH_S
").\n";
52 int main(
int argc,
char **argv)
54 char *agentDesc =
"demomod demonstration module";
55 char *AgentARSName =
"demomod_ars";
63 char agent_rev[myBUFSIZ];
79 snprintf(agent_rev,
sizeof(agent_rev),
"%s.%s", VERSION, COMMIT_HASH);
83 while ((cmdopt = getopt(argc, argv,
"ivVc:")) != -1)
124 LOG_VERBOSE(
"demomod upload_pk is %d\n",
upload_pk);
127 LOG_ERROR(
"demomod was passed a zero upload_pk. This is an invalid key.");
134 LOG_ERROR(
"You do not have write permission on upload %d",
upload_pk);
142 snprintf(sqlbuf,
sizeof(sqlbuf),
143 "select ars_pk from %s,agent where agent_pk=agent_fk and ars_success=true \
144 and upload_fk='%d' and agent_fk='%d'",
146 ars_result = PQexec(
pgConn, sqlbuf);
148 if (PQntuples(ars_result) > 0)
150 LOG_WARNING(
"Ignoring requested demomod scan of upload %d - Results are already in the database.\n",
upload_pk);
180 for (i=optind; i<argc; i++)
183 printf(
"%s: %s \n", argv[i], FileResult.
HexStr);
FUNCTION int ProcessUpload(int upload_pk, int agent_fk)
Process a single upload - read the first 32 bytes in each file.
FUNCTION int ProcessFile(char *FilePath, pFileResult_t FileResult)
Process a single file - read the first 32 bytes.
FUNCTION void ExitNow(int ExitVal)
Exit function. This does all cleanup and should be used instead of calling exit() or main() return.
FUNCTION void CheckTable(char *AgentARSName)
Check to make sure the demomod and demomod_ars tables exists.
PGconn * pgConn
Database connection.
psqlCopy_t psqlcpy
fo_sqlCopy struct used for fast data insertion
Usage()
Print Usage statement.
FUNCTION int GetUploadPerm(PGconn *pgConn, long UploadPk, int user_pk)
Get users permission to this upload.
FUNCTION int fo_WriteARS(PGconn *pgConn, int ars_pk, int upload_pk, int agent_pk, const char *tableName, const char *ars_status, int ars_success)
Write ars record.
FUNCTION int fo_GetAgentKey(PGconn *pgConn, const char *agent_name, long Upload_pk, const char *rev, const char *agent_desc)
Get the latest enabled agent key (agent_pk) from the database.
int fo_checkPQresult(PGconn *pgConn, PGresult *result, char *sql, char *FileID, int LineNumb)
Check the result status of a postgres SELECT.
#define PERM_WRITE
Read-Write permission.
char * fo_sysconfig(const char *sectionname, const char *variablename)
gets a system configuration variable from the configuration data.
int agent_verbose
Common verbose flags for the agents, this is used so that the scheduler can change the verbose level ...
int fo_scheduler_userID()
Gets the id of the user that created the job that the agent is running.
char * fo_scheduler_current()
Get the last read string from the scheduler.
char * fo_scheduler_next()
Get the next data to process from the scheduler.
void fo_scheduler_connect(int *argc, char **argv, PGconn **db_conn)
Establish a connection between an agent and the scheduler.
void fo_sqlCopyDestroy(psqlCopy_t pCopy, int ExecuteFlag)
Destructor for sqlCopy_struct.
psqlCopy_t fo_sqlCopyCreate(PGconn *pGconn, char *TableName, int BufSize, int NumColumns,...)
Constructor for sqlCopy_struct.
char HexStr[(DataSize *2)+1]
Hexadecimal string.