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