1 /* $NetBSD: cleanup_strflags.c,v 1.2 2017/02/14 01:16:45 christos Exp $ */
2
3 /*++
4 /* NAME
5 /* cleanup_strflags 3
6 /* SUMMARY
7 /* cleanup flags code to string
8 /* SYNOPSIS
9 /* #include <cleanup_user.h>
10 /*
11 /* const char *cleanup_strflags(code)
12 /* int code;
13 /* DESCRIPTION
14 /* cleanup_strflags() maps a CLEANUP_FLAGS code to printable string.
15 /* The result is for read purposes only. The result is overwritten
16 /* upon each call.
17 /* LICENSE
18 /* .ad
19 /* .fi
20 /* The Secure Mailer license must be distributed with this software.
21 /* AUTHOR(S)
22 /* Wietse Venema
23 /* IBM T.J. Watson Research
24 /* P.O. Box 704
25 /* Yorktown Heights, NY 10598, USA
26 /*--*/
27
28 /* System library. */
29
30 #include <sys_defs.h>
31
32 /* Utility library. */
33
34 #include <msg.h>
35 #include <vstring.h>
36
37 /* Global library. */
38
39 #include "cleanup_user.h"
40
41 /*
42 * Mapping from flags code to printable string.
43 */
44 struct cleanup_flag_map {
45 unsigned flag;
46 const char *text;
47 };
48
49 static struct cleanup_flag_map cleanup_flag_map[] = {
50 CLEANUP_FLAG_BOUNCE, "enable_bad_mail_bounce",
51 CLEANUP_FLAG_FILTER, "enable_header_body_filter",
52 CLEANUP_FLAG_HOLD, "hold_message",
53 CLEANUP_FLAG_DISCARD, "discard_message",
54 CLEANUP_FLAG_BCC_OK, "enable_automatic_bcc",
55 CLEANUP_FLAG_MAP_OK, "enable_address_mapping",
56 CLEANUP_FLAG_MILTER, "enable_milters",
57 CLEANUP_FLAG_SMTP_REPLY, "enable_smtp_reply",
58 CLEANUP_FLAG_SMTPUTF8, "smtputf8_requested",
59 CLEANUP_FLAG_AUTOUTF8, "smtputf8_autodetect",
60 };
61
62 /* cleanup_strflags - map flags code to printable string */
63
cleanup_strflags(unsigned flags)64 const char *cleanup_strflags(unsigned flags)
65 {
66 static VSTRING *result;
67 unsigned i;
68
69 if (flags == 0)
70 return ("none");
71
72 if (result == 0)
73 result = vstring_alloc(20);
74 else
75 VSTRING_RESET(result);
76
77 for (i = 0; i < sizeof(cleanup_flag_map) / sizeof(cleanup_flag_map[0]); i++) {
78 if (cleanup_flag_map[i].flag & flags) {
79 vstring_sprintf_append(result, "%s ", cleanup_flag_map[i].text);
80 flags &= ~cleanup_flag_map[i].flag;
81 }
82 }
83
84 if (flags != 0 || VSTRING_LEN(result) == 0)
85 msg_panic("cleanup_strflags: unrecognized flag value(s) 0x%x", flags);
86
87 vstring_truncate(result, VSTRING_LEN(result) - 1);
88 VSTRING_TERMINATE(result);
89
90 return (vstring_str(result));
91 }
92