FOSSology  4.4.0
Open Source License Compliance by Open Source Software
standalone.h
1 /*
2  SPDX-FileCopyrightText: © 2020 Siemens AG
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 int PGresult;
14 
15 #define PG_DIAG_SQLSTATE 0
16 #define PGRES_COMMAND_OK 1
17 #define PGRES_NONFATAL_ERROR 2
18 
19 #ifndef FALSE
20 #define FALSE 0
21 #endif
22 
23 #ifndef TRUE
24 #define TRUE 1
25 #endif
26 
27 #define PERM_WRITE 2
28 #define LOG_NOTICE(...) { \
29  fprintf(stdout, "FATAL %s.%d: ", __FILE__, __LINE__); \
30  fprintf(stdout, __VA_ARGS__); \
31  fprintf(stdout, "\n"); \
32  fflush(stdout); }
33 #define LOG_FATAL(...) { \
34  fprintf(stdout, "FATAL %s.%d: ", __FILE__, __LINE__); \
35  fprintf(stdout, __VA_ARGS__); \
36  fprintf(stdout, "\n"); \
37  fflush(stdout); }
38 #define LOG_ERROR(...) { \
39  fprintf(stdout, "ERROR %s.%d: ", __FILE__, __LINE__); \
40  fprintf(stdout, __VA_ARGS__); \
41  fprintf(stdout, "\n"); \
42  fflush(stdout); }
43 #define LOG_WARNING(...) { \
44  fprintf(stdout, "WARNING %s.%d: ", __FILE__, __LINE__); \
45  fprintf(stdout, __VA_ARGS__); \
46  fprintf(stdout, "\n"); \
47  fflush(stdout); }
48 
49 #define LOG_DEBUG(...) { \
50  fprintf(stdout, "DEBUG %s.%d: ", __FILE__, __LINE__); \
51  fprintf(stdout, __VA_ARGS__); \
52  fprintf(stdout, "\n"); \
53  fflush(stdout); }
54 
55 extern void fo_scheduler_heart(int i);
56 extern void fo_scheduler_connect(int* argc, char** argv, PGconn** db_conn);
57 extern void fo_scheduler_disconnect(int retcode);
58 extern char* fo_scheduler_next();
59 extern int fo_scheduler_userID();
60 extern void fo_scheduler_set_special(int option, int value);
61 extern int fo_scheduler_get_special(int option);
62 extern char* fo_sysconfig(const char* sectionname, const char* variablename);
63 extern int fo_GetAgentKey (PGconn *pgConn,const char *agent_name, long unused, const char *cpunused, const char *agent_desc);
64 extern int fo_WriteARS(PGconn *pgConn, int ars_pk, int upload_pk, int agent_pk,
65  const char *tableName, const char *ars_status, int ars_success);
66 
67 extern int fo_checkPQcommand(PGconn *pgConn, PGresult *result, char *sql, char *FileID, int LineNumb);
68 extern int fo_checkPQresult(PGconn *pgConn, PGresult *result, char *sql, char *FileID, int LineNumb);
69 extern int fo_tableExists(PGconn *pgConn, const char *tableName);
70 extern int GetUploadPerm(PGconn *pgConn, long UploadPk, int user_pk);
71 extern int fo_CreateARSTable(PGconn* pgConn, const char* tableName);
72 
73 typedef struct {} fo_dbManager;
74 
75 extern int PQresultStatus(const PGresult *res);
76 extern char* PQresultErrorMessage(const PGresult *res);
77 extern char* PQresultErrorField(const PGresult *res, int fieldcode);
78 extern int PQntuples(const PGresult *res);
79 extern PGresult *PQexec(PGconn *conn, const char *query);
80 extern void PQclear(PGresult *res);
81 extern char* PQgetvalue(const PGresult *res, int tup_num, int field_num);
82 extern size_t PQescapeStringConn(PGconn *conn,
83  char *to, const char *from, size_t length,
84  int *error);
85 extern void PQfinish(PGconn *conn);
86 
87 extern char* fo_RepMkPath (char *Type, char *Filename);
88 extern int fo_RepExist(char* Type, char* Filename);
89 extern int fo_RepExist2(char* Type, char* Filename);
90 extern int fo_RepImport(char* Source, char* Type, char* Filename, int HardLink);
91 #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
FUNCTION int fo_CreateARSTable(PGconn *pgConn, const char *tableName)
Create ars table if it doesn't already exist.
Definition: libfossagent.c:270
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
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
int fo_RepExist2(char *Type, char *Filename)
Determine if a file exists.
Definition: libfossrepo.c:531
int fo_RepImport(char *Source, char *Type, char *Filename, int Link)
Import a file into the repository.
Definition: libfossrepo.c:812
int fo_RepExist(char *Type, char *Filename)
Determine if a file exists.
Definition: libfossrepo.c:486
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_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.
PGconn * db_conn
The connection to Database.
Definition: pkgagent.c:22
const char * upload_pk
Definition: sqlstatements.h:82
char * Filename
Filename.
Definition: run_tests.c:17