1 /*++
2 /* NAME
3 /*	quote_flags 3
4 /* SUMMARY
5 /*	quote rfc 821/822 local part
6 /* SYNOPSIS
7 /*	#include <quote_flags.h>
8 /*
9 /*	int	quote_flags_from_string(const char *string)
10 /*
11 /*	const char *quote_flags_to_string(VSTRING *res_buf, int mask)
12 /* DESCRIPTION
13 /*	quote_flags_from_string() converts symbolic flag names into
14 /*	the corresponding internal bitmask. This logs a warning and
15 /*	returns zero if an unknown symbolic name is specified.
16 /*
17 /*	quote_flags_to_string() converts from internal bitmask to
18 /*	the corresponding symbolic names. This logs a warning and
19 /*	returns a null pointer if an unknown bitmask is specified.
20 /*
21 /*	Arguments:
22 /* .IP string
23 /*	Symbolic representation of a quote_flags bitmask, for
24 /*	example: \fB8bitclean | bare_localpart\fR. The conversion
25 /*	is case-insensitive.
26 /* .IP res_buf
27 /*	Storage for the quote_flags_to_string() result, which has
28 /*	the same form as the string argument. If a null pointer is
29 /*	specified, quote_flags_to_string() uses storage that is
30 /*	overwritten with each call.
31 /* .IP mask
32 /*	Binary representation of quote_flags.
33 /* DIAGNOSTICS
34 /*	Fatal error: out of memory; or unknown bitmask name or value.
35 /* LICENSE
36 /* .ad
37 /* .fi
38 /*	The Secure Mailer license must be distributed with this software.
39 /* AUTHOR(S)
40 /*	Wietse Venema
41 /*	Google, Inc.
42 /*	111 8th Avenue
43 /*	New York, NY 10011, USA
44 /*--*/
45 
46  /*
47   * System library.
48   */
49 #include <sys_defs.h>
50 
51  /*
52   * Utility library.
53   */
54 #include <name_mask.h>
55 
56  /*
57   * Global library.
58   */
59 #include <quote_flags.h>
60 
61 static const NAME_MASK quote_flags_table[] = {
62     "8bitclean", QUOTE_FLAG_8BITCLEAN,
63     "expose_at", QUOTE_FLAG_EXPOSE_AT,
64     "append", QUOTE_FLAG_APPEND,
65     "bare_localpart", QUOTE_FLAG_BARE_LOCALPART,
66     0,
67 };
68 
69 /* quote_flags_from_string - symbolic quote flags to internal form */
70 
quote_flags_from_string(const char * quote_flags_string)71 int     quote_flags_from_string(const char *quote_flags_string)
72 {
73     return (name_mask_delim_opt("quote_flags_from_string", quote_flags_table,
74 				quote_flags_string, "|",
75 				NAME_MASK_WARN | NAME_MASK_ANY_CASE));
76 }
77 
78 /* quote_flags_to_string - internal form to symbolic quote flags */
79 
quote_flags_to_string(VSTRING * res_buf,int quote_flags_mask)80 const char *quote_flags_to_string(VSTRING *res_buf, int quote_flags_mask)
81 {
82     static VSTRING *my_buf;
83 
84     if (res_buf == 0 && (res_buf = my_buf) == 0)
85 	res_buf = my_buf = vstring_alloc(20);
86     return (str_name_mask_opt(res_buf, "quote_flags_to_string",
87 			      quote_flags_table, quote_flags_mask,
88 			      NAME_MASK_WARN | NAME_MASK_PIPE));
89 }
90