Postfix3.3.1
dsn_mask.c
[詳解]
1 /*++
2 /* NAME
3 /* dsn_mask 3
4 /* SUMMARY
5 /* DSN embedding in SMTP
6 /* SYNOPSIS
7 /* #include <dsn_mask.h>
8 /*
9 /* int dsn_notify_mask(str)
10 /* const char *str;
11 /*
12 /* const char *dsn_notify_str(mask)
13 /* int mask;
14 /*
15 /* int dsn_ret_code(str)
16 /* const char *str;
17 /*
18 /* const char *dsn_ret_str(code)
19 /* int mask;
20 /* DESCRIPTION
21 /* dsn_ret_code() converts the parameters of a MAIL FROM ..
22 /* RET option to internal form.
23 /*
24 /* dsn_ret_str() converts internal form to the representation
25 /* used in the MAIL FROM .. RET command. The result is in
26 /* stable and static memory.
27 /*
28 /* dsn_notify_mask() converts the parameters of a RCPT TO ..
29 /* NOTIFY option to internal form.
30 /*
31 /* dsn_notify_str() converts internal form to the representation
32 /* used in the RCPT TO .. NOTIFY command. The result is in
33 /* volatile memory and is clobbered whenever str_name_mask()
34 /* is called.
35 /*
36 /* Arguments:
37 /* .IP str
38 /* Information received with the MAIL FROM or RCPT TO command.
39 /* .IP mask
40 /* Internal representation.
41 /* DIAGNOSTICS
42 /* dsn_ret_code() and dsn_notify_mask() return 0 when the string
43 /* specifies an invalid request.
44 /*
45 /* dsn_ret_str() and dsn_notify_str() abort on failure.
46 /* LICENSE
47 /* .ad
48 /* .fi
49 /* The Secure Mailer license must be distributed with this software.
50 /* AUTHOR(S)
51 /* Wietse Venema
52 /* IBM T.J. Watson Research
53 /* P.O. Box 704
54 /* Yorktown Heights, NY 10598, USA
55 /*--*/
56 
57 
58 /* System library. */
59 
60 #include <sys_defs.h>
61 
62 /* Utility library. */
63 
64 #include <name_code.h>
65 #include <name_mask.h>
66 #include <msg.h>
67 
68 /* Global library. */
69 
70 #include <dsn_mask.h>
71 
72 /* Application-specific. */
73 
74 static const NAME_MASK dsn_notify_table[] = {
75  "NEVER", DSN_NOTIFY_NEVER,
76  "SUCCESS", DSN_NOTIFY_SUCCESS,
77  "FAILURE", DSN_NOTIFY_FAILURE,
78  "DELAY", DSN_NOTIFY_DELAY,
79  0, 0,
80 };
81 
82 static const NAME_CODE dsn_ret_table[] = {
83  "FULL", DSN_RET_FULL,
84  "HDRS", DSN_RET_HDRS,
85  0, 0,
86 };
87 
88 /* dsn_ret_code - string to mask */
89 
90 int dsn_ret_code(const char *str)
91 {
92  return (name_code(dsn_ret_table, NAME_CODE_FLAG_NONE, str));
93 }
94 
95 /* dsn_ret_str - mask to string */
96 
97 const char *dsn_ret_str(int code)
98 {
99  const char *cp;
100 
101  if ((cp = str_name_code(dsn_ret_table, code)) == 0)
102  msg_panic("dsn_ret_str: unknown code %d", code);
103  return (cp);
104 }
105 
106 /* dsn_notify_mask - string to mask */
107 
108 int dsn_notify_mask(const char *str)
109 {
110  int mask = name_mask_opt("DSN NOTIFY command", dsn_notify_table,
112 
113  return (DSN_NOTIFY_OK(mask) ? mask : 0);
114 }
115 
116 /* dsn_notify_str - mask to string */
117 
118 const char *dsn_notify_str(int mask)
119 {
120  return (str_name_mask_opt((VSTRING *) 0, "DSN NOTIFY command",
121  dsn_notify_table, mask,
123 }
NORETURN msg_panic(const char *fmt,...)
Definition: msg.c:295
#define DSN_RET_HDRS
Definition: dsn_mask.h:18
#define DSN_NOTIFY_FAILURE
Definition: dsn_mask.h:45
#define DSN_NOTIFY_NEVER
Definition: dsn_mask.h:43
const char * str_name_mask_opt(VSTRING *buf, const char *context, const NAME_MASK *table, int mask, int flags)
Definition: name_mask.c:265
int dsn_notify_mask(const char *str)
Definition: dsn_mask.c:108
const char * str_name_code(const NAME_CODE *table, int code)
Definition: name_code.c:83
#define NAME_CODE_FLAG_NONE
Definition: name_code.h:22
const char * dsn_notify_str(int mask)
Definition: dsn_mask.c:118
#define NAME_MASK_RETURN
Definition: name_mask.h:29
#define DSN_RET_FULL
Definition: dsn_mask.h:17
int name_code(const NAME_CODE *table, int flags, const char *name)
Definition: name_code.c:65
int dsn_ret_code(const char *str)
Definition: dsn_mask.c:90
#define DSN_NOTIFY_SUCCESS
Definition: dsn_mask.h:44
#define DSN_NOTIFY_OK(v)
Definition: dsn_mask.h:63
#define NAME_MASK_FATAL
Definition: name_mask.h:27
#define NAME_MASK_ANY_CASE
Definition: name_mask.h:28
#define DSN_NOTIFY_DELAY
Definition: dsn_mask.h:46
const char * dsn_ret_str(int code)
Definition: dsn_mask.c:97
#define name_mask_opt(tag, table, str, flags)
Definition: name_mask.h:46
#define NAME_MASK_COMMA
Definition: name_mask.h:30