From b560301c00fd91b0e38cb177f90757b3abebb79b Mon Sep 17 00:00:00 2001 From: Tom Cort Date: Wed, 28 Nov 2007 02:17:14 -0500 Subject: [PATCH] c -> c++ --- CMakeLists.txt | 2 +- clam.c => clam.cxx | 27 +++++++++++++++++++++++---- clam.h => clam.hxx | 8 ++++---- inoclam.c => inoclam.cxx | 7 ++++--- inotify.c => inotify.cxx | 8 ++++++-- inotify.h => inotify.hxx | 4 ++-- monitor.c => monitor.cxx | 2 +- monitor.h => monitor.hxx | 4 ++-- sig.c => signal.cxx | 8 +++++++- sig.h => signal.hxx | 6 +++--- smtp.cxx | 21 ++++++++++----------- smtp.hxx | 14 +++++++++++++- 12 files changed, 76 insertions(+), 35 deletions(-) rename clam.c => clam.cxx (90%) rename clam.h => clam.hxx (94%) rename inoclam.c => inoclam.cxx (95%) rename inotify.c => inotify.cxx (96%) rename inotify.h => inotify.hxx (95%) rename monitor.c => monitor.cxx (98%) rename monitor.h => monitor.hxx (96%) rename sig.c => signal.cxx (92%) rename sig.h => signal.hxx (95%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 51840dd..addc3e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -126,7 +126,7 @@ INCLUDE_DIRECTORIES(${incdirs} ${LIBCLAMAV_INCLUDE_DIR} ${LIBDAEMON_INCLUDE_DIR} # compile ############################################# -ADD_EXECUTABLE(inoclam clam.c inoclam.c inotify.c monitor.c sig.c smtp.cxx) +ADD_EXECUTABLE(inoclam clam.cxx inoclam.cxx inotify.cxx monitor.cxx signal.cxx smtp.cxx) ############################################# # link diff --git a/clam.c b/clam.cxx similarity index 90% rename from clam.c rename to clam.cxx index 80787b8..c450ea8 100644 --- a/clam.c +++ b/clam.cxx @@ -20,6 +20,7 @@ * Tom Cort */ +#include #include #include #include @@ -27,9 +28,26 @@ #include #include -#include "clam.h" -#include "monitor.h" -#include "sig.h" +#include "clam.hxx" +#include "monitor.hxx" +#include "signal.hxx" + +/** + * A lock used to serialize access to the engine. Serialized access is + * needed to keep clam_refresh() from changing the engine while + * contains_virus() is using it. + * @see clam_refresh() + * @see contains_virus() + */ +pthread_mutex_t engine_lock; + +/** + * Thread attributes used by the clam_refresh() thread. This is + * a global so that main() can free them when its cleaning up. + * @see main() + * @see clam_refresh() + */ +pthread_attr_t ta; /** * Multiple threads are using and altering "engine". @@ -91,7 +109,8 @@ void clam_init() */ void clam_refresh() { - int sigs, ret; + unsigned int sigs; + int ret; struct cl_stat dbstat; memset(&dbstat, 0, sizeof(struct cl_stat)); diff --git a/clam.h b/clam.hxx similarity index 94% rename from clam.h rename to clam.hxx index d84a15e..beb1ff1 100644 --- a/clam.h +++ b/clam.hxx @@ -20,8 +20,8 @@ * Tom Cort */ -#ifndef __CLAM_H -#define __CLAM_H +#ifndef __CLAM_HXX +#define __CLAM_HXX #include @@ -32,7 +32,7 @@ * @see clam_refresh() * @see contains_virus() */ -pthread_mutex_t engine_lock; +extern pthread_mutex_t engine_lock; /** * Thread attributes used by the clam_refresh() thread. This is @@ -40,7 +40,7 @@ pthread_mutex_t engine_lock; * @see main() * @see clam_refresh() */ -pthread_attr_t ta; +extern pthread_attr_t ta; /** * Thread that reloads virus definitions as needed diff --git a/inoclam.c b/inoclam.cxx similarity index 95% rename from inoclam.c rename to inoclam.cxx index 8e5aa8a..6733f78 100644 --- a/inoclam.c +++ b/inoclam.cxx @@ -22,9 +22,10 @@ #include -#include "clam.h" -#include "inotify.h" -#include "sig.h" +#include "clam.hxx" +#include "inotify.hxx" +#include "monitor.hxx" +#include "signal.hxx" int main(int argc, char *argv[], char *envp[]) { diff --git a/inotify.c b/inotify.cxx similarity index 96% rename from inotify.c rename to inotify.cxx index fe41ad8..bc55490 100644 --- a/inotify.c +++ b/inotify.cxx @@ -27,9 +27,12 @@ #include #include #include +#include -#include "inotify.h" -#include "sig.h" +#include "clam.hxx" +#include "inotify.hxx" +#include "signal.hxx" +#include "smtp.hxx" int __inotify_init(char *basedir) { @@ -94,6 +97,7 @@ void inotify_main(char *basedir) case 1: /* virus found */ unlink(filename); /* remove without prejudice */ + smtp_send(filename); break; case 0: /* no virus detected */ diff --git a/inotify.h b/inotify.hxx similarity index 95% rename from inotify.h rename to inotify.hxx index ce0b593..709ad97 100644 --- a/inotify.h +++ b/inotify.hxx @@ -20,8 +20,8 @@ * Tom Cort */ -#ifndef __INOTIFY_H -#define __INOTIFY_H +#ifndef __INOTIFY_HXX +#define __INOTIFY_HXX /** * Watch the specified directory for changes and call contains_virus() diff --git a/monitor.c b/monitor.cxx similarity index 98% rename from monitor.c rename to monitor.cxx index 7dcca7e..66f9a23 100644 --- a/monitor.c +++ b/monitor.cxx @@ -27,7 +27,7 @@ #include #include -#include "monitor.h" +#include "monitor.hxx" /** * Counter for the number of running threads. diff --git a/monitor.h b/monitor.hxx similarity index 96% rename from monitor.h rename to monitor.hxx index 7fa8966..227dfb0 100644 --- a/monitor.h +++ b/monitor.hxx @@ -20,8 +20,8 @@ * Tom Cort */ -#ifndef __MONITOR_H -#define __MONITOR_H +#ifndef __MONITOR_HXX +#define __MONITOR_HXX /** * initialize monitor variables diff --git a/sig.c b/signal.cxx similarity index 92% rename from sig.c rename to signal.cxx index 27bb7a5..04ecb29 100644 --- a/sig.c +++ b/signal.cxx @@ -23,7 +23,13 @@ #include #include -#include "sig.h" +#include "signal.hxx" + +/** + * Global variable used to determine if the program should halt. Will it ever halt? Only Alan Turing knows. + * @see handle_signal() + */ +int exit_now; /** * Signal handler for SIGKILL diff --git a/sig.h b/signal.hxx similarity index 95% rename from sig.h rename to signal.hxx index 6d5ee07..5b5399d 100644 --- a/sig.h +++ b/signal.hxx @@ -20,8 +20,8 @@ * Tom Cort */ -#ifndef __SIGNAL_H -#define __SIGNAL_H +#ifndef __SIGNAL_HXX +#define __SIGNAL_HXX /** * Signal handler for SIGKILL, SIGQUIT, SIGINT. @@ -39,6 +39,6 @@ void install_signal_handlers(); * Global variable used to determine if the program should halt. Will it ever halt? Only Alan Turing knows. * @see handle_signal() */ -int exit_now; +extern int exit_now; #endif diff --git a/smtp.cxx b/smtp.cxx index 91d31a5..7a127c3 100644 --- a/smtp.cxx +++ b/smtp.cxx @@ -20,21 +20,20 @@ * Tom Cort */ +#include #include #include "smtp.hxx" -/* - * TODO: Replace these defaults with something more configurable ;) +/** + * Sends an E-Mail. */ -#define SMTP_TO "tom.cort@state.vt.us" -#define SMTP_FROM "tom.cort@state.vt.us" -#define SMTP_SUBJECT "[inoscan] Virus Detected" -#define SMTP_BODY "Virus Found. Check the Logs." -#define SMTP_HOSTNAME "localhost" -#define SMTP_PORT (25) - -int smtp_send(char *body) { - jwsmtp::mailer mail(SMTP_TO, SMTP_FROM, SMTP_SUBJECT, SMTP_BODY, SMTP_HOSTNAME, SMTP_PORT, false); +void smtp_send(char *body) { + daemon_log(LOG_INFO, "(%s:%u) Sending E-Mail", __FILE__, __LINE__); + + /* Why are there no C libraries for sending mail that are this simple? */ + jwsmtp::mailer mail(SMTP_TO, SMTP_FROM, SMTP_SUBJECT, body, SMTP_HOSTNAME, SMTP_PORT, false); mail.send(); + + daemon_log(LOG_INFO, "(%s:%u) E-Mail Sent", __FILE__, __LINE__); } diff --git a/smtp.hxx b/smtp.hxx index 1797d06..f976570 100644 --- a/smtp.hxx +++ b/smtp.hxx @@ -23,6 +23,18 @@ #ifndef __SMTP_HXX #define __SMTP_HXX -int smtp_send(char *body); +/* + * TODO: Replace these defaults with something more configurable ;) + */ +#define SMTP_TO "tom.cort@state.vt.us" +#define SMTP_FROM "tom.cort@state.vt.us" +#define SMTP_SUBJECT "[inoscan] Virus Detected" +#define SMTP_HOSTNAME "localhost" +#define SMTP_PORT (25) + +/** + * Sends an E-Mail. + */ +void smtp_send(char *body); #endif -- 2.11.4.GIT