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

/* System library. */

#include <sys_defs.h>

/* Utility library. */

#include <mymalloc.h>
#include <stringops.h>

/* Global library. */

/* Application-specific. */

#include "qmgr.h"

/* qmgr_error_transport - look up error transport for specified service */

QMGR_TRANSPORT *qmgr_error_transport(const char *service)
{
    QMGR_TRANSPORT *transport;

    /*
     * Find or create retry transport.
     */
    if ((transport = qmgr_transport_find(service)) == 0)
	transport = qmgr_transport_create(service);
    if (QMGR_TRANSPORT_THROTTLED(transport))
	return (0);

    /*
     * Done.
     */
    return (transport);
}

/* qmgr_error_queue - look up error queue for specified service and problem */

QMGR_QUEUE *qmgr_error_queue(const char *service, DSN *dsn)
{
    QMGR_TRANSPORT *transport;
    QMGR_QUEUE *queue;
    char   *nexthop;

    /*
     * Find or create transport.
     */
    if ((transport = qmgr_error_transport(service)) == 0)
	return (0);

    /*
     * Find or create queue.
     */
    nexthop = qmgr_error_nexthop(dsn);
    if ((queue = qmgr_queue_find(transport, nexthop)) == 0)
	queue = qmgr_queue_create(transport, nexthop, nexthop);
    myfree(nexthop);
    if (QMGR_QUEUE_THROTTLED(queue))
	return (0);

    /*
     * Done.
     */
    return (queue);
}

/* qmgr_error_nexthop - compute next-hop information from problem description */

char   *qmgr_error_nexthop(DSN *dsn)
{
    char   *nexthop;

    nexthop = concatenate(dsn->status, " ", dsn->reason, (char *) 0);
    return (nexthop);
}