Postfix3.3.1
dsn_util.h
[詳解]
1 #ifndef _DSN_UTIL_H_INCLUDED_
2 #define _DSN_UTIL_H_INCLUDED_
3 
4 /*++
5 /* NAME
6 /* dsn_util 3h
7 /* SUMMARY
8 /* DSN status parsing routines
9 /* SYNOPSIS
10 /* #include <dsn_util.h>
11 /* DESCRIPTION
12 /* .nf
13 
14  /*
15  * Utility library.
16  */
17 #include <vstring.h>
18 
19  /*
20  * Detail format is digit "." digit{1,3} "." digit{1,3}.
21  */
22 #define DSN_DIGS1 1 /* leading digits */
23 #define DSN_DIGS2 3 /* middle digits */
24 #define DSN_DIGS3 3 /* trailing digits */
25 #define DSN_LEN (DSN_DIGS1 + 1 + DSN_DIGS2 + 1 + DSN_DIGS3)
26 #define DSN_SIZE (DSN_LEN + 1)
27 
28  /*
29  * Storage for an enhanced status code. Avoid using malloc for itty-bitty
30  * strings with a known size limit.
31  *
32  * XXX gcc version 2 complains about sizeof() as format width specifier.
33  */
34 typedef struct {
35  char data[DSN_SIZE]; /* NOT a public interface */
36 } DSN_STAT;
37 
38 #define DSN_UPDATE(dsn_buf, dsn, len) do { \
39  if (len >= sizeof((dsn_buf).data)) \
40  msg_panic("DSN_UPDATE: bad DSN code \"%.*s...\" length %d", \
41  INT_SIZEOF((dsn_buf).data) - 1, dsn, len); \
42  strncpy((dsn_buf).data, (dsn), (len)); \
43  (dsn_buf).data[len] = 0; \
44  } while (0)
45 
46 #define DSN_STATUS(dsn_buf) ((const char *) (dsn_buf).data)
47 
48 #define DSN_CLASS(dsn_buf) ((dsn_buf).data[0])
49 
50  /*
51  * Split flat text into detail code and free text.
52  */
53 typedef struct {
54  DSN_STAT dsn; /* RFC 3463 status */
55  const char *text; /* free text */
56 } DSN_SPLIT;
57 
58 extern DSN_SPLIT *dsn_split(DSN_SPLIT *, const char *, const char *);
59 extern size_t dsn_valid(const char *);
60 
61  /*
62  * Create flat text from detail code and free text.
63  */
64 extern char *dsn_prepend(const char *, const char *);
65 
66 /* LICENSE
67 /* .ad
68 /* .fi
69 /* The Secure Mailer license must be distributed with this software.
70 /* AUTHOR(S)
71 /* Wietse Venema
72 /* IBM T.J. Watson Research
73 /* P.O. Box 704
74 /* Yorktown Heights, NY 10598, USA
75 /*--*/
76 
77 #endif
size_t dsn_valid(const char *)
Definition: dsn_util.c:112
DSN_SPLIT * dsn_split(DSN_SPLIT *, const char *, const char *)
Definition: dsn_util.c:138
const char * text
Definition: dsn_util.h:55
#define DSN_SIZE
Definition: dsn_util.h:26
DSN_STAT dsn
Definition: dsn_util.h:54
char * dsn_prepend(const char *, const char *)
Definition: dsn_util.c:177