Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / external / ibm-public / postfix / dist / src / global / cleanup_strflags.c
blobbf6a9d3b1bbf249296f6a9bc46bf379f11232eab
1 /* $NetBSD$ */
3 /*++
4 /* NAME
5 /* cleanup_strflags 3
6 /* SUMMARY
7 /* cleanup flags code to string
8 /* SYNOPSIS
9 /* #include <cleanup_user.h>
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 /*--*/
28 /* System library. */
30 #include <sys_defs.h>
32 /* Utility library. */
34 #include <msg.h>
35 #include <vstring.h>
37 /* Global library. */
39 #include "cleanup_user.h"
42 * Mapping from flags code to printable string.
44 struct cleanup_flag_map {
45 unsigned flag;
46 const char *text;
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",
60 /* cleanup_strflags - map flags code to printable string */
62 const char *cleanup_strflags(unsigned flags)
64 static VSTRING *result;
65 unsigned i;
67 if (flags == 0)
68 return ("none");
70 if (result == 0)
71 result = vstring_alloc(20);
72 else
73 VSTRING_RESET(result);
75 for (i = 0; i < sizeof(cleanup_flag_map) / sizeof(cleanup_flag_map[0]); i++) {
76 if (cleanup_flag_map[i].flag & flags) {
77 vstring_sprintf_append(result, "%s ", cleanup_flag_map[i].text);
78 flags &= ~cleanup_flag_map[i].flag;
82 if (flags != 0 || VSTRING_LEN(result) == 0)
83 msg_panic("cleanup_strflags: unrecognized flag value(s) 0x%x", flags);
85 vstring_truncate(result, VSTRING_LEN(result) - 1);
86 VSTRING_TERMINATE(result);
88 return (vstring_str(result));