~ubuntu-branches/ubuntu/vivid/postfix/vivid-proposed

« back to all changes in this revision

Viewing changes to src/global/mail_queue.h

  • Committer: Package Import Robot
  • Author(s): LaMont Jones
  • Date: 2012-03-20 13:47:16 UTC
  • mfrom: (1.1.33)
  • mto: This revision was merged to the branch mainline in revision 44.
  • Revision ID: package-import@ubuntu.com-20120320134716-v7ab94fmor2z9pvp
Tags: upstream-2.9.1
ImportĀ upstreamĀ versionĀ 2.9.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
61
61
extern int mail_queue_name_ok(const char *);
62
62
extern int mail_queue_id_ok(const char *);
63
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 minumum 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
        (void) MQID_SH_ENCODE_USEC((bp), _us_val); \
 
147
    } while (0)
 
148
 
 
149
 /*
 
150
  * The short repeating queue ID is encoded in upper-case hexadecimal, and is
 
151
  * the concatenation of:
 
152
  * 
 
153
  * - the time in microseconds (exactly five chars),
 
154
  * 
 
155
  * - the inode number.
 
156
  */
 
157
#define MQID_SH_USEC_PAD        5       /* microseconds exact field width */
 
158
 
 
159
#define MQID_SH_ENCODE_USEC(buf, usec) \
 
160
        vstring_str(vstring_sprintf((buf), "%05X", (int) (usec)))
 
161
 
 
162
#define MQID_SH_ENCODE_INUM(buf, inum) \
 
163
        vstring_str(vstring_sprintf((buf), "%lX", (unsigned long) (inum)))
 
164
 
 
165
#define MQID_SH_DECODE_INUM(str, ulval, error) do { \
 
166
        char *_end; \
 
167
        errno = 0; \
 
168
        (ulval) = strtoul((str), &_end, 16); \
 
169
        (error) = (*_end != 0 || ((ulval) == ULONG_MAX && errno == ERANGE)); \
 
170
    } while (0)
 
171
 
 
172
#endif                                  /* MAIL_QUEUE_INTERNAL */
 
173
 
64
174
/* LICENSE
65
175
/* .ad
66
176
/* .fi
72
182
/*      Yorktown Heights, NY 10598, USA
73
183
/*--*/
74
184
 
75
 
#endif
 
185
#endif                                  /* _MAIL_QUEUE_H_INCLUDED_ */