From 6bbfe1e7341010c7415436c3b09a6692944a0420 Mon Sep 17 00:00:00 2001 From: SJ Date: Thu, 31 Jan 2013 22:20:23 +0100 Subject: [PATCH] code cleanup --- configure | 2 +- configure.in | 2 +- src/message.c | 17 ----------------- src/mysql.c | 38 ++++++++++++++++++++++++++++++++++++++ src/piler.h | 1 + 5 files changed, 41 insertions(+), 19 deletions(-) create mode 100644 src/mysql.c diff --git a/configure b/configure index 2aaf5a2c..06cc348d 100755 --- a/configure +++ b/configure @@ -4595,7 +4595,7 @@ echo; echo CFLAGS="$static -O2 -Wall -g" LIBS="$antispam_libs $sunos_libs " -OBJS="dirs.o base64.o misc.o counters.o cfg.o sig.o decoder.o list.o parser.o parser_utils.o rules.o session.o message.o attachment.o digest.o store.o archive.o tai.o import.o imap.o pop3.o extract.o mydomains.o $objs" +OBJS="dirs.o base64.o misc.o counters.o cfg.o sig.o decoder.o list.o parser.o parser_utils.o rules.o session.o message.o attachment.o digest.o store.o archive.o tai.o import.o imap.o pop3.o extract.o mydomains.o mysql.o $objs" ac_config_files="$ac_config_files Makefile src/Makefile etc/Makefile util/Makefile init.d/Makefile test/Makefile contrib/imap/Makefile" diff --git a/configure.in b/configure.in index 0d016be4..36db57bf 100644 --- a/configure.in +++ b/configure.in @@ -394,7 +394,7 @@ echo; echo CFLAGS="$static -O2 -Wall -g" LIBS="$antispam_libs $sunos_libs " -OBJS="dirs.o base64.o misc.o counters.o cfg.o sig.o decoder.o list.o parser.o parser_utils.o rules.o session.o message.o attachment.o digest.o store.o archive.o tai.o import.o imap.o pop3.o extract.o mydomains.o $objs" +OBJS="dirs.o base64.o misc.o counters.o cfg.o sig.o decoder.o list.o parser.o parser_utils.o rules.o session.o message.o attachment.o digest.o store.o archive.o tai.o import.o imap.o pop3.o extract.o mydomains.o mysql.o $objs" AC_CONFIG_FILES([Makefile src/Makefile etc/Makefile util/Makefile init.d/Makefile test/Makefile contrib/imap/Makefile]) AC_OUTPUT diff --git a/src/message.c b/src/message.c index f6a8dde6..d08964bb 100644 --- a/src/message.c +++ b/src/message.c @@ -17,23 +17,6 @@ #include -int prepare_a_mysql_statement(struct session_data *sdata, MYSQL_STMT **stmt, char *s){ - - *stmt = mysql_stmt_init(&(sdata->mysql)); - if(!*stmt){ - syslog(LOG_PRIORITY, "%s: mysql_stmt_init() error", sdata->ttmpfile); - return ERR; - } - - if(mysql_stmt_prepare(*stmt, s, strlen(s))){ - syslog(LOG_PRIORITY, "%s: mysql_stmt_prepare() error: %s => sql: %s", sdata->ttmpfile, mysql_stmt_error(*stmt), s); - return ERR; - } - - return OK; -} - - int store_index_data(struct session_data *sdata, struct _state *state, struct __data *data, uint64 id, struct __config *cfg){ int rc=ERR; char *subj; diff --git a/src/mysql.c b/src/mysql.c new file mode 100644 index 00000000..e66910cc --- /dev/null +++ b/src/mysql.c @@ -0,0 +1,38 @@ +/* + * mysql.c, SJ + */ + +#include +#include +#include +#include +#include + + +int prepare_a_mysql_statement(struct session_data *sdata, MYSQL_STMT **stmt, char *s){ + + *stmt = mysql_stmt_init(&(sdata->mysql)); + if(!*stmt){ + syslog(LOG_PRIORITY, "%s: mysql_stmt_init() error", sdata->ttmpfile); + return ERR; + } + + if(mysql_stmt_prepare(*stmt, s, strlen(s))){ + syslog(LOG_PRIORITY, "%s: mysql_stmt_prepare() error: %s => sql: %s", sdata->ttmpfile, mysql_stmt_error(*stmt), s); + return ERR; + } + + return OK; +} + + +void insert_offset(struct session_data *sdata, int server_id){ + char s[SMALLBUFSIZE]; + uint64 id = server_id * 1000000000000ULL; + + snprintf(s, sizeof(s)-1, "INSERT INTO %s (`id`) VALUES (%llu)", SQL_METADATA_TABLE, id); + + mysql_real_query(&(sdata->mysql), s, strlen(s)); +} + + diff --git a/src/piler.h b/src/piler.h index b81ea4a2..f9f79890 100644 --- a/src/piler.h +++ b/src/piler.h @@ -26,6 +26,7 @@ #endif int read_key(struct __config *cfg); +void insert_offset(struct session_data *sdata, int server_id); int do_av_check(struct session_data *sdata, char *rcpttoemail, char *virusinfo, struct __data *data, struct __config *cfg);