1*33881f77Schristos /* $NetBSD: qmgr_error.c,v 1.2 2020/03/18 19:05:19 christos Exp $ */
241fbaed0Stron
341fbaed0Stron /*++
441fbaed0Stron /* NAME
541fbaed0Stron /* qmgr_error 3
641fbaed0Stron /* SUMMARY
741fbaed0Stron /* look up/create error/retry queue
841fbaed0Stron /* SYNOPSIS
941fbaed0Stron /* #include "qmgr.h"
1041fbaed0Stron /*
1141fbaed0Stron /* QMGR_TRANSPORT *qmgr_error_transport(service)
1241fbaed0Stron /* const char *service;
1341fbaed0Stron /*
1441fbaed0Stron /* QMGR_QUEUE *qmgr_error_queue(service, dsn)
1541fbaed0Stron /* const char *service;
1641fbaed0Stron /* DSN *dsn;
1741fbaed0Stron /*
1841fbaed0Stron /* char *qmgr_error_nexthop(dsn)
1941fbaed0Stron /* DSN *dsn;
2041fbaed0Stron /* DESCRIPTION
2141fbaed0Stron /* qmgr_error_transport() looks up the error transport for the
2241fbaed0Stron /* specified service. The result is null if the transport is
2341fbaed0Stron /* not available.
2441fbaed0Stron /*
2541fbaed0Stron /* qmgr_error_queue() looks up an error queue for the specified
2641fbaed0Stron /* service and problem. The result is null if the queue is not
27f3bc92a4Schristos /* available.
2841fbaed0Stron /*
2941fbaed0Stron /* qmgr_error_nexthop() computes the next-hop information for
3041fbaed0Stron /* the specified problem. The result must be passed to myfree().
3141fbaed0Stron /*
3241fbaed0Stron /* Arguments:
3341fbaed0Stron /* .IP dsn
3441fbaed0Stron /* See dsn(3).
3541fbaed0Stron /* .IP service
3641fbaed0Stron /* One of MAIL_SERVICE_ERROR or MAIL_SERVICE_RETRY.
3741fbaed0Stron /* DIAGNOSTICS
3841fbaed0Stron /* Panic: consistency check failure. Fatal: out of memory.
3941fbaed0Stron /* LICENSE
4041fbaed0Stron /* .ad
4141fbaed0Stron /* .fi
4241fbaed0Stron /* The Secure Mailer license must be distributed with this software.
4341fbaed0Stron /* AUTHOR(S)
4441fbaed0Stron /* Wietse Venema
4541fbaed0Stron /* IBM T.J. Watson Research
4641fbaed0Stron /* P.O. Box 704
4741fbaed0Stron /* Yorktown Heights, NY 10598, USA
4841fbaed0Stron /*--*/
4941fbaed0Stron
5041fbaed0Stron /* System library. */
5141fbaed0Stron
5241fbaed0Stron #include <sys_defs.h>
5341fbaed0Stron
5441fbaed0Stron /* Utility library. */
5541fbaed0Stron
5641fbaed0Stron #include <mymalloc.h>
5741fbaed0Stron #include <stringops.h>
5841fbaed0Stron
5941fbaed0Stron /* Global library. */
6041fbaed0Stron
6141fbaed0Stron /* Application-specific. */
6241fbaed0Stron
6341fbaed0Stron #include "qmgr.h"
6441fbaed0Stron
6541fbaed0Stron /* qmgr_error_transport - look up error transport for specified service */
6641fbaed0Stron
qmgr_error_transport(const char * service)6741fbaed0Stron QMGR_TRANSPORT *qmgr_error_transport(const char *service)
6841fbaed0Stron {
6941fbaed0Stron QMGR_TRANSPORT *transport;
7041fbaed0Stron
7141fbaed0Stron /*
7241fbaed0Stron * Find or create retry transport.
7341fbaed0Stron */
7441fbaed0Stron if ((transport = qmgr_transport_find(service)) == 0)
7541fbaed0Stron transport = qmgr_transport_create(service);
7641fbaed0Stron if (QMGR_TRANSPORT_THROTTLED(transport))
7741fbaed0Stron return (0);
7841fbaed0Stron
7941fbaed0Stron /*
8041fbaed0Stron * Done.
8141fbaed0Stron */
8241fbaed0Stron return (transport);
8341fbaed0Stron }
8441fbaed0Stron
8541fbaed0Stron /* qmgr_error_queue - look up error queue for specified service and problem */
8641fbaed0Stron
qmgr_error_queue(const char * service,DSN * dsn)8741fbaed0Stron QMGR_QUEUE *qmgr_error_queue(const char *service, DSN *dsn)
8841fbaed0Stron {
8941fbaed0Stron QMGR_TRANSPORT *transport;
9041fbaed0Stron QMGR_QUEUE *queue;
9141fbaed0Stron char *nexthop;
9241fbaed0Stron
9341fbaed0Stron /*
9441fbaed0Stron * Find or create transport.
9541fbaed0Stron */
9641fbaed0Stron if ((transport = qmgr_error_transport(service)) == 0)
9741fbaed0Stron return (0);
9841fbaed0Stron
9941fbaed0Stron /*
10041fbaed0Stron * Find or create queue.
10141fbaed0Stron */
10241fbaed0Stron nexthop = qmgr_error_nexthop(dsn);
10341fbaed0Stron if ((queue = qmgr_queue_find(transport, nexthop)) == 0)
10441fbaed0Stron queue = qmgr_queue_create(transport, nexthop, nexthop);
10541fbaed0Stron myfree(nexthop);
10641fbaed0Stron if (QMGR_QUEUE_THROTTLED(queue))
10741fbaed0Stron return (0);
10841fbaed0Stron
10941fbaed0Stron /*
11041fbaed0Stron * Done.
11141fbaed0Stron */
11241fbaed0Stron return (queue);
11341fbaed0Stron }
11441fbaed0Stron
11541fbaed0Stron /* qmgr_error_nexthop - compute next-hop information from problem description */
11641fbaed0Stron
qmgr_error_nexthop(DSN * dsn)11741fbaed0Stron char *qmgr_error_nexthop(DSN *dsn)
11841fbaed0Stron {
11941fbaed0Stron char *nexthop;
12041fbaed0Stron
12141fbaed0Stron nexthop = concatenate(dsn->status, " ", dsn->reason, (char *) 0);
12241fbaed0Stron return (nexthop);
12341fbaed0Stron }
124