1 /* $NetBSD: cleanup_strflags.c,v 1.1.1.1 2009/06/23 10:08:45 tron 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 }; 59 60 /* cleanup_strflags - map flags code to printable string */ 61 62 const char *cleanup_strflags(unsigned flags) 63 { 64 static VSTRING *result; 65 unsigned i; 66 67 if (flags == 0) 68 return ("none"); 69 70 if (result == 0) 71 result = vstring_alloc(20); 72 else 73 VSTRING_RESET(result); 74 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; 79 } 80 } 81 82 if (flags != 0 || VSTRING_LEN(result) == 0) 83 msg_panic("cleanup_strflags: unrecognized flag value(s) 0x%x", flags); 84 85 vstring_truncate(result, VSTRING_LEN(result) - 1); 86 VSTRING_TERMINATE(result); 87 88 return (vstring_str(result)); 89 } 90