FOSSology
4.4.0
Open Source License Compliance by Open Source Software
|
Database related operations. More...
#include <agent.h>
#include <database.h>
#include <logging.h>
#include <emailformatter.h>
#include <libfossdb.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <sqlstatements.h>
Go to the source code of this file.
Classes | |
struct | email_replace_args |
struct | reqcols |
Data type used to check if the database is correct. More... | |
Macros | |
#define | EMAIL_ERROR(...) |
#define | EMAIL_BUILD_CMD "%s %s -s '%s' %s" |
Email command format. | |
#define | DEFAULT_HEADER "FOSSology scan complete\nmessage:\"" |
Default email header. | |
#define | DEFAULT_FOOTER "\"" |
Default email footer. | |
#define | DEFAULT_SUBJECT "FOSSology scan complete\n" |
Default email subject. | |
#define | DEFAULT_COMMAND "/usr/bin/mailx" |
Default email command to use. | |
#define | min(x, y) (x < y ? x : y) |
Return the minimum of x, y. | |
Functions | |
static gboolean | email_replace (const GMatchInfo *match, GString *ret, email_replace_args *args) |
Replaces the variables that are in the header and footer files. More... | |
static gint | email_checkjobstatus (scheduler_t *scheduler, job_t *job) |
Checks the database for the status of the job. More... | |
static void | email_notification (scheduler_t *scheduler, job_t *job) |
void | email_init (scheduler_t *scheduler) |
Loads information about the email that will be sent for job notifications. More... | |
static void | check_tables (scheduler_t *scheduler) |
Checks that any part of the database used by the scheduler is correct. More... | |
static PGconn * | database_connect (gchar *configdir) |
Creates and performs error checking for a new database connection. More... | |
void | database_init (scheduler_t *scheduler) |
PGresult * | database_exec (scheduler_t *scheduler, const char *sql) |
Executes an sql statement for the scheduler. More... | |
void | database_exec_event (scheduler_t *scheduler, char *sql) |
void | database_update_event (scheduler_t *scheduler, void *unused) |
Checks the job queue for any new entries. More... | |
void | database_reset_queue (scheduler_t *scheduler) |
Resets any jobs in the job queue that are not completed. More... | |
void | database_update_job (scheduler_t *scheduler, job_t *job, job_status status) |
Change the status of a job in the database. More... | |
void | database_job_processed (int j_id, int num) |
Updates the number of items that a job queue entry has processed. More... | |
void | database_job_log (int j_id, char *log_name) |
Enters the name of the log file for a job into the database. More... | |
void | database_job_priority (scheduler_t *scheduler, job_t *job, int priority) |
Changes the priority of a job queue entry in the database. More... | |
int | check_mta_support () |
Find s-nail version to check if mta is supported. More... | |
char * | get_email_command (scheduler_t *scheduler, char *user_email) |
Build command to run to send email. More... | |
Database related operations.
Definition in file database.c.
#define EMAIL_ERROR | ( | ... | ) |
Definition at line 37 of file database.c.
int check_mta_support | ( | ) |
Find s-nail version to check if mta is supported.
Definition at line 1039 of file database.c.
|
static |
Checks that any part of the database used by the scheduler is correct.
This has a static list of all tables and the associated columns used by the scheduler. If any changes that affect the tables and columns used by the scheduler are made, this static list should be updated.
scheduler | the scheduler_t* that holds the connection |
Definition at line 655 of file database.c.
|
static |
Creates and performs error checking for a new database connection.
configdir | the location of the Db.conf file |
Definition at line 749 of file database.c.
PGresult* database_exec | ( | scheduler_t * | scheduler, |
const char * | sql | ||
) |
Executes an sql statement for the scheduler.
This is used in case the database connection is lost. The scheduler requires a connection to the database to correctly operate. So if the connection is ever lost we automatically try to reconnect and if we are unable to, the scheduler will die.
scheduler | the scheduler_t* that holds the connection |
sql | the sql that will be performed |
Definition at line 803 of file database.c.
void database_exec_event | ( | scheduler_t * | scheduler, |
char * | sql | ||
) |
void database_init | ( | scheduler_t * | scheduler | ) |
Initializes any one-time attributes relating to the database. Currently this includes creating the db connection and checking the URL of the FOSSology instance out of the db.
Definition at line 770 of file database.c.
void database_job_log | ( | int | j_id, |
char * | log_name | ||
) |
Enters the name of the log file for a job into the database.
j_id | the id number for the relevant job |
log_name | the name of the log file |
Definition at line 1006 of file database.c.
void database_job_priority | ( | scheduler_t * | scheduler, |
job_t * | job, | ||
int | priority | ||
) |
Changes the priority of a job queue entry in the database.
scheduler | The scheduler_t* that holds the connection |
job | the job to change the priority for |
priority | the new priority of the job |
Definition at line 1021 of file database.c.
void database_job_processed | ( | int | j_id, |
int | num | ||
) |
Updates the number of items that a job queue entry has processed.
j_id | the id number of the job queue entry |
num | the number of items processed in total |
Definition at line 992 of file database.c.
void database_reset_queue | ( | scheduler_t * | scheduler | ) |
Resets any jobs in the job queue that are not completed.
This is to make sure that any jobs that were running with the scheduler shutdown are run correctly when it starts up again.
Definition at line 931 of file database.c.
void database_update_event | ( | scheduler_t * | scheduler, |
void * | unused | ||
) |
Checks the job queue for any new entries.
scheduler | The scheduler_t* that holds the connection |
unused |
Definition at line 841 of file database.c.
void database_update_job | ( | scheduler_t * | scheduler, |
job_t * | job, | ||
job_status | status | ||
) |
Change the status of a job in the database.
scheduler | The scheduler_t* that holds the connection |
job | job_t* object for the job |
status | the new status of the job |
Definition at line 945 of file database.c.
|
static |
Checks the database for the status of the job.
scheduler | Current scheduler reference |
job | The job to check for the job status on |
Definition at line 365 of file database.c.
void email_init | ( | scheduler_t * | scheduler | ) |
Loads information about the email that will be sent for job notifications.
This loads the header and footer configuration files, loads the subject and client info, and compiles the regex that is used to replace variables in the header and footer files.
[in,out] | scheduler | Current scheduler to init |
Definition at line 557 of file database.c.
|
static |
Sends an email notification that a particular job has completed correctly. This compiles the email based upon the header file, footer file, and the job that just completed.
scheduler | Current scheduler reference |
job | The job that just finished |
Definition at line 429 of file database.c.
|
static |
Replaces the variables that are in the header and footer files.
This is a callback function that is passed to the glib function g_regex_replace_eval(). This reads what was matched by the regex and then appends the correct information onto the GString that is passed to the function.
Variables:
$UPLOADNAME
$BROWSELINK
$SCHEDULERLOG
$UPLOADFOLDERNAME
$JOBRESULT
$JOBQUEUELINK
$AGENTSTATUS
$DB.table.column [not implemented]
match | the regex match that glib found |
ret | the GString* that results should be appended to. |
args | The email replace arguments with foss url and job reference |
Definition at line 84 of file database.c.
char* get_email_command | ( | scheduler_t * | scheduler, |
char * | user_email | ||
) |
Build command to run to send email.
scheduler | Current scheduler object |
user_email | Email id to send mail to |
Definition at line 1073 of file database.c.