FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
libfossagent.c File Reference

libfossagent.c contains general use functions for agents. More...

#include "libfossology.h"
Include dependency graph for libfossagent.c:

Go to the source code of this file.

Functions

char * getUploadTreeTableName (fo_dbManager *dbManager, int uploadId)
 Get the upload tree table name for a given upload. More...
 
PGresult * queryFileIdsForUpload (fo_dbManager *dbManager, int uploadId, bool ignoreFilesWithMimeType)
 Get all file IDs (pfile_fk) for a given upload. More...
 
char * queryPFileForFileId (fo_dbManager *dbManager, long fileId)
 Get the pfile name for a given file ID. More...
 
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. More...
 
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. More...
 
FUNCTION int fo_CreateARSTable (PGconn *pgConn, const char *tableName)
 Create ars table if it doesn't already exist. More...
 
FUNCTION int max (int permGroup, int permPublic)
 Get the maximum group privilege. More...
 
FUNCTION int min (int user_perm, int permExternal)
 Get the minimum permission level required. More...
 
FUNCTION int getEffectivePermissionOnUpload (PGconn *pgConn, long UploadPk, int user_pk, int user_perm)
 Get users permission to this upload. More...
 
FUNCTION int GetUploadPerm (PGconn *pgConn, long UploadPk, int user_pk)
 Get users permission to this upload. More...
 
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". More...
 
PGresult * checkDuplicateReq (PGconn *pgConn, int uploadPk, int agentPk)
 Get the upload_pk and agent_pk to find out the agent has already scanned the package. More...
 
PGresult * getSelectedPFiles (PGconn *pgConn, int uploadPk, int agentPk, bool ignoreFilesWithMimeType)
 Get the upload_pk, agent_pk and ignoreFilesWithMimeType to get all the file Ids for nomos. More...
 

Detailed Description

libfossagent.c contains general use functions for agents.

Definition in file libfossagent.c.

Function Documentation

PGresult* checkDuplicateReq ( PGconn *  pgConn,
int  uploadPk,
int  agentPk 
)

Get the upload_pk and agent_pk to find out the agent has already scanned the package.

Parameters
pgConnDatabase connection object pointer.
upload_pkUpload ID
agent_pkagentPk
Returns
result, ars_pk if the agent has already scanned the package.
Note
Caller must free the (non-null) returned value.

Definition at line 449 of file libfossagent.c.

FUNCTION int fo_CreateARSTable ( PGconn *  pgConn,
const char *  tableName 
)

Create ars table if it doesn't already exist.

Parameters
pgConnDatabase connection object pointer.
tableNamears table name
Returns
0 on failure

Definition at line 284 of file libfossagent.c.

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.

Parameters
pgConnDatabase connection object pointer.
agent_nameName of agent to look up.
Upload_pkis no longer used.
revAgent revision, if given this is the exact revision of the agent being requested.
agent_descDescription of the agent. Used to write a new agent record in the case where no enabled agent records exist for this agent_name.
Returns
On success return agent_pk. On sql failure, return 0, and the error will be written to stdout.
Todo:
This function is not checking if the agent is enabled. And it is not setting agent version when an agent record is inserted.

Definition at line 172 of file libfossagent.c.

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.

If the ars table does not exist, one is created by inheriting the ars_master table. The new table is called {tableName}. For example, "unpack_ars". If ars_pk is zero a new ars record will be created. Otherwise, it is updated.

Parameters
pgConnDatabase connection object pointer.
ars_pkIf zero, a new record will be created.
upload_pkID of the upload
agent_pkAgents should get this from fo_GetAgentKey()
tableNamears table name
ars_statusStatus to update ars_status. May be null.
ars_successAutomatically set to false if ars_pk is zero.
Returns
On success write the ars record and return the ars_pk. On sql failure, return 0, and the error will be written to stdout.

Definition at line 228 of file libfossagent.c.

FUNCTION int getEffectivePermissionOnUpload ( PGconn *  pgConn,
long  UploadPk,
int  user_pk,
int  user_perm 
)

Get users permission to this upload.

Parameters
pgConnDatabase connection object pointer.
upload_pkUpload ID
user_pkUser ID
user_permPrivilege of user
Returns
permission (PERM_) this user has for UploadPk

Definition at line 335 of file libfossagent.c.

PGresult* getSelectedPFiles ( PGconn *  pgConn,
int  uploadPk,
int  agentPk,
bool  ignoreFilesWithMimeType 
)

Get the upload_pk, agent_pk and ignoreFilesWithMimeType to get all the file Ids for nomos.

Parameters
pgConnDatabase connection object pointer.
upload_pkuploadPk
agent_pkagentPk
ignoreFilesWithMimeTypeTo ignore Files With MimeType
Returns
the result, the list of pfiles, require to be scan by nomos.
Note
Caller must free the (non-null) returned value.

Definition at line 476 of file libfossagent.c.

FUNCTION int GetUploadPerm ( PGconn *  pgConn,
long  UploadPk,
int  user_pk 
)

Get users permission to this upload.

Parameters
pgConnDatabase connection object pointer.
upload_pkUpload ID
user_pkUser ID
Returns
permission (PERM_) this user has for UploadPk

Definition at line 385 of file libfossagent.c.

char* getUploadTreeTableName ( fo_dbManager dbManager,
int  uploadId 
)

Get the upload tree table name for a given upload.

Parameters
dbManagerThe DB manager in use
uploadIdID of the upload
Returns
Upload tree table name of the upload.

Definition at line 37 of file libfossagent.c.

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".

Parameters
pgConnDatabase connection object pointer.
upload_pkUpload ID
Returns
uploadtree table name, or null if upload_pk does not exist.
Note
Caller must free the (non-null) returned value.

Definition at line 421 of file libfossagent.c.

FUNCTION int max ( int  permGroup,
int  permPublic 
)

Get the maximum group privilege.

Parameters
permGroupPermission level of the group
permPublicPublic permission on the upload
Returns
The maximum privilege allowed

Definition at line 309 of file libfossagent.c.

FUNCTION int min ( int  user_perm,
int  permExternal 
)

Get the minimum permission level required.

Parameters
user_permUser level permission on the upload
permExternalExternal permission level on the upload
Returns
The minimum permission required

Definition at line 320 of file libfossagent.c.

PGresult* queryFileIdsForUpload ( fo_dbManager dbManager,
int  uploadId,
bool  ignoreFilesWithMimeType 
)

Get all file IDs (pfile_fk) for a given upload.

Parameters
dbManagerfo_dbManager in use
uploadIdID of the upload
ignoreFilesWithMimeTypeTo ignore Files With MimeType
Returns
File IDs for the given upload

Definition at line 73 of file libfossagent.c.

char* queryPFileForFileId ( fo_dbManager dbManager,
long  fileId 
)

Get the pfile name for a given file ID.

Parameters
dbManagerfo_dbManager in use
fileIdFile ID (pfile_pk)
Returns
The file name (SHA1.MD5.SIZE)

Definition at line 136 of file libfossagent.c.