1 /* $NetBSD: cleanup_strerror.c,v 1.1.1.1 2009/06/23 10:08:45 tron Exp $ */ 2 3 /*++ 4 /* NAME 5 /* cleanup_strerror 3 6 /* SUMMARY 7 /* cleanup status code to string 8 /* SYNOPSIS 9 /* #include <cleanup_user.h> 10 /* 11 /* typedef struct { 12 /* .in +4 13 /* const unsigned status; /* cleanup status */ 14 /* const int smtp; /* RFC 821 */ 15 /* const char *dsn; /* RFC 3463 */ 16 /* const char *text; /* free text */ 17 /* .in -4 18 /* } CLEANUP_STAT_DETAIL; 19 /* 20 /* const char *cleanup_strerror(code) 21 /* int code; 22 /* 23 /* const CLEANUP_STAT_DETAIL *cleanup_stat_detail(code) 24 /* int code; 25 /* DESCRIPTION 26 /* cleanup_strerror() maps a status code returned by the \fIcleanup\fR 27 /* service to printable string. 28 /* The result is for read purposes only. 29 /* 30 /* cleanup_stat_detail() returns a pointer to structure with 31 /* assorted information. 32 /* DIAGNOSTICS: 33 /* Panic: unknown status. 34 /* LICENSE 35 /* .ad 36 /* .fi 37 /* The Secure Mailer license must be distributed with this software. 38 /* AUTHOR(S) 39 /* Wietse Venema 40 /* IBM T.J. Watson Research 41 /* P.O. Box 704 42 /* Yorktown Heights, NY 10598, USA 43 /*--*/ 44 45 /* System library. */ 46 47 #include <sys_defs.h> 48 49 /* Utility library. */ 50 51 #include <vstring.h> 52 #include <msg.h> 53 54 /* Global library. */ 55 56 #include <cleanup_user.h> 57 58 /* 59 * Mapping from status code to printable string. One message may suffer from 60 * multiple errors, to it is important to list the most severe errors first, 61 * because cleanup_strerror() can report only one error. 62 */ 63 static const CLEANUP_STAT_DETAIL cleanup_stat_map[] = { 64 CLEANUP_STAT_DEFER, 451, "4.7.1", "service unavailable", 65 CLEANUP_STAT_PROXY, 451, "4.3.0", "queue file write error", 66 CLEANUP_STAT_BAD, 451, "4.3.0", "internal protocol error", 67 CLEANUP_STAT_RCPT, 550, "5.1.0", "no recipients specified", 68 CLEANUP_STAT_HOPS, 554, "5.4.0", "too many hops", 69 CLEANUP_STAT_SIZE, 552, "5.3.4", "message file too big", 70 CLEANUP_STAT_CONT, 550, "5.7.1", "message content rejected", 71 CLEANUP_STAT_WRITE, 451, "4.3.0", "queue file write error", 72 }; 73 74 static CLEANUP_STAT_DETAIL cleanup_stat_success = { 75 CLEANUP_STAT_OK, 250, "2.0.0", "Success", 76 }; 77 78 /* cleanup_strerror - map status code to printable string */ 79 80 const char *cleanup_strerror(unsigned status) 81 { 82 unsigned i; 83 84 if (status == CLEANUP_STAT_OK) 85 return ("Success"); 86 87 for (i = 0; i < sizeof(cleanup_stat_map) / sizeof(cleanup_stat_map[0]); i++) 88 if (cleanup_stat_map[i].status & status) 89 return (cleanup_stat_map[i].text); 90 91 msg_panic("cleanup_strerror: unknown status %u", status); 92 } 93 94 /* cleanup_stat_detail - map status code to table entry with assorted data */ 95 96 const CLEANUP_STAT_DETAIL *cleanup_stat_detail(unsigned status) 97 { 98 unsigned i; 99 100 if (status == CLEANUP_STAT_OK) 101 return (&cleanup_stat_success); 102 103 for (i = 0; i < sizeof(cleanup_stat_map) / sizeof(cleanup_stat_map[0]); i++) 104 if (cleanup_stat_map[i].status & status) 105 return (cleanup_stat_map + i); 106 107 msg_panic("cleanup_stat_detail: unknown status %u", status); 108 } 109