cache separation stuff

This commit is contained in:
whottgen
2005-02-25 14:21:07 +00:00
parent b8a0a2a1bb
commit c8257af1bc
5 changed files with 120 additions and 35 deletions

View File

@ -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 <fcntl.h>
#include <stdio.h>
#ifndef CACHE_SEPARATED
#if ENABLE_CACHE == 1
#define DB_DBM_HSEARCH 1
#include <db.h>
#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;