67 char BuildVersion[]=
"mimetype build version: " VERSION_S
" r(" COMMIT_HASH_S
").\n";
78 int main(
int argc,
char *argv[])
84 char *agent_desc =
"Determines mimetype for each file";
91 char *AgentARSName =
"mimetype_ars";
98 char agent_rev[MAXCMD];
104 while((c = getopt(argc,argv,
"iCc:hvV")) != -1)
133 sprintf(agent_rev,
"%s.%s", VERSION, COMMIT_HASH);
137 FMimetype = fopen(
"/etc/mime.types",
"rb");
140 LOG_WARNING(
"Unable to open /etc/mime.types\n");
143 MagicCookie = magic_open(MAGIC_PRESERVE_ATIME|MAGIC_MIME);
146 LOG_FATAL(
"Failed to initialize magic cookie\n");
152 LOG_FATAL(
"Failed to load magic file: UnMagic\n");
158 for(arg=optind; arg < argc; arg++)
161 strncpy(
A,argv[arg],
sizeof(
A)-1);
162 A[
sizeof(
A)-1] =
'\0';
167 if (0 == CmdlineFlag)
177 upload_pk = atoi(Parm);
182 LOG_ERROR(
"You have no update permissions on upload %d", upload_pk);
197 memset(sqlbuf, 0,
sizeof(sqlbuf));
198 snprintf(sqlbuf,
sizeof(sqlbuf),
199 "select ars_pk from mimetype_ars,agent \ 200 where agent_pk=agent_fk and ars_success=true \ 201 and upload_fk='%d' and agent_fk='%d'",
202 upload_pk, Agent_pk);
203 result = PQexec(
pgConn, sqlbuf);
205 if (PQntuples(result) > 0)
208 LOG_WARNING(
"Ignoring requested mimetype analysis of upload %d - Results are already in database.\n",upload_pk);
217 memset(sqlbuf, 0,
sizeof(sqlbuf));
218 snprintf(sqlbuf,
sizeof(sqlbuf),
"SELECT DISTINCT(pfile_pk) as Akey, pfile_sha1 || '.' || pfile_md5 || '.' || pfile_size AS A FROM uploadtree, pfile WHERE uploadtree.pfile_fk = pfile.pfile_pk AND pfile_mimetypefk is NULL AND upload_fk = '%d';", upload_pk);
219 result = PQexec(
pgConn, sqlbuf);
221 pfile_count = PQntuples(result);
223 for(i=0; i < pfile_count; i++)
225 Akey = atoi(PQgetvalue(result, i, 0));
226 strncpy(
A, PQgetvalue(result, i, 1),
sizeof(
A)-1);
227 A[
sizeof(
A)-1] =
'\0';
228 if (Akey <= 0 ||
A[0]==
'\0')
230 printf(
"ERROR: Data is in an unknown format.\n");
245 printf(
"ERROR pfile %d Unable to process.\n",Akey);
246 printf(
"LOG pfile %d File '%s' not found.\n",Akey,
A);
261 if (ars_pk)
fo_WriteARS(
pgConn, ars_pk, upload_pk, Agent_pk, AgentARSName, 0, 1);
int fo_checkPQresult(PGconn *pgConn, PGresult *result, char *sql, char *FileID, int LineNumb)
Check the result status of a postgres SELECT.
PGresult * DBMime
contents of mimetype table
PGconn * pgConn
Database connection.
char * fo_scheduler_current()
Get the last read string from the scheduler.
void fo_scheduler_disconnect(int retcode)
Disconnect the scheduler connection.
void fo_scheduler_connect(int *argc, char **argv, PGconn **db_conn)
Establish a connection between an agent and the scheduler.
char A[MAXCMD]
input for this system
int agent_verbose
Common verbose flags for the agents, this is used so that the scheduler can change the verbose level ...
void DBCheckMime(char *Filename)
Given a file, check if it has a mime type in the DB.
int fo_scheduler_userID()
Gets the id of the user that created the job that the agent is running.
Usage()
Print Usage statement.
int Agent_pk
agent identifier
char * fo_RepMkPath(const char *Type, char *Filename)
Given a filename, construct the full path to the file.
FUNCTION int fo_CreateARSTable(PGconn *pgConn, const char *tableName)
Create ars table if it doesn't already exist.
int fo_tableExists(PGconn *pgConn, const char *tableName)
Check if table exists. Note, this assumes the database name is 'fossology'.
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.
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...
FUNCTION int GetUploadPerm(PGconn *pgConn, long UploadPk, int user_pk)
Get users permission to this upload.
FILE * FMimetype
for /etc/mime.types
magic_t MagicCookie
for Magic
int main(int argc, char *argv[])
Get the mimetype for a package.
char * fo_sysconfig(const char *sectionname, const char *variablename)
gets a system configuration variable from the configuration data.
#define PERM_WRITE
Read-Write permission.
int fo_RepExist(char *Type, char *Filename)
Determine if a file exists.