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