diff --git a/smmapdfw/libsmmapdfw/Makefile.am b/smmapdfw/libsmmapdfw/Makefile.am index 9481760..7072904 100644 --- a/smmapdfw/libsmmapdfw/Makefile.am +++ b/smmapdfw/libsmmapdfw/Makefile.am @@ -2,4 +2,6 @@ include_HEADERS=containers_public.h queue.h smtp.h cfg.h count.h safe_write.h su lib_LTLIBRARIES = libsmmapdfw.la libsmmapdfw_la_SOURCES = cfg.c queue.c count.c safe_write.c config_public.c htdns.c smtp.c htmalloc.c stats.c htcache.c libsmmapdfw_la_LIBADD = @BDB_LIBS@ - +bin_PROGRAMS = htcachetest +htcachetest_SOURCES = htcachetest.c +htcachetest_LDADD = libsmmapdfw.la diff --git a/smmapdfw/libsmmapdfw/Makefile.in b/smmapdfw/libsmmapdfw/Makefile.in index 8e175bd..9fd1047 100644 --- a/smmapdfw/libsmmapdfw/Makefile.in +++ b/smmapdfw/libsmmapdfw/Makefile.in @@ -91,6 +91,9 @@ include_HEADERS = containers_public.h queue.h smtp.h cfg.h count.h safe_write.h lib_LTLIBRARIES = libsmmapdfw.la libsmmapdfw_la_SOURCES = cfg.c queue.c count.c safe_write.c config_public.c htdns.c smtp.c htmalloc.c stats.c htcache.c libsmmapdfw_la_LIBADD = @BDB_LIBS@ +bin_PROGRAMS = htcachetest +htcachetest_SOURCES = htcachetest.c +htcachetest_LDADD = libsmmapdfw.la mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs CONFIG_HEADER = ../config.h CONFIG_CLEAN_FILES = @@ -105,6 +108,12 @@ libsmmapdfw_la_LDFLAGS = libsmmapdfw_la_DEPENDENCIES = libsmmapdfw_la_OBJECTS = cfg.lo queue.lo count.lo safe_write.lo \ config_public.lo htdns.lo smtp.lo htmalloc.lo stats.lo htcache.lo +bin_PROGRAMS = htcachetest$(EXEEXT) +PROGRAMS = $(bin_PROGRAMS) + +htcachetest_OBJECTS = htcachetest.$(OBJEXT) +htcachetest_DEPENDENCIES = libsmmapdfw.la +htcachetest_LDFLAGS = CFLAGS = @CFLAGS@ COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) @@ -120,10 +129,10 @@ DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) TAR = tar GZIP_ENV = --best DEP_FILES = .deps/cfg.P .deps/config_public.P .deps/count.P \ -.deps/htcache.P .deps/htdns.P .deps/htmalloc.P .deps/queue.P \ -.deps/safe_write.P .deps/smtp.P .deps/stats.P -SOURCES = $(libsmmapdfw_la_SOURCES) -OBJECTS = $(libsmmapdfw_la_OBJECTS) +.deps/htcache.P .deps/htcachetest.P .deps/htdns.P .deps/htmalloc.P \ +.deps/queue.P .deps/safe_write.P .deps/smtp.P .deps/stats.P +SOURCES = $(libsmmapdfw_la_SOURCES) $(htcachetest_SOURCES) +OBJECTS = $(libsmmapdfw_la_OBJECTS) $(htcachetest_OBJECTS) all: all-redirect .SUFFIXES: @@ -202,6 +211,35 @@ maintainer-clean-libtool: libsmmapdfw.la: $(libsmmapdfw_la_OBJECTS) $(libsmmapdfw_la_DEPENDENCIES) $(LINK) -rpath $(libdir) $(libsmmapdfw_la_LDFLAGS) $(libsmmapdfw_la_OBJECTS) $(libsmmapdfw_la_LIBADD) $(LIBS) +mostlyclean-binPROGRAMS: + +clean-binPROGRAMS: + -test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS) + +distclean-binPROGRAMS: + +maintainer-clean-binPROGRAMS: + +install-binPROGRAMS: $(bin_PROGRAMS) + @$(NORMAL_INSTALL) + $(mkinstalldirs) $(DESTDIR)$(bindir) + @list='$(bin_PROGRAMS)'; for p in $$list; do \ + if test -f $$p; then \ + echo " $(LIBTOOL) --mode=install $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`"; \ + $(LIBTOOL) --mode=install $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`; \ + else :; fi; \ + done + +uninstall-binPROGRAMS: + @$(NORMAL_UNINSTALL) + list='$(bin_PROGRAMS)'; for p in $$list; do \ + rm -f $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`; \ + done + +htcachetest$(EXEEXT): $(htcachetest_OBJECTS) $(htcachetest_DEPENDENCIES) + @rm -f htcachetest$(EXEEXT) + $(LINK) $(htcachetest_LDFLAGS) $(htcachetest_OBJECTS) $(htcachetest_LDADD) $(LIBS) + install-includeHEADERS: $(include_HEADERS) @$(NORMAL_INSTALL) $(mkinstalldirs) $(DESTDIR)$(includedir) @@ -306,7 +344,7 @@ check-am: all-am check: check-am installcheck-am: installcheck: installcheck-am -install-exec-am: install-libLTLIBRARIES +install-exec-am: install-libLTLIBRARIES install-binPROGRAMS install-exec: install-exec-am install-data-am: install-includeHEADERS @@ -315,14 +353,16 @@ install-data: install-data-am install-am: all-am @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am install: install-am -uninstall-am: uninstall-libLTLIBRARIES uninstall-includeHEADERS +uninstall-am: uninstall-libLTLIBRARIES uninstall-binPROGRAMS \ + uninstall-includeHEADERS uninstall: uninstall-am -all-am: Makefile $(LTLIBRARIES) $(HEADERS) +all-am: Makefile $(LTLIBRARIES) $(PROGRAMS) $(HEADERS) all-redirect: all-am install-strip: $(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install installdirs: - $(mkinstalldirs) $(DESTDIR)$(libdir) $(DESTDIR)$(includedir) + $(mkinstalldirs) $(DESTDIR)$(libdir) $(DESTDIR)$(bindir) \ + $(DESTDIR)$(includedir) mostlyclean-generic: @@ -335,27 +375,29 @@ distclean-generic: maintainer-clean-generic: mostlyclean-am: mostlyclean-libLTLIBRARIES mostlyclean-compile \ - mostlyclean-libtool mostlyclean-tags mostlyclean-depend \ - mostlyclean-generic + mostlyclean-libtool mostlyclean-binPROGRAMS \ + mostlyclean-tags mostlyclean-depend mostlyclean-generic mostlyclean: mostlyclean-am -clean-am: clean-libLTLIBRARIES clean-compile clean-libtool clean-tags \ - clean-depend clean-generic mostlyclean-am +clean-am: clean-libLTLIBRARIES clean-compile clean-libtool \ + clean-binPROGRAMS clean-tags clean-depend clean-generic \ + mostlyclean-am clean: clean-am distclean-am: distclean-libLTLIBRARIES distclean-compile \ - distclean-libtool distclean-tags distclean-depend \ - distclean-generic clean-am + distclean-libtool distclean-binPROGRAMS distclean-tags \ + distclean-depend distclean-generic clean-am -rm -f libtool distclean: distclean-am maintainer-clean-am: maintainer-clean-libLTLIBRARIES \ maintainer-clean-compile maintainer-clean-libtool \ - maintainer-clean-tags maintainer-clean-depend \ - maintainer-clean-generic distclean-am + maintainer-clean-binPROGRAMS maintainer-clean-tags \ + maintainer-clean-depend maintainer-clean-generic \ + distclean-am @echo "This command is intended for maintainers to use;" @echo "it deletes files that may require special tools to rebuild." @@ -366,11 +408,13 @@ clean-libLTLIBRARIES maintainer-clean-libLTLIBRARIES \ uninstall-libLTLIBRARIES install-libLTLIBRARIES mostlyclean-compile \ distclean-compile clean-compile maintainer-clean-compile \ mostlyclean-libtool distclean-libtool clean-libtool \ -maintainer-clean-libtool uninstall-includeHEADERS \ -install-includeHEADERS tags mostlyclean-tags distclean-tags clean-tags \ -maintainer-clean-tags distdir mostlyclean-depend distclean-depend \ -clean-depend maintainer-clean-depend info-am info dvi-am dvi check \ -check-am installcheck-am installcheck install-exec-am install-exec \ +maintainer-clean-libtool mostlyclean-binPROGRAMS distclean-binPROGRAMS \ +clean-binPROGRAMS maintainer-clean-binPROGRAMS uninstall-binPROGRAMS \ +install-binPROGRAMS uninstall-includeHEADERS install-includeHEADERS \ +tags mostlyclean-tags distclean-tags clean-tags maintainer-clean-tags \ +distdir mostlyclean-depend distclean-depend clean-depend \ +maintainer-clean-depend info-am info dvi-am dvi check check-am \ +installcheck-am installcheck install-exec-am install-exec \ install-data-am install-data install-am install uninstall-am uninstall \ all-redirect all-am all installdirs mostlyclean-generic \ distclean-generic clean-generic maintainer-clean-generic clean \ diff --git a/smmapdfw/libsmmapdfw/htcache.c b/smmapdfw/libsmmapdfw/htcache.c index d6f3356..e4b1bf9 100644 --- a/smmapdfw/libsmmapdfw/htcache.c +++ b/smmapdfw/libsmmapdfw/htcache.c @@ -1,5 +1,5 @@ /* - Copyright (C) 2004, Wolfgang Hottgenroth + Copyright (C) 2004,2005 Wolfgang Hottgenroth This file is part of smmapdfw. @@ -52,7 +52,7 @@ typedef struct mydata_s mydata_t; -htcache_t *cache_init(const char *file, int expiry) { +htcache_t *htcache_init(const char *file, int expiry) { #if ENABLE_CACHE == 1 htcache_t *handle = (htcache_t*) htmalloc(sizeof(htcache_t)); handle->mutex = (pthread_mutex_t*) htmalloc(sizeof(pthread_mutex_t)); @@ -67,7 +67,7 @@ htcache_t *cache_init(const char *file, int expiry) { #endif } -void cache_destroy(htcache_t *handle) { +void htcache_destroy(htcache_t *handle) { #if ENABLE_CACHE == 1 pthread_mutex_destroy(handle->mutex); free(handle->mutex); @@ -75,7 +75,7 @@ void cache_destroy(htcache_t *handle) { #endif } -void cache_insert(htcache_t *handle, const char *key, const void *value, int value_size) { +void htcache_insert(htcache_t *handle, const char *key, const char *value, int value_size) { #if ENABLE_CACHE == 1 DBM *cache; datum data, dkey; @@ -111,7 +111,7 @@ void cache_insert(htcache_t *handle, const char *key, const void *value, int val } -void *cache_lookup(htcache_t *handle, const char* key) { +int htcache_lookup(htcache_t *handle, const char* key, char** value, int* value_size2) { #if ENABLE_CACHE == 1 DBM *cache; datum data, dkey; @@ -131,13 +131,16 @@ void *cache_lookup(htcache_t *handle, const char* key) { dbm_close(cache); } else { mydata = (mydata_t *) data.dptr; - syslog(LOG_DEBUG, "cache_lookup: found: %s -> %s (size %d)", - key, data.dptr, data.dsize); + syslog(LOG_DEBUG, "cache_lookup: found: %s %d %d %s (size %d)", + key, mydata->timestamp, mydata->value_size, mydata->value, data.dsize); if ((mydata->timestamp + handle->expiry) > time(NULL)) { syslog(LOG_DEBUG, "cache_lookup: not yet expired"); value_size = mydata->value_size; output = (char*) htmalloc(value_size+5); memcpy(output, mydata->value, value_size); + + *value_size2 = value_size; + *value = output; /* Berkeley DB frees on its own! */ /* free(data.dptr); */ @@ -157,6 +160,7 @@ void *cache_lookup(htcache_t *handle, const char* key) { syslog(LOG_DEBUG, "cache_insert: record deleted"); } dbm_close(cache); + res = -2; } pthread_mutex_unlock(handle->mutex); } @@ -171,4 +175,3 @@ void *cache_lookup(htcache_t *handle, const char* key) { - diff --git a/smmapdfw/libsmmapdfw/htcache.h b/smmapdfw/libsmmapdfw/htcache.h index 7980c57..537f32f 100644 --- a/smmapdfw/libsmmapdfw/htcache.h +++ b/smmapdfw/libsmmapdfw/htcache.h @@ -32,10 +32,10 @@ typedef struct htcache_s { pthread_mutex_t *mutex; } htcache_t; -htcache_t *cache_init(const char *file, int expiry); -void cache_destroy(htcache_t *handle); -void cache_insert(htcache_t *handle, const char *key, const void *value, int value_size); -void *cache_lookup(htcache_t *handle, const char *key); +htcache_t *htcache_init(const char *file, int expiry); +void htcache_destroy(htcache_t *handle); +void htcache_insert(htcache_t *handle, const char *key, const char *value, int value_size); +int htcache_lookup(htcache_t *handle, const char *key, char** value, int* value_size2); #endif /* _HTCACHE_H_ */ diff --git a/smmapdfw/verify_worker/verify_worker.c b/smmapdfw/verify_worker/verify_worker.c index dcdf14f..14540bd 100644 --- a/smmapdfw/verify_worker/verify_worker.c +++ b/smmapdfw/verify_worker/verify_worker.c @@ -18,6 +18,8 @@ Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +// #define CACHE_SEPARATED 1 + #if HAVE_CONFIG_H # include "config.h" #endif @@ -35,10 +37,15 @@ #include #include + +#ifndef CACHE_SEPARATED #if ENABLE_CACHE == 1 #define DB_DBM_HSEARCH 1 #include -#endif +#endif /* ENABLE_CACHE */ +#else +#include "htcache.h" +#endif /* CACHE_SEPARATED */ #include "containers_public.h" #include "smmapd.h" @@ -59,10 +66,16 @@ struct verify_container_handle_s { cfgl_t *cfg; int timeout_result; int timeout_dialog; + +#ifndef CACHE_SEPARATED int cache_enabled; int cache_expiry; pthread_mutex_t *cache_mutex; char *cache_file; +#else + htcache_t *cache; +#endif /* CACHE_SEPARATED */ + char *sender_address; char *helo_arg; int smtp_port; @@ -126,7 +139,9 @@ typedef struct worker_thread_s worker_thread_t; struct mydata_s { int result; +#ifndef CACHE_SEPARATED time_t timestamp; +#endif /* CACHE_SEPARATED */ char output[1]; }; @@ -160,6 +175,8 @@ class_descriptor_t verifier = { /* container handle for each class in the application. */ int verify_init(cfgl_t *cfg, void **handle) { verify_container_handle_t *vch; + int cache_enabled, cache_expiry; + char *cache_file; vch = (verify_container_handle_t*) htmalloc(sizeof(verify_container_handle_t)); vch->cfg = cfg; @@ -170,6 +187,8 @@ int verify_init(cfgl_t *cfg, void **handle) { vch->helo_arg = findcfglx(vch->cfg, "helo_arg", "local"); vch->smtp_port = atoi(findcfglx(vch->cfg, "smtp_port", "25")); vch->max_checker_threads = atoi(findcfglx(vch->cfg, "max_checker_threads", "25")); + +#ifndef CACHE_SEPARATED vch->cache_enabled = atoi(findcfglx(vch->cfg, "cache_enabled", "1")); vch->cache_expiry = atoi(findcfglx(vch->cfg, "cache_expiry", "86400")); vch->cache_file = findcfglx(vch->cfg, "cache_file", "verifier_cache"); @@ -181,7 +200,17 @@ int verify_init(cfgl_t *cfg, void **handle) { } else { vch->cache_mutex = NULL; } +#else + cache_enabled = atoi(findcfglx(vch->cfg, "cache_enabled", "1")); + cache_expiry = atoi(findcfglx(vch->cfg, "cache_expiry", "86400")); + cache_file = findcfglx(vch->cfg, "cache_file", "verifier_cache"); + if (1 == cache_enabled) { + vch->cache = cache_init(cache_file, cache_expiry); + } else { + vch->cache = NULL; + } +#endif /* CACHE_SEPARATED */ *handle = vch; return 0; @@ -192,10 +221,17 @@ int verify_init(cfgl_t *cfg, void **handle) { int verify_destroy(void *handle) { verify_container_handle_t *vch = (verify_container_handle_t*)handle; +#ifndef CACHE_SEPARATED if (1 == vch->cache_enabled) { pthread_mutex_destroy(vch->cache_mutex); free(vch->cache_mutex); } +#else + if (NULL != vch->cache) { + cache_destroy(vch->cache); + } +#endif /* CACHE_SEPARATED */ + free(vch); return 0;