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