7 /* fast flush cache manager client interface
9 /* #include <flush_clnt.h>
13 /* int flush_add(site, queue_id)
15 /* const char *queue_id;
17 /* int flush_send_site(site)
20 /* int flush_send_file(queue_id)
21 /* const char *queue_id;
23 /* int flush_refresh()
27 /* The following routines operate through the "fast flush" service.
28 /* This service maintains a cache of what mail is queued. The cache
29 /* is maintained for eligible destinations. A destination is the
30 /* right-hand side of a user@domain email address.
32 /* flush_init() initializes. It must be called before dropping
33 /* privileges in a daemon process.
35 /* flush_add() informs the "fast flush" cache manager that mail is
36 /* queued for the specified site with the specified queue ID.
38 /* flush_send_site() requests delivery of all mail that is queued for
39 /* the specified destination.
41 /* flush_send_file() requests delivery of mail with the specified
44 /* flush_refresh() requests the "fast flush" cache manager to refresh
45 /* cached information that was not used for some configurable amount
48 /* flush_purge() requests the "fast flush" cache manager to refresh
49 /* all cached information. This is incredibly expensive, and is not
52 /* The result codes and their meanings are (see flush_clnt(5h)):
54 /* The request completed successfully (in case of requests that
55 /* complete in the background: the request was accepted by the server).
56 /* .IP MAIL_FLUSH_FAIL
57 /* The request failed (the request could not be sent to the server,
58 /* or the server reported failure).
60 /* The "fast flush" server rejected the request (invalid request
62 /* .IP MAIL_FLUSH_DENY
63 /* The specified domain is not eligible for "fast flush" service,
64 /* or the "fast flush" service is disabled.
66 /* flush(8) Postfix fast flush cache manager
70 /* The Secure Mailer license must be distributed with this software.
73 /* IBM T.J. Watson Research
75 /* Yorktown Heights, NY 10598, USA
84 /* Utility library. */
91 #include <mail_proto.h>
92 #include <mail_flush.h>
93 #include <mail_params.h>
94 #include <domain_list.h>
95 #include <match_parent_style.h>
96 #include <flush_clnt.h>
98 /* Application-specific. */
100 #define STR(x) vstring_str(x)
102 static DOMAIN_LIST
*flush_domains
;
104 /* flush_init - initialize */
106 void flush_init(void)
108 flush_domains
= domain_list_init(match_parent_style(VAR_FFLUSH_DOMAINS
),
112 /* flush_purge - house keeping */
114 int flush_purge(void)
116 const char *myname
= "flush_purge";
120 msg_info("%s", myname
);
123 * Don't bother the server if the service is turned off.
125 if (*var_fflush_domains
== 0)
126 status
= FLUSH_STAT_DENY
;
128 status
= mail_command_client(MAIL_CLASS_PUBLIC
, var_flush_service
,
129 ATTR_TYPE_STR
, MAIL_ATTR_REQ
, FLUSH_REQ_PURGE
,
133 msg_info("%s: status %d", myname
, status
);
138 /* flush_refresh - house keeping */
140 int flush_refresh(void)
142 const char *myname
= "flush_refresh";
146 msg_info("%s", myname
);
149 * Don't bother the server if the service is turned off.
151 if (*var_fflush_domains
== 0)
152 status
= FLUSH_STAT_DENY
;
154 status
= mail_command_client(MAIL_CLASS_PUBLIC
, var_flush_service
,
155 ATTR_TYPE_STR
, MAIL_ATTR_REQ
, FLUSH_REQ_REFRESH
,
159 msg_info("%s: status %d", myname
, status
);
164 /* flush_send_site - deliver mail queued for site */
166 int flush_send_site(const char *site
)
168 const char *myname
= "flush_send_site";
172 msg_info("%s: site %s", myname
, site
);
175 * Don't bother the server if the service is turned off, or if the site
178 if (flush_domains
== 0)
179 msg_panic("missing flush client initialization");
180 if (domain_list_match(flush_domains
, site
) == 0)
181 status
= FLUSH_STAT_DENY
;
183 status
= mail_command_client(MAIL_CLASS_PUBLIC
, var_flush_service
,
184 ATTR_TYPE_STR
, MAIL_ATTR_REQ
, FLUSH_REQ_SEND_SITE
,
185 ATTR_TYPE_STR
, MAIL_ATTR_SITE
, site
,
189 msg_info("%s: site %s status %d", myname
, site
, status
);
194 /* flush_send_file - deliver specific message */
196 int flush_send_file(const char *queue_id
)
198 const char *myname
= "flush_send_file";
202 msg_info("%s: queue_id %s", myname
, queue_id
);
205 * Require that the service is turned on.
207 status
= mail_command_client(MAIL_CLASS_PUBLIC
, var_flush_service
,
208 ATTR_TYPE_STR
, MAIL_ATTR_REQ
, FLUSH_REQ_SEND_FILE
,
209 ATTR_TYPE_STR
, MAIL_ATTR_QUEUEID
, queue_id
,
213 msg_info("%s: queue_id %s status %d", myname
, queue_id
, status
);
218 /* flush_add - inform "fast flush" cache manager */
220 int flush_add(const char *site
, const char *queue_id
)
222 const char *myname
= "flush_add";
226 msg_info("%s: site %s id %s", myname
, site
, queue_id
);
229 * Don't bother the server if the service is turned off, or if the site
232 if (flush_domains
== 0)
233 msg_panic("missing flush client initialization");
234 if (domain_list_match(flush_domains
, site
) == 0)
235 status
= FLUSH_STAT_DENY
;
237 status
= mail_command_client(MAIL_CLASS_PUBLIC
, var_flush_service
,
238 ATTR_TYPE_STR
, MAIL_ATTR_REQ
, FLUSH_REQ_ADD
,
239 ATTR_TYPE_STR
, MAIL_ATTR_SITE
, site
,
240 ATTR_TYPE_STR
, MAIL_ATTR_QUEUEID
, queue_id
,
244 msg_info("%s: site %s id %s status %d", myname
, site
, queue_id
,