52 char BuildVersion[]=
"demomod build version: " VERSION_S
" r(" COMMIT_HASH_S
").\n";
63 int main(
int argc,
char **argv)
65 char *agentDesc =
"demomod demonstration module";
66 char *AgentARSName =
"demomod_ars";
74 char agent_rev[myBUFSIZ];
90 snprintf(agent_rev,
sizeof(agent_rev),
"%s.%s", VERSION, COMMIT_HASH);
94 while ((cmdopt = getopt(argc, argv,
"ivVc:")) != -1)
135 LOG_VERBOSE(
"demomod upload_pk is %d\n", upload_pk);
138 LOG_ERROR(
"demomod was passed a zero upload_pk. This is an invalid key.");
145 LOG_ERROR(
"You do not have write permission on upload %d", upload_pk);
153 snprintf(sqlbuf,
sizeof(sqlbuf),
154 "select ars_pk from %s,agent where agent_pk=agent_fk and ars_success=true \ 155 and upload_fk='%d' and agent_fk='%d'",
156 AgentARSName, upload_pk, agent_pk);
157 ars_result = PQexec(
pgConn, sqlbuf);
159 if (PQntuples(ars_result) > 0)
161 LOG_WARNING(
"Ignoring requested demomod scan of upload %d - Results are already in the database.\n",upload_pk);
191 for (i=optind; i<argc; i++)
194 printf(
"%s: %s \n", argv[i], FileResult.
HexStr);
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.
PGconn * pgConn
Database connection.
FUNCTION int ProcessFile(char *FilePath, pFileResult_t FileResult)
Process a single file - read the first 32 bytes.
char * fo_scheduler_current()
Get the last read string from the scheduler.
FUNCTION void CheckTable(char *AgentARSName)
Check to make sure the demomod and demomod_ars tables exists.
void fo_scheduler_connect(int *argc, char **argv, PGconn **db_conn)
Establish a connection between an agent and the scheduler.
char HexStr[(DataSize *2)+1]
Hexadecimal string.
int agent_verbose
Common verbose flags for the agents, this is used so that the scheduler can change the verbose level ...
psqlCopy_t psqlcpy
fo_sqlCopy struct used for fast data insertion
int fo_scheduler_userID()
Gets the id of the user that created the job that the agent is running.
Usage()
Print Usage statement.
FUNCTION void ExitNow(int ExitVal)
Exit function. This does all cleanup and should be used instead of calling exit() or main() return...
psqlCopy_t fo_sqlCopyCreate(PGconn *pGconn, char *TableName, int BufSize, int NumColumns,...)
Constructor for sqlCopy_struct.
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.
char * fo_scheduler_next()
Get the next data to process from the scheduler.
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 GetUploadPerm(PGconn *pgConn, long UploadPk, int user_pk)
Get users permission to this upload.
void fo_sqlCopyDestroy(psqlCopy_t pCopy, int ExecuteFlag)
Destructor for sqlCopy_struct.
char * fo_sysconfig(const char *sectionname, const char *variablename)
gets a system configuration variable from the configuration data.
#define PERM_WRITE
Read-Write permission.