Home | History | Annotate | Line # | Download | only in global
      1 /*	$NetBSD: cleanup_strerror.c,v 1.3 2025/02/25 19:15:45 christos 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 /*	Wietse Venema
     45 /*	Google, Inc.
     46 /*	111 8th Avenue
     47 /*	New York, NY 10011, USA
     48 /*--*/
     49 
     50 /* System library. */
     51 
     52 #include <sys_defs.h>
     53 
     54 /* Utility library. */
     55 
     56 #include <vstring.h>
     57 #include <msg.h>
     58 
     59 /* Global library. */
     60 
     61 #include <cleanup_user.h>
     62 
     63  /*
     64   * Mapping from status code to printable string. One message may suffer from
     65   * multiple errors, to it is important to list the most severe errors first,
     66   * because cleanup_strerror() can report only one error.
     67   */
     68 static const CLEANUP_STAT_DETAIL cleanup_stat_map[] = {
     69     CLEANUP_STAT_DEFER, 451, "4.7.1", "service unavailable",
     70     CLEANUP_STAT_PROXY, 451, "4.3.0", "queue file write error",
     71     CLEANUP_STAT_BAD, 451, "4.3.0", "internal protocol error",
     72     CLEANUP_STAT_RCPT, 550, "5.1.0", "no recipients specified",
     73     CLEANUP_STAT_HOPS, 554, "5.4.0", "too many hops",
     74     CLEANUP_STAT_SIZE, 552, "5.3.4", "message file too big",
     75     CLEANUP_STAT_CONT, 550, "5.7.1", "message content rejected",
     76     CLEANUP_STAT_WRITE, 451, "4.3.0", "queue file write error",
     77     CLEANUP_STAT_NOPERM, 550, "5.7.1", "service denied",
     78     CLEANUP_STAT_BARE_LF, 521, "5.5.2", "bare <LF> received",
     79 };
     80 
     81 static CLEANUP_STAT_DETAIL cleanup_stat_success = {
     82     CLEANUP_STAT_OK, 250, "2.0.0", "Success",
     83 };
     84 
     85 /* cleanup_strerror - map status code to printable string */
     86 
     87 const char *cleanup_strerror(unsigned status)
     88 {
     89     unsigned i;
     90 
     91     if (status == CLEANUP_STAT_OK)
     92 	return ("Success");
     93 
     94     for (i = 0; i < sizeof(cleanup_stat_map) / sizeof(cleanup_stat_map[0]); i++)
     95 	if (cleanup_stat_map[i].status & status)
     96 	    return (cleanup_stat_map[i].text);
     97 
     98     msg_panic("cleanup_strerror: unknown status %u", status);
     99 }
    100 
    101 /* cleanup_stat_detail - map status code to table entry with assorted data */
    102 
    103 const CLEANUP_STAT_DETAIL *cleanup_stat_detail(unsigned status)
    104 {
    105     unsigned i;
    106 
    107     if (status == CLEANUP_STAT_OK)
    108 	return (&cleanup_stat_success);
    109 
    110     for (i = 0; i < sizeof(cleanup_stat_map) / sizeof(cleanup_stat_map[0]); i++)
    111 	if (cleanup_stat_map[i].status & status)
    112 	    return (cleanup_stat_map + i);
    113 
    114     msg_panic("cleanup_stat_detail: unknown status %u", status);
    115 }
    116