Expand PMF_FN_* macros.
[netbsd-mini2440.git] / external / ibm-public / postfix / dist / src / global / flush_clnt.c
bloba360a1172e7705417995377c589f43837c8f736a
1 /* $NetBSD$ */
3 /*++
4 /* NAME
5 /* flush_clnt 3
6 /* SUMMARY
7 /* fast flush cache manager client interface
8 /* SYNOPSIS
9 /* #include <flush_clnt.h>
11 /* void flush_init()
13 /* int flush_add(site, queue_id)
14 /* const char *site;
15 /* const char *queue_id;
17 /* int flush_send_site(site)
18 /* const char *site;
20 /* int flush_send_file(queue_id)
21 /* const char *queue_id;
23 /* int flush_refresh()
25 /* int flush_purge()
26 /* DESCRIPTION
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
42 /* queue ID.
44 /* flush_refresh() requests the "fast flush" cache manager to refresh
45 /* cached information that was not used for some configurable amount
46 /* time.
48 /* flush_purge() requests the "fast flush" cache manager to refresh
49 /* all cached information. This is incredibly expensive, and is not
50 /* recommended.
51 /* DIAGNOSTICS
52 /* The result codes and their meanings are (see flush_clnt(5h)):
53 /* .IP MAIL_FLUSH_OK
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).
59 /* .IP MAIL_FLUSH_BAD
60 /* The "fast flush" server rejected the request (invalid request
61 /* parameter).
62 /* .IP MAIL_FLUSH_DENY
63 /* The specified domain is not eligible for "fast flush" service,
64 /* or the "fast flush" service is disabled.
65 /* SEE ALSO
66 /* flush(8) Postfix fast flush cache manager
67 /* LICENSE
68 /* .ad
69 /* .fi
70 /* The Secure Mailer license must be distributed with this software.
71 /* AUTHOR(S)
72 /* Wietse Venema
73 /* IBM T.J. Watson Research
74 /* P.O. Box 704
75 /* Yorktown Heights, NY 10598, USA
76 /*--*/
78 /* System library. */
80 #include "sys_defs.h"
81 #include <unistd.h>
82 #include <stdarg.h>
84 /* Utility library. */
86 #include <msg.h>
87 #include <vstream.h>
89 /* Global 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),
109 var_fflush_domains);
112 /* flush_purge - house keeping */
114 int flush_purge(void)
116 const char *myname = "flush_purge";
117 int status;
119 if (msg_verbose)
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;
127 else
128 status = mail_command_client(MAIL_CLASS_PUBLIC, var_flush_service,
129 ATTR_TYPE_STR, MAIL_ATTR_REQ, FLUSH_REQ_PURGE,
130 ATTR_TYPE_END);
132 if (msg_verbose)
133 msg_info("%s: status %d", myname, status);
135 return (status);
138 /* flush_refresh - house keeping */
140 int flush_refresh(void)
142 const char *myname = "flush_refresh";
143 int status;
145 if (msg_verbose)
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;
153 else
154 status = mail_command_client(MAIL_CLASS_PUBLIC, var_flush_service,
155 ATTR_TYPE_STR, MAIL_ATTR_REQ, FLUSH_REQ_REFRESH,
156 ATTR_TYPE_END);
158 if (msg_verbose)
159 msg_info("%s: status %d", myname, status);
161 return (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";
169 int status;
171 if (msg_verbose)
172 msg_info("%s: site %s", myname, site);
175 * Don't bother the server if the service is turned off, or if the site
176 * is not eligible.
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;
182 else
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,
186 ATTR_TYPE_END);
188 if (msg_verbose)
189 msg_info("%s: site %s status %d", myname, site, status);
191 return (status);
194 /* flush_send_file - deliver specific message */
196 int flush_send_file(const char *queue_id)
198 const char *myname = "flush_send_file";
199 int status;
201 if (msg_verbose)
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,
210 ATTR_TYPE_END);
212 if (msg_verbose)
213 msg_info("%s: queue_id %s status %d", myname, queue_id, status);
215 return (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";
223 int status;
225 if (msg_verbose)
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
230 * is not eligible.
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;
236 else
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,
241 ATTR_TYPE_END);
243 if (msg_verbose)
244 msg_info("%s: site %s id %s status %d", myname, site, queue_id,
245 status);
247 return (status);