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