#include "sys_defs.h"
#include <unistd.h>
#include <stdarg.h>
#include <msg.h>
#include <vstream.h>
#include <mail_proto.h>
#include <mail_flush.h>
#include <mail_params.h>
#include <domain_list.h>
#include <match_parent_style.h>
#include <flush_clnt.h>
#define STR(x) vstring_str(x)
static DOMAIN_LIST *flush_domains;
void flush_init(void)
{
flush_domains = domain_list_init(VAR_FFLUSH_DOMAINS, MATCH_FLAG_RETURN
| match_parent_style(VAR_FFLUSH_DOMAINS),
var_fflush_domains);
}
int flush_purge(void)
{
const char *myname = "flush_purge";
int status;
if (msg_verbose)
msg_info("%s", myname);
if (*var_fflush_domains == 0)
status = FLUSH_STAT_DENY;
else
status = mail_command_client(MAIL_CLASS_PUBLIC, var_flush_service,
SEND_ATTR_STR(MAIL_ATTR_REQ, FLUSH_REQ_PURGE),
ATTR_TYPE_END);
if (msg_verbose)
msg_info("%s: status %d", myname, status);
return (status);
}
int flush_refresh(void)
{
const char *myname = "flush_refresh";
int status;
if (msg_verbose)
msg_info("%s", myname);
if (*var_fflush_domains == 0)
status = FLUSH_STAT_DENY;
else
status = mail_command_client(MAIL_CLASS_PUBLIC, var_flush_service,
SEND_ATTR_STR(MAIL_ATTR_REQ, FLUSH_REQ_REFRESH),
ATTR_TYPE_END);
if (msg_verbose)
msg_info("%s: status %d", myname, status);
return (status);
}
int flush_send_site(const char *site)
{
const char *myname = "flush_send_site";
int status;
if (msg_verbose)
msg_info("%s: site %s", myname, site);
if (flush_domains == 0)
msg_panic("missing flush client initialization");
if (domain_list_match(flush_domains, site) != 0) {
if (warn_compat_break_flush_domains)
msg_info("using backwards-compatible default setting "
VAR_RELAY_DOMAINS "=$mydestination to flush "
"mail for domain \"%s\"", site);
status = mail_command_client(MAIL_CLASS_PUBLIC, var_flush_service,
SEND_ATTR_STR(MAIL_ATTR_REQ, FLUSH_REQ_SEND_SITE),
SEND_ATTR_STR(MAIL_ATTR_SITE, site),
ATTR_TYPE_END);
} else if (flush_domains->error == 0)
status = FLUSH_STAT_DENY;
else
status = FLUSH_STAT_FAIL;
if (msg_verbose)
msg_info("%s: site %s status %d", myname, site, status);
return (status);
}
int flush_send_file(const char *queue_id)
{
const char *myname = "flush_send_file";
int status;
if (msg_verbose)
msg_info("%s: queue_id %s", myname, queue_id);
status = mail_command_client(MAIL_CLASS_PUBLIC, var_flush_service,
SEND_ATTR_STR(MAIL_ATTR_REQ, FLUSH_REQ_SEND_FILE),
SEND_ATTR_STR(MAIL_ATTR_QUEUEID, queue_id),
ATTR_TYPE_END);
if (msg_verbose)
msg_info("%s: queue_id %s status %d", myname, queue_id, status);
return (status);
}
int flush_add(const char *site, const char *queue_id)
{
const char *myname = "flush_add";
int status;
if (msg_verbose)
msg_info("%s: site %s id %s", myname, site, queue_id);
if (flush_domains == 0)
msg_panic("missing flush client initialization");
if (domain_list_match(flush_domains, site) != 0) {
if (warn_compat_break_flush_domains)
msg_info("using backwards-compatible default setting "
VAR_RELAY_DOMAINS "=$mydestination to update "
"fast-flush logfile for domain \"%s\"", site);
status = mail_command_client(MAIL_CLASS_PUBLIC, var_flush_service,
SEND_ATTR_STR(MAIL_ATTR_REQ, FLUSH_REQ_ADD),
SEND_ATTR_STR(MAIL_ATTR_SITE, site),
SEND_ATTR_STR(MAIL_ATTR_QUEUEID, queue_id),
ATTR_TYPE_END);
} else if (flush_domains->error == 0)
status = FLUSH_STAT_DENY;
else
status = FLUSH_STAT_FAIL;
if (msg_verbose)
msg_info("%s: site %s id %s status %d", myname, site, queue_id,
status);
return (status);
}