56 char BuildVersion[]=
"mimetype build version: " VERSION_S
" r(" COMMIT_HASH_S
").\n";
67 int main(
int argc,
char *argv[])
73 char *agent_desc =
"Determines mimetype for each file";
80 char *AgentARSName =
"mimetype_ars";
87 char agent_rev[MAXCMD];
93 while((c = getopt(argc,argv,
"iCc:hvV")) != -1)
122 sprintf(agent_rev,
"%s.%s", VERSION, COMMIT_HASH);
126 FMimetype = fopen(
"/etc/mime.types",
"rb");
129 LOG_WARNING(
"Unable to open /etc/mime.types\n");
132 MagicCookie = magic_open(MAGIC_PRESERVE_ATIME|MAGIC_MIME);
135 LOG_FATAL(
"Failed to initialize magic cookie\n");
141 LOG_FATAL(
"Failed to load magic file: UnMagic\n");
147 for(arg=optind; arg < argc; arg++)
150 strncpy(
A,argv[arg],
sizeof(
A)-1);
151 A[
sizeof(
A)-1] =
'\0';
156 if (0 == CmdlineFlag)
171 LOG_ERROR(
"You have no update permissions on upload %d",
upload_pk);
186 memset(sqlbuf, 0,
sizeof(sqlbuf));
187 snprintf(sqlbuf,
sizeof(sqlbuf),
188 "select ars_pk from mimetype_ars,agent \
189 where agent_pk=agent_fk and ars_success=true \
190 and upload_fk='%d' and agent_fk='%d'",
192 result = PQexec(
pgConn, sqlbuf);
194 if (PQntuples(result) > 0)
197 LOG_WARNING(
"Ignoring requested mimetype analysis of upload %d - Results are already in database.\n",
upload_pk);
206 memset(sqlbuf, 0,
sizeof(sqlbuf));
207 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);
208 result = PQexec(
pgConn, sqlbuf);
210 pfile_count = PQntuples(result);
212 for(i=0; i < pfile_count; i++)
214 Akey = atoi(PQgetvalue(result, i, 0));
215 strncpy(
A, PQgetvalue(result, i, 1),
sizeof(
A)-1);
216 A[
sizeof(
A)-1] =
'\0';
217 if (Akey <= 0 ||
A[0]==
'\0')
219 printf(
"ERROR: Data is in an unknown format.\n");
234 printf(
"ERROR pfile %d Unable to process.\n",Akey);
235 printf(
"LOG pfile %d File '%s' not found.\n",Akey,
A);
PGconn * pgConn
Database connection.
FILE * FMimetype
for /etc/mime.types
char A[MAXCMD]
input for this system
magic_t MagicCookie
for Magic
void DBCheckMime(char *Filename)
Given a file, check if it has a mime type in the DB.
int Agent_pk
agent identifier
PGresult * DBMime
contents of mimetype table
Usage()
Print Usage statement.
FUNCTION int GetUploadPerm(PGconn *pgConn, long UploadPk, int user_pk)
Get users permission to this upload.
FUNCTION int fo_CreateARSTable(PGconn *pgConn, const char *tableName)
Create ars table if it doesn't already exist.
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.
int fo_tableExists(PGconn *pgConn, const char *tableName)
Check if table exists. Note, this assumes the database name is 'fossology'.
#define PERM_WRITE
Read-Write permission.
char * fo_RepMkPath(const char *Type, char *Filename)
Given a filename, construct the full path to the file.
int fo_RepExist(char *Type, char *Filename)
Determine if a file exists.
void fo_scheduler_disconnect(int retcode)
Disconnect the scheduler connection.
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...
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.
int main(int argc, char *argv[])
Get the mimetype for a package.