1 /* $NetBSD: qmgr_error.c,v 1.2 2020/03/18 19:05:19 christos Exp $ */
2
3 /*++
4 /* NAME
5 /* qmgr_error 3
6 /* SUMMARY
7 /* look up/create error/retry queue
8 /* SYNOPSIS
9 /* #include "qmgr.h"
10 /*
11 /* QMGR_TRANSPORT *qmgr_error_transport(service)
12 /* const char *service;
13 /*
14 /* QMGR_QUEUE *qmgr_error_queue(service, dsn)
15 /* const char *service;
16 /* DSN *dsn;
17 /*
18 /* char *qmgr_error_nexthop(dsn)
19 /* DSN *dsn;
20 /* DESCRIPTION
21 /* qmgr_error_transport() looks up the error transport for the
22 /* specified service. The result is null if the transport is
23 /* not available.
24 /*
25 /* qmgr_error_queue() looks up an error queue for the specified
26 /* service and problem. The result is null if the queue is not
27 /* available.
28 /*
29 /* qmgr_error_nexthop() computes the next-hop information for
30 /* the specified problem. The result must be passed to myfree().
31 /*
32 /* Arguments:
33 /* .IP dsn
34 /* See dsn(3).
35 /* .IP service
36 /* One of MAIL_SERVICE_ERROR or MAIL_SERVICE_RETRY.
37 /* DIAGNOSTICS
38 /* Panic: consistency check failure. Fatal: out of memory.
39 /* LICENSE
40 /* .ad
41 /* .fi
42 /* The Secure Mailer license must be distributed with this software.
43 /* AUTHOR(S)
44 /* Wietse Venema
45 /* IBM T.J. Watson Research
46 /* P.O. Box 704
47 /* Yorktown Heights, NY 10598, USA
48 /*--*/
49
50 /* System library. */
51
52 #include <sys_defs.h>
53
54 /* Utility library. */
55
56 #include <mymalloc.h>
57 #include <stringops.h>
58
59 /* Global library. */
60
61 /* Application-specific. */
62
63 #include "qmgr.h"
64
65 /* qmgr_error_transport - look up error transport for specified service */
66
qmgr_error_transport(const char * service)67 QMGR_TRANSPORT *qmgr_error_transport(const char *service)
68 {
69 QMGR_TRANSPORT *transport;
70
71 /*
72 * Find or create retry transport.
73 */
74 if ((transport = qmgr_transport_find(service)) == 0)
75 transport = qmgr_transport_create(service);
76 if (QMGR_TRANSPORT_THROTTLED(transport))
77 return (0);
78
79 /*
80 * Done.
81 */
82 return (transport);
83 }
84
85 /* qmgr_error_queue - look up error queue for specified service and problem */
86
qmgr_error_queue(const char * service,DSN * dsn)87 QMGR_QUEUE *qmgr_error_queue(const char *service, DSN *dsn)
88 {
89 QMGR_TRANSPORT *transport;
90 QMGR_QUEUE *queue;
91 char *nexthop;
92
93 /*
94 * Find or create transport.
95 */
96 if ((transport = qmgr_error_transport(service)) == 0)
97 return (0);
98
99 /*
100 * Find or create queue.
101 */
102 nexthop = qmgr_error_nexthop(dsn);
103 if ((queue = qmgr_queue_find(transport, nexthop)) == 0)
104 queue = qmgr_queue_create(transport, nexthop, nexthop);
105 myfree(nexthop);
106 if (QMGR_QUEUE_THROTTLED(queue))
107 return (0);
108
109 /*
110 * Done.
111 */
112 return (queue);
113 }
114
115 /* qmgr_error_nexthop - compute next-hop information from problem description */
116
qmgr_error_nexthop(DSN * dsn)117 char *qmgr_error_nexthop(DSN *dsn)
118 {
119 char *nexthop;
120
121 nexthop = concatenate(dsn->status, " ", dsn->reason, (char *) 0);
122 return (nexthop);
123 }
124