Postfix3.3.1
mail_queue.h
[詳解]
1 #ifndef _MAIL_QUEUE_H_INCLUDED_
2 #define _MAIL_QUEUE_H_INCLUDED_
3 
4 /*++
5 /* NAME
6 /* mail_queue 3h
7 /* SUMMARY
8 /* mail queue access
9 /* SYNOPSIS
10 /* #include <mail_queue.h>
11 /* DESCRIPTION
12 /* .nf
13 
14  /*
15  * System library.
16  */
17 #include <sys/time.h>
18 
19  /*
20  * Utility library.
21  */
22 #include <vstring.h>
23 #include <vstream.h>
24 
25  /*
26  * Mail queue names.
27  */
28 #define MAIL_QUEUE_MAILDROP "maildrop"
29 #define MAIL_QUEUE_HOLD "hold"
30 #define MAIL_QUEUE_INCOMING "incoming"
31 #define MAIL_QUEUE_ACTIVE "active"
32 #define MAIL_QUEUE_DEFERRED "deferred"
33 #define MAIL_QUEUE_TRACE "trace"
34 #define MAIL_QUEUE_DEFER "defer"
35 #define MAIL_QUEUE_BOUNCE "bounce"
36 #define MAIL_QUEUE_CORRUPT "corrupt"
37 #define MAIL_QUEUE_FLUSH "flush"
38 #define MAIL_QUEUE_SAVED "saved"
39 
40  /*
41  * Queue file modes.
42  *
43  * 4.4BSD-like systems don't allow (sticky AND executable) together, so we use
44  * group read permission bits instead. These are more portable, but they
45  * also are more likely to be turned on by accident. It would not be the end
46  * of the world.
47  */
48 #define MAIL_QUEUE_STAT_READY (S_IRUSR | S_IWUSR | S_IXUSR)
49 #define MAIL_QUEUE_STAT_CORRUPT (S_IRUSR)
50 #ifndef MAIL_QUEUE_STAT_UNTHROTTLE
51 #define MAIL_QUEUE_STAT_UNTHROTTLE (S_IRGRP)
52 #endif
53 
54 extern struct VSTREAM *mail_queue_enter(const char *, mode_t, struct timeval *);
55 extern struct VSTREAM *mail_queue_open(const char *, const char *, int, mode_t);
56 extern int mail_queue_rename(const char *, const char *, const char *);
57 extern int mail_queue_remove(const char *, const char *);
58 extern const char *mail_queue_dir(VSTRING *, const char *, const char *);
59 extern const char *mail_queue_path(VSTRING *, const char *, const char *);
60 extern int mail_queue_mkdirs(const char *);
61 extern int mail_queue_name_ok(const char *);
62 extern int mail_queue_id_ok(const char *);
63 
64  /*
65  * MQID - Mail Queue ID format definitions. Needed only by code that creates
66  * or parses queue ID strings.
67  */
68 #ifdef MAIL_QUEUE_INTERNAL
69 
70  /*
71  * System library.
72  */
73 #include <errno.h>
74 
75  /*
76  * Global library.
77  */
78 #include <safe_ultostr.h>
79 
80  /*
81  * The long non-repeating queue ID is encoded in an alphabet of 10 digits,
82  * 21 upper-case characters, and 21 or fewer lower-case characters. The
83  * alphabet is made "safe" by removing all the vowels (AEIOUaeiou). The ID
84  * is the concatenation of:
85  *
86  * - the time in seconds (base 52 encoded, six or more chars),
87  *
88  * - the time in microseconds (base 52 encoded, exactly four chars),
89  *
90  * - the 'z' character to separate the time and inode information,
91  *
92  * - the inode number (base 51 encoded so that it contains no 'z').
93  */
94 #define MQID_LG_SEC_BASE 52 /* seconds safe alphabet base */
95 #define MQID_LG_SEC_PAD 6 /* seconds minimum field width */
96 #define MQID_LG_USEC_BASE 52 /* microseconds safe alphabet base */
97 #define MQID_LG_USEC_PAD 4 /* microseconds exact field width */
98 #define MQID_LG_TIME_PAD (MQID_LG_SEC_PAD + MQID_LG_USEC_PAD)
99 #define MQID_LG_INUM_SEP 'z' /* time-inode separator */
100 #define MQID_LG_INUM_BASE 51 /* inode safe alphabet base */
101 #define MQID_LG_INUM_PAD 0 /* no padding needed */
102 
103 #define MQID_FIND_LG_INUM_SEPARATOR(cp, path) \
104  (((cp) = strrchr((path), MQID_LG_INUM_SEP)) != 0 \
105  && ((cp) - (path) >= MQID_LG_TIME_PAD))
106 
107 #define MQID_GET_INUM(path, inum, long_form, error) do { \
108  char *_cp; \
109  if (((long_form) = MQID_FIND_LG_INUM_SEPARATOR(_cp, (path))) != 0) { \
110  MQID_LG_DECODE_INUM(_cp + 1, (inum), (error)); \
111  } else { \
112  MQID_SH_DECODE_INUM((path) + MQID_SH_USEC_PAD, (inum), (error)); \
113  } \
114  } while (0)
115 
116 #define MQID_LG_ENCODE_SEC(buf, val) \
117  MQID_LG_ENCODE((buf), (val), MQID_LG_SEC_BASE, MQID_LG_SEC_PAD)
118 
119 #define MQID_LG_ENCODE_USEC(buf, val) \
120  MQID_LG_ENCODE((buf), (val), MQID_LG_USEC_BASE, MQID_LG_USEC_PAD)
121 
122 #define MQID_LG_ENCODE_INUM(buf, val) \
123  MQID_LG_ENCODE((buf), (val), MQID_LG_INUM_BASE, MQID_LG_INUM_PAD)
124 
125 #define MQID_LG_DECODE_USEC(str, ulval, error) \
126  MQID_LG_DECODE((str), (ulval), MQID_LG_USEC_BASE, (error))
127 
128 #define MQID_LG_DECODE_INUM(str, ulval, error) \
129  MQID_LG_DECODE((str), (ulval), MQID_LG_INUM_BASE, (error))
130 
131 #define MQID_LG_ENCODE(buf, val, base, padlen) \
132  safe_ultostr((buf), (unsigned long) (val), (base), (padlen), '0')
133 
134 #define MQID_LG_DECODE(str, ulval, base, error) do { \
135  char *_end; \
136  errno = 0; \
137  (ulval) = safe_strtoul((str), &_end, (base)); \
138  (error) = (*_end != 0 || ((ulval) == ULONG_MAX && errno == ERANGE)); \
139  } while (0)
140 
141 #define MQID_LG_GET_HEX_USEC(bp, zp) do { \
142  int _error; \
143  unsigned long _us_val; \
144  vstring_strncpy((bp), (zp) - MQID_LG_USEC_PAD, MQID_LG_USEC_PAD); \
145  MQID_LG_DECODE_USEC(STR(bp), _us_val, _error); \
146  if (_error) \
147  _us_val = 0; \
148  (void) MQID_SH_ENCODE_USEC((bp), _us_val); \
149  } while (0)
150 
151  /*
152  * The short repeating queue ID is encoded in upper-case hexadecimal, and is
153  * the concatenation of:
154  *
155  * - the time in microseconds (exactly five chars),
156  *
157  * - the inode number.
158  */
159 #define MQID_SH_USEC_PAD 5 /* microseconds exact field width */
160 
161 #define MQID_SH_ENCODE_USEC(buf, usec) \
162  vstring_str(vstring_sprintf((buf), "%05X", (int) (usec)))
163 
164 #define MQID_SH_ENCODE_INUM(buf, inum) \
165  vstring_str(vstring_sprintf((buf), "%lX", (unsigned long) (inum)))
166 
167 #define MQID_SH_DECODE_INUM(str, ulval, error) do { \
168  char *_end; \
169  errno = 0; \
170  (ulval) = strtoul((str), &_end, 16); \
171  (error) = (*_end != 0 || ((ulval) == ULONG_MAX && errno == ERANGE)); \
172  } while (0)
173 
174 #endif /* MAIL_QUEUE_INTERNAL */
175 
176 /* LICENSE
177 /* .ad
178 /* .fi
179 /* The Secure Mailer license must be distributed with this software.
180 /* AUTHOR(S)
181 /* Wietse Venema
182 /* IBM T.J. Watson Research
183 /* P.O. Box 704
184 /* Yorktown Heights, NY 10598, USA
185 /*
186 /* Wietse Venema
187 /* Google, Inc.
188 /* 111 8th Avenue
189 /* New York, NY 10011, USA
190 /*--*/
191 
192 #endif /* _MAIL_QUEUE_H_INCLUDED_ */
const char * mail_queue_path(VSTRING *, const char *, const char *)
Definition: mail_queue.c:204
int mail_queue_mkdirs(const char *)
Definition: mail_queue.c:228
struct VSTREAM * mail_queue_enter(const char *, mode_t, struct timeval *)
Definition: mail_queue.c:319
struct VSTREAM * mail_queue_open(const char *, const char *, int, mode_t)
Definition: mail_queue.c:424
const char * mail_queue_dir(VSTRING *, const char *, const char *)
Definition: mail_queue.c:145
int mail_queue_remove(const char *, const char *)
Definition: mail_queue.c:274
int mail_queue_id_ok(const char *)
Definition: mail_queue.c:296
int mail_queue_rename(const char *, const char *, const char *)
Definition: mail_queue.c:247
int mail_queue_name_ok(const char *)
Definition: mail_queue.c:281