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