FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
standalone.h
1 #ifndef _STANDALONE_H
2 #define _STANDALONE_H 1
3 #include <stdlib.h>
4 #include <stdbool.h>
5 
6 typedef int PGconn;
7 typedef enum
8 {
9  PGRES_EMPTY_QUERY = 0,
10  PGRES_COMMAND_OK,
13  PGRES_TUPLES_OK,
16  PGRES_COPY_OUT,
17  PGRES_COPY_IN,
18  PGRES_BAD_RESPONSE,
20  PGRES_NONFATAL_ERROR,
21  PGRES_FATAL_ERROR
22 } ExecStatusType;
23 #define PG_DIAG_SQLSTATE 0
24 
25 #ifndef FALSE
26 #define FALSE 0
27 #endif
28 
29 #ifndef TRUE
30 #define TRUE 1
31 #endif
32 
33 typedef int PGresult;
34 
35 #define PERM_WRITE 2
36 #define LOG_NOTICE(...) { \
37  fprintf(stdout, "FATAL %s.%d: ", __FILE__, __LINE__); \
38  fprintf(stdout, __VA_ARGS__); \
39  fprintf(stdout, "\n"); \
40  fflush(stdout); }
41 #define LOG_FATAL(...) { \
42  fprintf(stdout, "FATAL %s.%d: ", __FILE__, __LINE__); \
43  fprintf(stdout, __VA_ARGS__); \
44  fprintf(stdout, "\n"); \
45  fflush(stdout); }
46 #define LOG_ERROR(...) { \
47  fprintf(stdout, "ERROR %s.%d: ", __FILE__, __LINE__); \
48  fprintf(stdout, __VA_ARGS__); \
49  fprintf(stdout, "\n"); \
50  fflush(stdout); }
51 #define LOG_WARNING(...) { \
52  fprintf(stdout, "WARNING %s.%d: ", __FILE__, __LINE__); \
53  fprintf(stdout, __VA_ARGS__); \
54  fprintf(stdout, "\n"); \
55  fflush(stdout); }
56 
57 extern void fo_scheduler_heart(int i);
58 extern void fo_scheduler_connect(int* argc, char** argv, PGconn** db_conn);
59 extern void fo_scheduler_disconnect(int retcode);
60 extern char* fo_scheduler_next();
61 extern char* fo_scheduler_current();
62 extern int fo_scheduler_userID();
63 extern void fo_scheduler_set_special(int option, int value);
64 extern int fo_scheduler_get_special(int option);
65 extern char* fo_sysconfig(const char* sectionname, const char* variablename);
66 extern int fo_GetAgentKey (PGconn *pgConn,const char *agent_name, long unused, const char *cpunused, const char *agent_desc);
67 extern int fo_WriteARS(PGconn *pgConn, int ars_pk, int upload_pk, int agent_pk,
68  const char *tableName, const char *ars_status, int ars_success);
69 extern PGconn *fo_dbconnect(char *DBConfFile, char **ErrorBuf);
70 extern int fo_checkPQcommand(PGconn *pgConn, PGresult *result, char *sql, char *FileID, int LineNumb);
71 extern int fo_checkPQresult(PGconn *pgConn, PGresult *result, char *sql, char *FileID, int LineNumb);
72 extern int fo_tableExists(PGconn *pgConn, const char *tableName);
73 extern int GetUploadPerm(PGconn *pgConn, long UploadPk, int user_pk);
74 extern char * fo_RepMkPath (char *Type, char *Filename);
75 
76 
77 typedef struct {} fo_dbManager;
79 
80 #define fo_dbManager_PrepareStamement(dbManager, name, query, ...) \
81 fo_dbManager_PrepareStamement_str(dbManager, \
82  name, \
83  query, \
84  #__VA_ARGS__\
85 )
86 
87 
88 fo_dbManager* fo_dbManager_new(PGconn* dbConnection);
90 fo_dbManager_PreparedStatement* fo_dbManager_PrepareStamement_str(fo_dbManager* dbManager, const char* name, const char* query, const char* paramtypes);
91 PGresult* fo_dbManager_ExecPrepared(fo_dbManager_PreparedStatement* preparedStatement, ...);
92 
93 PGresult* getSelectedPFiles(PGconn* pgConn, int uploadPk, int agentPk, bool ignoreFilesWithMimeType);
94 PGresult* checkDuplicateReq(PGconn* pgConn, int upload_pk, int agentPk);
95 
96 
97 //ExecStatusType PQresultStatus(const PGresult *res);
98 extern int PQresultStatus(const PGresult *res);
99 extern char *PQresultErrorMessage(const PGresult *res);
100 extern char *PQresultErrorField(const PGresult *res, int fieldcode);
101 extern int PQntuples(const PGresult *res);
102 extern PGresult *PQexec(PGconn *conn, const char *query);
103 extern void PQclear(PGresult *res);
104 extern char *PQgetvalue(const PGresult *res, int tup_num, int field_num);
105 extern size_t PQescapeStringConn(PGconn *conn,
106  char *to, const char *from, size_t length,
107  int *error);
108 extern void PQfinish(PGconn *conn);
109 
110 #endif
char * DBConfFile
DB conf file location.
Definition: testRun.c:33
int fo_checkPQresult(PGconn *pgConn, PGresult *result, char *sql, char *FileID, int LineNumb)
Check the result status of a postgres SELECT.
Definition: libfossdb.c:181
fo_dbManager_PreparedStatement * fo_dbManager_PrepareStamement_str(fo_dbManager *dbManager, const char *name, const char *query, const char *paramtypes)
Create a prepared statement.
Definition: standalone.c:30
PGconn * pgConn
Database connection.
Definition: adj2nest.c:98
PGresult * fo_dbManager_ExecPrepared(fo_dbManager_PreparedStatement *preparedStatement,...)
Execute a prepared statement.
Definition: standalone.c:31
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.
void fo_scheduler_set_special(int option, int value)
Sets something special about the agent within the scheduler.
fo_dbManager * fo_dbManager_new(PGconn *dbConnection)
Create and initialize new fo_dbManager object.
Definition: standalone.c:28
int fo_scheduler_get_special(int option)
Gets if a particular special attribute is set in the scheduler.
int fo_checkPQcommand(PGconn *pgConn, PGresult *result, char *sql, char *FileID, int LineNumb)
Check the result status of a postgres commands (not select) If an error occured, write the error to s...
Definition: libfossdb.c:215
int fo_scheduler_userID()
Gets the id of the user that created the job that the agent is running.
char * fo_RepMkPath(const char *Type, char *Filename)
Given a filename, construct the full path to the file.
Definition: libfossrepo.c:364
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:28
int agent_pk
Definition: agent.h:85
int fo_tableExists(PGconn *pgConn, const char *tableName)
Check if table exists. Note, this assumes the database name is &#39;fossology&#39;.
Definition: libfossdb.c:243
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.
Definition: libfossagent.c:172
PGconn * db_conn
The connection to Database.
Definition: pkgagent.c:34
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.
Definition: libfossagent.c:228
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...
void fo_dbManager_free(fo_dbManager *dbManager)
Un-allocate the memory from a DB manager.
Definition: standalone.c:29
FUNCTION int GetUploadPerm(PGconn *pgConn, long UploadPk, int user_pk)
Get users permission to this upload.
Definition: libfossagent.c:385
char * Filename
Filename.
Definition: run_tests.c:28
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...
Definition: libfossagent.c:476
const char * upload_pk
Definition: sqlstatements.h:93
char * fo_sysconfig(const char *sectionname, const char *variablename)
gets a system configuration variable from the configuration data.
PGconn * fo_dbconnect(char *DBConfFile, char **ErrorBuf)
Connect to a database. The default is Db.conf.
Definition: libfossdb.c:40
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.
Definition: libfossagent.c:449